Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amend scanner.c to correctly parse strings of the form "*\$" #137

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions test/corpus/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ More string interpolation
"$1"
"$ $ $"
"\$foo"

"\$"
yosefAlsuhaibani marked this conversation as resolved.
Show resolved Hide resolved
--------------------------------------------------------------------------------

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

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