Skip to content

Commit

Permalink
Fix escape sequences for raw strings
Browse files Browse the repository at this point in the history
Inside raw strings, only escaped delimiters and \\ are considered escape
sequences. Other backslashes are treated as regular characters.
  • Loading branch information
savq committed Nov 5, 2024
1 parent 73e9669 commit a4f8a0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ static bool scan_content(TSLexer *lexer, TSSymbol content_symbol, char end_char,
int32_t next;
while ((next = lexer->lookahead)) {
mark_end(lexer);
if (next == '\\' || (next == '$' && interp)) {
if (interp && (next == '$' || next == '\\')) {
lexer->result_symbol = content_symbol;
return has_content;
} else if (next == '\\') {
// Parse backslash in raw strings (check escaped delimiters and '\\')
advance(lexer);
next = lexer->lookahead;
if (next == end_char || next == '\\') {
lexer->result_symbol = content_symbol;
return has_content;
}
} else {
bool is_end_delimiter = true;
for (unsigned i = 1; i <= n_delim; i++) {
Expand Down
1 change: 0 additions & 1 deletion test/corpus/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ K"\\"
(operator)
(prefixed_string_literal
prefix: (identifier)
(escape_sequence)
(content)))
(assignment
(identifier)
Expand Down

0 comments on commit a4f8a0a

Please sign in to comment.