aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-05-08 20:21:47 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-05-08 20:24:21 +0300
commit808b211c7d268d8c2978145451b1863d4e9306bf (patch)
tree948742bac9642f0a4daea951906b6b79b013ec4a
parentb1a26bd032cbed37adc2a7d828491d0b56244578 (diff)
downloadrush-808b211c7d268d8c2978145451b1863d4e9306bf.tar.gz
rush-808b211c7d268d8c2978145451b1863d4e9306bf.tar.bz2
Fixes in scanner
* src/cflex.l: Merge INMATCH and ARGS. Generalize rule for unquoted strings. Use stringbuf_add_escape_octal and stringbuf_add_escape_hex (complements dc4dcf015f24).
-rw-r--r--src/cflex.l59
1 files changed, 24 insertions, 35 deletions
diff --git a/src/cflex.l b/src/cflex.l
index a6caab8..6fda227 100644
--- a/src/cflex.l
+++ b/src/cflex.l
@@ -258,7 +258,7 @@ inpctx_pop(void)
static void straychar(int);
static int noinc(void);
%}
-%x NORMAL ARGS INMATCH QSTR VAR
+%x NORMAL ARGS QSTR VAR
%option nounput
%%
/* INITIAL: The scanner is processing the initial portion of the input file,
@@ -279,7 +279,7 @@ static int noinc(void);
. return tok(BOGUS);
}
-<NORMAL,INMATCH,ARGS>{
+<NORMAL,ARGS>{
\\\n { advance_line(1); }
#.*\n { advance_line(1);
BEGIN(NORMAL);
@@ -290,24 +290,6 @@ static int noinc(void);
[ \t]+ reset_loc();
}
- /* The INMATCH state is activated when scanning the arguments to the "match"
- command. This is the only state where comparison and logical operators
- are allowed. */
-<INMATCH>{
-"&&" return tok(AND);
-"||" return tok(OR);
-"!" return tok(NOT);
-"==" return tok(EQ);
-"!=" return tok(NE);
-"<" return tok(LT);
-"<=" return tok(LE);
-">" return tok(GT);
-">=" return tok(GE);
-"!~" return tok(NM);
-"in" return tok(IN);
-"member" return tok(MEMBER);
-}
-
/* NORMAL: The input point is before the next keyword.
*/
<NORMAL>{
@@ -319,7 +301,7 @@ static int noinc(void);
"global" { if (!noinc()) return tok(GLOBAL); }
"set" { BEGIN(ARGS); return tok(SET); }
"unset" { BEGIN(ARGS); return tok(UNSET); }
-"match" { BEGIN(INMATCH); return tok(MATCH); }
+"match" { BEGIN(ARGS); return tok(MATCH); }
"fallthrough"|"fall-through" { BEGIN(ARGS); return tok(FALLTHROUGH); }
"include" { BEGIN(ARGS); return tok(INCLUDE); }
"limits" { BEGIN(ARGS); return tok(LIMITS); }
@@ -347,14 +329,26 @@ static int noinc(void);
/* ARGS: Processing arguments to a configuration statement.
*/
-<ARGS,INMATCH>{
+<ARGS>{
+"&&" return tok(AND);
+"||" return tok(OR);
+"!" return tok(NOT);
+"==" return tok(EQ);
+"!=" return tok(NE);
+"<" return tok(LT);
+"<=" return tok(LE);
+">" return tok(GT);
+">=" return tok(GE);
+"!~" return tok(NM);
+"in" return tok(IN);
+"member" return tok(MEMBER);
[+-]?[0-9]+ { yylval.num.strval = xstrdup(yytext);
yylval.num.intval = atoi(yytext);
return tok(NUMBER); }
[A-Za-z_][A-Za-z0-9_-]* { yylval.str = xstrdup(yytext);
return tok(IDENT); }
-[A-Za-z_/+-][A-Za-z0-9_/+-]* { yylval.str = xstrdup(yytext);
- return tok(STRING); }
+[^ \t\n\\\"!=<>(){}\[\]\$%&|~#]+ { yylval.str = xstrdup(yytext);
+ return tok(STRING); }
\$[A-Za-z_][A-Za-z_0-9-]* { yylval.str = xstrdup(yytext);
return tok(STRING); }
\$\{[A-Za-z_][A-Za-z_0-9-]*\} { yylval.str = xstrdup(yytext);
@@ -440,17 +434,13 @@ static int noinc(void);
\"[^\\\"\n]*\\\n { stringbuf_add_array(&sb, yytext + 1, yyleng - 3);
advance_line(1);
pushstart(QSTR); }
-\"[^\\\"\n]*\\[0-9]{3} { stringbuf_add_array(&sb, yytext + 1, yyleng - 5);
- stringbuf_add_char(&sb,
- strtoul(yytext + yyleng - 3,
- NULL, 8));
- pushstart(QSTR); }
-\"[^\\\"\n]*\\0[xX][a-fA-F0-9]{2} {
- stringbuf_add_array(&sb, yytext + 1, yyleng - 6);
- stringbuf_add_char(&sb,
- strtoul(yytext + yyleng - 2,
- NULL, 16));
+\"[^\\\"\n]*\\[0-9]{3} { stringbuf_add_escape_octal(&sb,
+ yytext + 1,
+ yyleng - 1);
pushstart(QSTR); }
+\"[^\\\"\n]*\\[xX][a-fA-F0-9]{2} { stringbuf_add_escape_hex(&sb,
+ yytext + 1,
+ yyleng - 1); pushstart(QSTR); }
[^}\"\$%]+ { stringbuf_add_array(&sb, yytext, yyleng); }
. { straychar(yytext[0]);
stringbuf_add_char(&sb, yytext[0]); }
@@ -479,7 +469,6 @@ straychar(int c)
static char *start_name[] = {
[INITIAL] = N_("looking for rush version clause"),
[NORMAL] = N_("looking for rule"),
- [INMATCH] = N_("scanning match expression"),
[ARGS] = N_("scanning arguments"),
[QSTR] = N_("scanning quoted string"),
[VAR] = N_("scanning variable reference")

Return to:

Send suggestions and report system problems to the System administrator.