Skip to content

Commit

Permalink
Fix the parsing of "$"'s in strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
layus committed Jul 3, 2015
1 parent 65e4dcd commit 467977f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/libexpr/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,11 @@ or { return OR_KW; }
\} { POP_STATE(); return '}'; }

\" { PUSH_STATE(STRING); return '"'; }
<STRING>([^\$\"\\]|\$[^\{\"]|\\.)+ {
/* !!! Not quite right: we want a follow restriction on
"$", it shouldn't be followed by a "{". Right now
"$\"" will be consumed as part of a string, rather
than a "$" followed by the string terminator.
Disallow "$\"" for now. */
<STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)*\$/\" |
<STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)+ {
/* It is impossible to match strings ending with '$' with one
regex because trailing contexts are only valid at the end
of a rule. (A sane but undocumented limitation.) */
yylval->e = unescapeStr(data->symbols, yytext);
return STR;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lang/eval-okay-string.exp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"foobar/a/b/c/d/foo/xyzzy/foo.txt/../foo/x/yescape: \"quote\" \n \\end\nof\nlinefoobarblaatfoo$bar"
"foobar/a/b/c/d/foo/xyzzy/foo.txt/../foo/x/yescape: \"quote\" \n \\end\nof\nlinefoobarblaatfoo$bar$\"$\"$"
2 changes: 2 additions & 0 deletions tests/lang/eval-okay-string.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ of
line"
+ "foo${if true then "b${"a" + "r"}" else "xyzzy"}blaat"
+ "foo$bar"
+ "$\"$\""
+ "$"

0 comments on commit 467977f

Please sign in to comment.