Added %options never-interactive and caseless

Added code for DELIMITER statements
Rewrote string rules to deal with delimiter statements
This commit is contained in:
Thomas Jensen 1999-08-18 15:40:10 +00:00
parent 52816696e6
commit f5b5d4572a

View File

@ -4,7 +4,7 @@
* Date created: March 15, 1999 (Monday, 17:16h) * Date created: March 15, 1999 (Monday, 17:16h)
* Author: Copyright (C) 1999 Thomas Jensen * Author: Copyright (C) 1999 Thomas Jensen
* tsjensen@stud.informatik.uni-erlangen.de * tsjensen@stud.informatik.uni-erlangen.de
* Version: $Id: lexer.l,v 1.13 1999/07/22 12:21:14 tsjensen Exp tsjensen $ * Version: $Id: lexer.l,v 1.14 1999/08/16 16:28:03 tsjensen Exp tsjensen $
* Language: lex (ANSI C) * Language: lex (ANSI C)
* Purpose: flex lexical analyzer for boxes configuration files * Purpose: flex lexical analyzer for boxes configuration files
* *
@ -24,6 +24,11 @@
* Revision History: * Revision History:
* *
* $Log: lexer.l,v $ * $Log: lexer.l,v $
* Revision 1.14 1999/08/16 16:28:03 tsjensen
* Implemented new SAMPLE block syntax
* Replaced states SAMPLE1 and SAMPLE2 with new state SAMPLE - this is now
* much simpler code
*
* Revision 1.13 1999/07/22 12:21:14 tsjensen * Revision 1.13 1999/07/22 12:21:14 tsjensen
* Added GNU GPL disclaimer * Added GNU GPL disclaimer
* Renamed y.tab.h include to parser.h (same file) * Renamed y.tab.h include to parser.h (same file)
@ -59,9 +64,6 @@
* Revision 1.6 1999/06/14 12:13:41 tsjensen * Revision 1.6 1999/06/14 12:13:41 tsjensen
* Added Reverse pattern * Added Reverse pattern
* *
* Revision 1.5 1999/06/03 18:54:55 tsjensen
* *** empty log message ***
*
* Revision 1.4 1999/04/09 13:31:13 tsjensen * Revision 1.4 1999/04/09 13:31:13 tsjensen
* Removed all code related to OFFSET blocks (obsolete) * Removed all code related to OFFSET blocks (obsolete)
* *
@ -70,9 +72,6 @@
* Added Replace token * Added Replace token
* Some fiddling which will hopefully fix a line counting bug * Some fiddling which will hopefully fix a line counting bug
* *
* Revision 1.2 1999/03/30 09:42:51 tsjensen
* Added rcs keywords and standard file header.
*
* Revision 1.1 1999/03/18 15:09:48 tsjensen * Revision 1.1 1999/03/18 15:09:48 tsjensen
* Initial revision * Initial revision
* *
@ -95,71 +94,102 @@
static const char rcsid_lexer_l[] = static const char rcsid_lexer_l[] =
"$Id: lexer.l,v 1.13 1999/07/22 12:21:14 tsjensen Exp tsjensen $"; "$Id: lexer.l,v 1.14 1999/08/16 16:28:03 tsjensen Exp tsjensen $";
int yylineno = 1; int yylineno = 1;
int yyerrcnt = 0; int yyerrcnt = 0;
static char sdel = '\"';
static char sesc = '\\';
%} %}
%option nounput %option nounput
%option noyywrap %option noyywrap
%option never-interactive
%option caseless
%x SAMPLE %x SAMPLE
%x SPEEDMODE %x SPEEDMODE
%x DELWORD
%s SHAPES %s SHAPES
%s ELASTIC %s ELASTIC
PWORD [a-zA-ZäöüÄÖÜ][a-zA-Z0-9\-_üäöÜÄÖß]* PWORD [a-zA-ZäöüÄÖÜ][a-zA-Z0-9\-_üäöÜÄÖß]*
PWHITE [\n \r\t] PWHITE [\n \r\t]
PBOX Box PBOX Box
SDELIM [\"~\'`!@\%\&\*=:;<>\?/|\.\\]
%% %%
<SHAPES,ELASTIC,INITIAL>[ \r\t] /* ignore whitespace */
<SHAPES,ELASTIC,INITIAL>\n ++yylineno; <DELWORD,SHAPES,ELASTIC,INITIAL>[ \r\t] /* ignore whitespace */
\"[^"\n]*$ { <DELWORD,SHAPES,ELASTIC,INITIAL>\n ++yylineno;
if (yyerrcnt++ < 5)
yyerror ("Unterminated String at %s", yytext);
return YUNREC; <DELWORD>[^ \t\r\n]+ {
/*
* String delimiter spec - like WORD, but allow any character
*/
#ifdef LEXER_DEBUG
fprintf (stderr, "\nYDELWOR: %s -- STATE INITIAL", yytext);
#endif
yylval.s = (char *) strdup (yytext);
if (yylval.s == NULL) {
perror (PROJECT);
exit (EXIT_FAILURE);
}
BEGIN INITIAL;
return YDELWORD;
} }
\"[^"\n]*\" {
int bidx = yyleng-2; /* backslash index */
while (yytext[bidx] == '\\') bidx--; {SDELIM}.*$ {
/*
* Strings -- first match everything starting from a potential
* string delimiter until the end of the line. We will give back what
* we don't need and also detect unterminated strings.
*/
char *p;
int rest_len = yyleng - 1; /* length of string pointed to by p */
int qcnt = 0; /* esc char count in current string */
if ((yyleng-2-bidx) % 2) { if (yytext[0] != sdel) {
yyless (yyleng-1); /* give back last quote */ REJECT; /* that was not our delimiter */
yymore(); /* append next string */
} }
else {
for (bidx=0; bidx<yyleng-1; ++bidx) {
if (yytext[bidx] == '\\') {
memmove (yytext+bidx, yytext+bidx+1, yyleng-bidx-1);
yytext[yyleng-1] = '\0';
--yyleng; /* inefficient */
}
}
memmove (yytext, yytext+1, yyleng-1); /* cut quotes */ yylval.s = (char *) strdup (yytext + 1);
--yyleng; if (yylval.s == NULL) {
yytext[yyleng-1] = '\0'; perror (PROJECT);
--yyleng; exit (EXIT_FAILURE);
#ifdef LEXER_DEBUG
fprintf (stderr, "\n STRING: \"%s\"", yytext);
#endif
yylval.s = (char *) strdup (yytext);
if (yylval.s == NULL) {
perror (PROJECT);
exit (EXIT_FAILURE);
}
return STRING;
} }
p = yylval.s;
while (*p) {
if (*p == sesc) {
memmove (p, p+1, rest_len); /* incl. '\0' */
++qcnt;
--rest_len;
if (*p == '\0')
break;
}
else if (*p == sdel) {
*p = '\0';
yyless ((p-yylval.s)+2+qcnt); /* string plus quotes */
#ifdef LEXER_DEBUG
fprintf (stderr, "\n STRING: \"%s\"", yylval.s);
#endif
return STRING;
}
--rest_len;
++p;
}
if (yyerrcnt++ < 5)
yyerror ("Unterminated String -- %s", yytext);
return YUNREC;
} }
@ -313,6 +343,18 @@ author|created|revision|revdate|indent {
} }
Delimiter|Delim {
/*
* Change string delimiting characters
*/
#ifdef LEXER_DEBUG
fprintf (stderr, "\nYCHGDEL: %s -- STATE DELWORD", yytext);
#endif
BEGIN DELWORD;
return YCHGDEL;
}
{PWORD} { {PWORD} {
#ifdef LEXER_DEBUG #ifdef LEXER_DEBUG
fprintf (stderr, "\n WORD: %s", yytext); fprintf (stderr, "\n WORD: %s", yytext);
@ -360,7 +402,7 @@ author|created|revision|revdate|indent {
<SPEEDMODE>{PBOX}{PWHITE}+{PWORD} { <SPEEDMODE>{PBOX}{PWHITE}+{PWORD} {
#ifdef LEXER_DEBUG #ifdef LEXER_DEBUG
fprintf (stderr, "\n STATUS: %s -- BEGIN INITIAL", yytext); fprintf (stderr, "\n STATUS: %s -- STATE INITIAL", yytext);
#endif #endif
yyless (0); yyless (0);
speeding = 0; speeding = 0;
@ -384,4 +426,16 @@ void begin_speedmode()
} }
void chg_strdelims (const char asesc, const char asdel)
{
#ifdef LEXER_DEBUG
fprintf (stderr, "\n STATUS: chg_strdelims ('%c', '%c')", asesc, asdel);
#endif
sesc = asesc;
sdel = asdel;
}
/*EOF*/ /* vim: set cindent sw=4: */ /*EOF*/ /* vim: set cindent sw=4: */