Skip to content

Commit

Permalink
Merge pull request #137 from yosefAlsuhaibani/escaped-dollar-sign-at-…
Browse files Browse the repository at this point in the history
…end-of-string-does-not-parse

Amend `scanner.c` to correctly parse strings of the form `"*\$"`
  • Loading branch information
fwcd committed Aug 2, 2024
2 parents fe73604 + b5ce081 commit 754394c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,20 @@ static bool scan_string_content(TSLexer *lexer, Stack *stack) {
advance(lexer);
// this dollar sign is escaped, so it must be content.
// we consume it here so we don't enter the dollar sign case above,
// which leaves the possibility that it is an interpolation
if (lexer->lookahead == '$') advance(lexer);
// which leaves the possibility that it is an interpolation
if (lexer->lookahead == '$') {
advance(lexer);
// however this leaves an edgecase where an escaped dollar sign could
// appear at the end of a string (e.g "aa\$") which isn't handled
// correctly; if we were at the end of the string, terminate properly
if (lexer->lookahead == end_char) {
stack_pop(stack);
advance(lexer);
lexer->mark_end(lexer);
lexer->result_symbol = STRING_END;
return true;
}
}
} else if (lexer->lookahead == end_char) {
if (is_triple) {
lexer->mark_end(lexer);
Expand Down
4 changes: 3 additions & 1 deletion test/corpus/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ More string interpolation
"$1"
"$ $ $"
"\$foo"
"\$"

--------------------------------------------------------------------------------

Expand All @@ -130,7 +131,8 @@ More string interpolation
(string_content)
(string_content))
(string_literal
(string_content)))
(string_content))
(string_literal))

================================================================================
Integer literals
Expand Down

0 comments on commit 754394c

Please sign in to comment.