Skip to content

Commit 188b6b0

Browse files
committed
Ensure dedent tokens are returned even amid syntax errors
1 parent 597c4bb commit 188b6b0

File tree

5 files changed

+70916
-37482
lines changed

5 files changed

+70916
-37482
lines changed

grammar.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ const PREC = {
77

88
parenthesized_expression: 1,
99
parenthesized_list_splat: 1,
10-
or: 10,
11-
and: 11,
12-
not: 12,
13-
compare: 13,
14-
bitwise_or: 14,
10+
or: 10,
11+
and: 11,
12+
not: 12,
13+
compare: 13,
14+
bitwise_or: 14,
1515
bitwise_and: 15,
16-
xor: 16,
17-
shift: 17,
18-
plus: 18,
19-
times: 19,
20-
unary: 20,
21-
power: 21,
22-
call: 22,
16+
xor: 16,
17+
shift: 17,
18+
plus: 18,
19+
times: 19,
20+
unary: 20,
21+
power: 21,
22+
call: 22,
2323
}
2424

2525
const SEMICOLON = ';'
@@ -58,6 +58,19 @@ module.exports = grammar({
5858
$._string_start,
5959
$._string_content,
6060
$._string_end,
61+
62+
// Mark comments as external tokens so that the external scanner is always
63+
// invoked, even if no external token is expected. This allows for better
64+
// error recovery, because the external scanner can maintain the overall
65+
// structure by returning dedent tokens whenever a dedent occurs, even
66+
// if no dedent is expected.
67+
$.comment,
68+
69+
// Allow the external scanner to check for the validity of closing brackets
70+
// so that it can avoid returning dedent tokens between brackets.
71+
']',
72+
')',
73+
'}',
6174
],
6275

6376
inline: $ => [

src/grammar.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5205,6 +5205,22 @@
52055205
{
52065206
"type": "SYMBOL",
52075207
"name": "_string_end"
5208+
},
5209+
{
5210+
"type": "SYMBOL",
5211+
"name": "comment"
5212+
},
5213+
{
5214+
"type": "STRING",
5215+
"value": "]"
5216+
},
5217+
{
5218+
"type": "STRING",
5219+
"value": ")"
5220+
},
5221+
{
5222+
"type": "STRING",
5223+
"value": "}"
52085224
}
52095225
],
52105226
"inline": [

0 commit comments

Comments
 (0)