mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-06-20 01:37:52 +02:00
Implemented new SAMPLE block syntax
Replaced states SAMPLE1 and SAMPLE2 with new state SAMPLE - this is now much simpler code
This commit is contained in:
parent
eefbebe467
commit
291158afc2
102
src/lexer.l
102
src/lexer.l
@ -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.12 1999/07/02 11:58:15 tsjensen Exp tsjensen $
|
* Version: $Id: lexer.l,v 1.13 1999/07/22 12:21:14 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,12 @@
|
|||||||
* Revision History:
|
* Revision History:
|
||||||
*
|
*
|
||||||
* $Log: lexer.l,v $
|
* $Log: lexer.l,v $
|
||||||
|
* Revision 1.13 1999/07/22 12:21:14 tsjensen
|
||||||
|
* Added GNU GPL disclaimer
|
||||||
|
* Renamed y.tab.h include to parser.h (same file)
|
||||||
|
* Renamed parser.h include to lexer.h (same file)
|
||||||
|
* Added config.h include
|
||||||
|
*
|
||||||
* Revision 1.12 1999/07/02 11:58:15 tsjensen
|
* Revision 1.12 1999/07/02 11:58:15 tsjensen
|
||||||
* Added begin_speedmode() which is called by parser.y
|
* Added begin_speedmode() which is called by parser.y
|
||||||
* Added state SPEEDMODE for fast skipping of designs
|
* Added state SPEEDMODE for fast skipping of designs
|
||||||
@ -45,7 +51,7 @@
|
|||||||
* Added #include tools.h
|
* Added #include tools.h
|
||||||
*
|
*
|
||||||
* Revision 1.8 1999/06/20 14:17:58 tsjensen
|
* Revision 1.8 1999/06/20 14:17:58 tsjensen
|
||||||
* Added "padding" keyword and recogintion of numbers (YNUMBER)
|
* Added "padding" keyword and recognition of numbers (YNUMBER)
|
||||||
*
|
*
|
||||||
* Revision 1.7 1999/06/17 19:05:46 tsjensen
|
* Revision 1.7 1999/06/17 19:05:46 tsjensen
|
||||||
* Bugfix: Sample block analysis didn't handle empty blocks
|
* Bugfix: Sample block analysis didn't handle empty blocks
|
||||||
@ -89,7 +95,7 @@
|
|||||||
|
|
||||||
|
|
||||||
static const char rcsid_lexer_l[] =
|
static const char rcsid_lexer_l[] =
|
||||||
"$Id: lexer.l,v 1.12 1999/07/02 11:58:15 tsjensen Exp tsjensen $";
|
"$Id: lexer.l,v 1.13 1999/07/22 12:21:14 tsjensen Exp tsjensen $";
|
||||||
|
|
||||||
|
|
||||||
int yylineno = 1;
|
int yylineno = 1;
|
||||||
@ -100,8 +106,7 @@ int yyerrcnt = 0;
|
|||||||
%option nounput
|
%option nounput
|
||||||
%option noyywrap
|
%option noyywrap
|
||||||
|
|
||||||
%x SAMPLE1
|
%x SAMPLE
|
||||||
%x SAMPLE2
|
|
||||||
%x SPEEDMODE
|
%x SPEEDMODE
|
||||||
%s SHAPES
|
%s SHAPES
|
||||||
%s ELASTIC
|
%s ELASTIC
|
||||||
@ -112,9 +117,9 @@ PBOX Box
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
<SAMPLE1,SHAPES,ELASTIC,INITIAL>[ \r\t] /* ignore whitespace */
|
<SHAPES,ELASTIC,INITIAL>[ \r\t] /* ignore whitespace */
|
||||||
|
|
||||||
<SAMPLE1,SHAPES,ELASTIC,INITIAL>\n ++yylineno;
|
<SHAPES,ELASTIC,INITIAL>\n ++yylineno;
|
||||||
|
|
||||||
\"[^"\n]*$ {
|
\"[^"\n]*$ {
|
||||||
if (yyerrcnt++ < 5)
|
if (yyerrcnt++ < 5)
|
||||||
@ -157,80 +162,73 @@ PBOX Box
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Sample {
|
Sample {
|
||||||
#ifdef LEXER_DEBUG
|
#ifdef LEXER_DEBUG
|
||||||
fprintf (stderr, "\n WORD: %s -- STATE SAMPLE1", yytext);
|
fprintf (stderr, "\nYSAMPLE: %s -- STATE SAMPLE", yytext);
|
||||||
#endif
|
#endif
|
||||||
BEGIN SAMPLE1;
|
BEGIN SAMPLE;
|
||||||
return YSAMPLE;
|
return YSAMPLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
<SAMPLE1>\{ {
|
|
||||||
#ifdef LEXER_DEBUG
|
|
||||||
fprintf (stderr, "\n SYMBOL: \'%c\' -- STATE SAMPLE2", yytext[0]);
|
|
||||||
#endif
|
|
||||||
BEGIN SAMPLE2;
|
|
||||||
return yytext[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
<SAMPLE1>[^\{\n\r\t ]+ {
|
<SAMPLE>\n {
|
||||||
if (yyerrcnt++ < 5)
|
|
||||||
yyerror ("Syntax Error at \"%s\"", yytext);
|
|
||||||
return YUNREC;
|
|
||||||
}
|
|
||||||
|
|
||||||
<SAMPLE2>\n {
|
|
||||||
++yylineno;
|
++yylineno;
|
||||||
if (yyleng > 1)
|
if (yyleng > 1)
|
||||||
yymore();
|
yymore();
|
||||||
}
|
}
|
||||||
|
|
||||||
<SAMPLE2>\} {
|
|
||||||
int bidx = yyleng-2; /* backslash index */
|
|
||||||
|
|
||||||
if (bidx >= 0) {
|
<SAMPLE>^[ \t]*ends[ \t\r]*$ {
|
||||||
while (bidx >= 0 && yytext[bidx] == '\\') bidx--;
|
char *p = yytext + yyleng -1;
|
||||||
|
size_t len; /* length of sample */
|
||||||
|
|
||||||
if ((yyleng-2-bidx) % 2) { /* odd number of backslashes */
|
while (*p == ' ' || *p == '\t' || *p == '\r')
|
||||||
yymore(); /* append next string */
|
--p; /* skip trailing whitespace */
|
||||||
}
|
p -= 2; /* almost skip "ends" statement */
|
||||||
else {
|
*p = '\0'; /* p now points to 'n' */
|
||||||
yyless (yyleng-1); /* have him recognize '}' symbol */
|
|
||||||
|
|
||||||
for (bidx=yyleng-1; yytext[bidx]=='\n'; --bidx) {
|
|
||||||
yytext[bidx] = '\0'; /* remove trailing newlines */
|
|
||||||
--yyleng;
|
|
||||||
}
|
|
||||||
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 */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BEGIN INITIAL;
|
|
||||||
#ifdef LEXER_DEBUG
|
|
||||||
fprintf (stderr, "\n SAMPLE: %s -- STATE INITIAL", yytext);
|
|
||||||
#endif
|
|
||||||
yylval.s = (char *) strdup (yytext);
|
yylval.s = (char *) strdup (yytext);
|
||||||
if (yylval.s == NULL) {
|
if (yylval.s == NULL) {
|
||||||
perror (PROJECT);
|
perror (PROJECT);
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
*p-- = 'n';
|
||||||
|
|
||||||
|
len = p - yytext; /* yyless(n): push back all but the first n */
|
||||||
|
yyless (len); /* allow him to return YENDSAMPLE */
|
||||||
|
|
||||||
|
yylval.s[len] = '\n'; /* replace 'e' with newline */
|
||||||
|
btrim (yylval.s, &len);
|
||||||
|
if (len > 0) {
|
||||||
|
strcat (yylval.s, "\n"); /* memory was allocated with strdup */
|
||||||
|
#ifdef LEXER_DEBUG
|
||||||
|
fprintf (stderr, "\n STRING: \"%s\" -- STATE INITIAL", yylval.s);
|
||||||
|
#endif
|
||||||
|
BEGIN INITIAL;
|
||||||
return STRING;
|
return STRING;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
if (yyerrcnt++ < 5)
|
if (yyerrcnt++ < 5)
|
||||||
yyerror ("SAMPLE entry must not be empty");
|
yyerror ("SAMPLE block must not be empty");
|
||||||
|
BFREE (yylval.s);
|
||||||
return YUNREC;
|
return YUNREC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<SAMPLE2>. {
|
|
||||||
yymore();
|
<SAMPLE>. yymore();
|
||||||
|
|
||||||
|
|
||||||
|
ends[ \t\r]*$ {
|
||||||
|
#ifdef LEXER_DEBUG
|
||||||
|
fprintf (stderr, "\nYENDSAM: %s", yytext);
|
||||||
|
#endif
|
||||||
|
return YENDSAMPLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Elastic {
|
Elastic {
|
||||||
#ifdef LEXER_DEBUG
|
#ifdef LEXER_DEBUG
|
||||||
fprintf (stderr, "\nYELASTC: %s -- STATE ELASTIC", yytext);
|
fprintf (stderr, "\nYELASTC: %s -- STATE ELASTIC", yytext);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user