Skip to content

Commit

Permalink
Be more flexible with escape parsing, avoid infinite loops with inval…
Browse files Browse the repository at this point in the history
…id escapes
  • Loading branch information
irh committed Jan 9, 2024
1 parent 2c23f01 commit 10d620f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
15 changes: 7 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,16 609,15 @@ module.exports = grammar({
escape: $ => seq(
'\\',
choice(
'n',
'r',
't',
'$',
'\'',
'"',
'\\',
// Any single non-whitespace character
// (we don't need to list all valid escape characters)
/\S/,
// Newline
/\r?\n/,
// \x42
/x[0-9a-fA-F]{2}/,
/u\{[0-9a-fA-F]{1,6}\}/
// \u{123456}
/u\{[0-9a-fA-F]{1,6}\}/,
)
),
}
Expand Down
4 changes: 2 additions & 2 deletions src/grammar.json
Git LFS file not shown
4 changes: 2 additions & 2 deletions src/node-types.json
Git LFS file not shown
4 changes: 2 additions & 2 deletions src/parser.c
Git LFS file not shown
3 changes: 2 additions & 1 deletion src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 229,8 @@ bool tree_sitter_koto_external_scanner_scan(
}

// String start/end detection
if (valid_symbols[STRING_START] && (next == '"' || next == '\'')) {
if (valid_symbols[STRING_START] && !scanner->in_string
&& (next == '"' || next == '\'')) {
printf(">>>> string start\n");
scanner->in_string = true;
VEC_PUSH(scanner->quotes, next);
Expand Down

0 comments on commit 10d620f

Please sign in to comment.