Skip to content

Commit acafb36

Browse files
authored
Fix parsing of string literals immediately after syntax errors (#172)
1 parent 2b9e9e0 commit acafb36

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/scanner.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ struct Scanner {
149149
}
150150

151151
bool scan(TSLexer *lexer, const bool *valid_symbols) {
152-
if (valid_symbols[STRING_CONTENT] && !valid_symbols[INDENT] && !delimiter_stack.empty()) {
152+
bool error_recovery_mode = valid_symbols[STRING_CONTENT] && valid_symbols[INDENT];
153+
154+
if (valid_symbols[STRING_CONTENT] && !delimiter_stack.empty() && !error_recovery_mode) {
153155
Delimiter delimiter = delimiter_stack.back();
154156
int32_t end_character = delimiter.end_character();
155157
bool has_content = false;
@@ -272,7 +274,7 @@ struct Scanner {
272274
}
273275
}
274276

275-
if (found_end_of_line) {
277+
if (found_end_of_line && !error_recovery_mode) {
276278
if (!indent_length_stack.empty()) {
277279
uint16_t current_indent_length = indent_length_stack.back();
278280

test/corpus/errors.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
====================================
2+
An error before a string literal
3+
====================================
4+
5+
def a(b):
6+
c.
7+
8+
"""
9+
d
10+
"""
11+
12+
e
13+
14+
---
15+
16+
(module
17+
(function_definition
18+
(identifier)
19+
(parameters
20+
(identifier))
21+
(ERROR
22+
(identifier))
23+
(block
24+
(expression_statement
25+
(string))
26+
(expression_statement
27+
(identifier)))))

0 commit comments

Comments
 (0)