Revert "Revert "next try for "don't abort when given unmatched '}' with 'start-condition stack underflow'. This fixes #751"""

This reverts commit b669d3d2e8.
This commit is contained in:
Eelco Dolstra 2016-01-20 16:34:42 +01:00
parent 84e01203a7
commit 5d8b7eb3e1
4 changed files with 23 additions and 8 deletions

View file

@ -8,6 +8,7 @@
%x STRING %x STRING
%x IND_STRING %x IND_STRING
%x INSIDE_DOLLAR_CURLY
%{ %{
@ -93,6 +94,8 @@ URI [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~
%% %%
<INITIAL,INSIDE_DOLLAR_CURLY>{
if { return IF; } if { return IF; }
then { return THEN; } then { return THEN; }
@ -124,11 +127,15 @@ or { return OR_KW; }
return INT; return INT;
} }
\$\{ { PUSH_STATE(INITIAL); return DOLLAR_CURLY; } \$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
\{ { PUSH_STATE(INITIAL); return '{'; } }
\} { POP_STATE(); return '}'; }
\" { PUSH_STATE(STRING); return '"'; } \} { return '}'; }
<INSIDE_DOLLAR_CURLY>\} { POP_STATE(); return '}'; }
\{ { return '{'; }
<INSIDE_DOLLAR_CURLY>\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return '{'; }
<INITIAL,INSIDE_DOLLAR_CURLY>\" { PUSH_STATE(STRING); return '"'; }
<STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)*\$/\" | <STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)*\$/\" |
<STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)+ { <STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)+ {
/* It is impossible to match strings ending with '$' with one /* It is impossible to match strings ending with '$' with one
@ -137,11 +144,11 @@ or { return OR_KW; }
yylval->e = unescapeStr(data->symbols, yytext); yylval->e = unescapeStr(data->symbols, yytext);
return STR; return STR;
} }
<STRING>\$\{ { PUSH_STATE(INITIAL); return DOLLAR_CURLY; } <STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
<STRING>\" { POP_STATE(); return '"'; } <STRING>\" { POP_STATE(); return '"'; }
<STRING>. return yytext[0]; /* just in case: shouldn't be reached */ <STRING>. return yytext[0]; /* just in case: shouldn't be reached */
\'\'(\ *\n)? { PUSH_STATE(IND_STRING); return IND_STRING_OPEN; } <INITIAL,INSIDE_DOLLAR_CURLY>\'\'(\ *\n)? { PUSH_STATE(IND_STRING); return IND_STRING_OPEN; }
<IND_STRING>([^\$\']|\$[^\{\']|\'[^\'\$])+ { <IND_STRING>([^\$\']|\$[^\{\']|\'[^\'\$])+ {
yylval->e = new ExprIndStr(yytext); yylval->e = new ExprIndStr(yytext);
return IND_STR; return IND_STR;
@ -158,7 +165,7 @@ or { return OR_KW; }
yylval->e = unescapeStr(data->symbols, yytext + 2); yylval->e = unescapeStr(data->symbols, yytext + 2);
return IND_STR; return IND_STR;
} }
<IND_STRING>\$\{ { PUSH_STATE(INITIAL); return DOLLAR_CURLY; } <IND_STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
<IND_STRING>\'\' { POP_STATE(); return IND_STRING_CLOSE; } <IND_STRING>\'\' { POP_STATE(); return IND_STRING_CLOSE; }
<IND_STRING>\' { <IND_STRING>\' {
yylval->e = new ExprIndStr("'"); yylval->e = new ExprIndStr("'");
@ -166,6 +173,8 @@ or { return OR_KW; }
} }
<IND_STRING>. return yytext[0]; /* just in case: shouldn't be reached */ <IND_STRING>. return yytext[0]; /* just in case: shouldn't be reached */
<INITIAL,INSIDE_DOLLAR_CURLY>{
{PATH} { yylval->path = strdup(yytext); return PATH; } {PATH} { yylval->path = strdup(yytext); return PATH; }
{HPATH} { yylval->path = strdup(yytext); return HPATH; } {HPATH} { yylval->path = strdup(yytext); return HPATH; }
{SPATH} { yylval->path = strdup(yytext); return SPATH; } {SPATH} { yylval->path = strdup(yytext); return SPATH; }
@ -177,6 +186,7 @@ or { return OR_KW; }
. return yytext[0]; . return yytext[0];
}
%% %%

2
tests/lexer.nix Normal file
View file

@ -0,0 +1,2 @@
let const = a: "const"; in
''${ const { x = "q"; }}''

3
tests/lexer.sh Normal file
View file

@ -0,0 +1,3 @@
source common.sh
nix-instantiate --eval ./lexer.nix

View file

@ -11,7 +11,7 @@ nix_tests = \
binary-patching.sh timeout.sh secure-drv-outputs.sh nix-channel.sh \ binary-patching.sh timeout.sh secure-drv-outputs.sh nix-channel.sh \
multiple-outputs.sh import-derivation.sh fetchurl.sh optimise-store.sh \ multiple-outputs.sh import-derivation.sh fetchurl.sh optimise-store.sh \
binary-cache.sh nix-profile.sh repair.sh dump-db.sh case-hack.sh \ binary-cache.sh nix-profile.sh repair.sh dump-db.sh case-hack.sh \
check-reqs.sh pass-as-file.sh tarball.sh check-reqs.sh pass-as-file.sh tarball.sh lexer.sh
# parallel.sh # parallel.sh
install-tests += $(foreach x, $(nix_tests), tests/$(x)) install-tests += $(foreach x, $(nix_tests), tests/$(x))