Skip to content

Commit

Permalink
don't abort when given unmatched '}' with 'start-condition stack unde…
Browse files Browse the repository at this point in the history
…rflow'. This fixes  NixOS#751
  • Loading branch information
fkz committed Jan 12, 2016
1 parent 4202b17 commit 8d22b26
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/libexpr/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

%x STRING
%x IND_STRING
%x INSIDE_DOLLAR_CURLY


%{
Expand Down Expand Up @@ -93,6 +94,8 @@ URI [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~

%%

<INITIAL,INSIDE_DOLLAR_CURLY>{


if { return IF; }
then { return THEN; }
Expand Down Expand Up @@ -124,11 +127,15 @@ or { return OR_KW; }
return INT;
}

\$\{ { PUSH_STATE(INITIAL); return DOLLAR_CURLY; }
\{ { PUSH_STATE(INITIAL); return '{'; }
\} { POP_STATE(); return '}'; }
\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
\{ { return '{'; }
}

\} { return '}'; }
<INSIDE_DOLLAR_CURLY>\} { POP_STATE(); return '}'; }

<INITIAL,INSIDE_DOLLAR_CURLY>\" { PUSH_STATE(STRING); return '"'; }

\" { PUSH_STATE(STRING); return '"'; }
<STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)*\$/\" |
<STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)+ {
/* It is impossible to match strings ending with '$' with one
Expand All @@ -137,11 +144,11 @@ or { return OR_KW; }
yylval->e = unescapeStr(data->symbols, yytext);
return STR;
}
<STRING>\$\{ { PUSH_STATE(INITIAL); return DOLLAR_CURLY; }
<STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
<STRING>\" { POP_STATE(); return '"'; }
<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>([^\$\']|\$[^\{\']|\'[^\'\$])+ {
yylval->e = new ExprIndStr(yytext);
return IND_STR;
Expand All @@ -158,14 +165,16 @@ or { return OR_KW; }
yylval->e = unescapeStr(data->symbols, yytext + 2);
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>\' {
yylval->e = new ExprIndStr("'");
return IND_STR;
}
<IND_STRING>. return yytext[0]; /* just in case: shouldn't be reached */

<INITIAL,INSIDE_DOLLAR_CURLY>{

{PATH} { yylval->path = strdup(yytext); return PATH; }
{HPATH} { yylval->path = strdup(yytext); return HPATH; }
{SPATH} { yylval->path = strdup(yytext); return SPATH; }
Expand All @@ -177,6 +186,7 @@ or { return OR_KW; }

. return yytext[0];

}

%%

0 comments on commit 8d22b26

Please sign in to comment.