Skip to content

Commit

Permalink
fix: give yield in _reserved_identifier a precedence of 0
Browse files Browse the repository at this point in the history
This fixes an issue where yield used as a method invocation's name is
misparsed, because the keyword `yield` is always selected in this parse
state
  • Loading branch information
amaanq committed Dec 21, 2024
1 parent 04a649d commit e75fda2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
25 changes: 14 additions & 11 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module.exports = grammar({
[$.lambda_expression, $.primary_expression],
[$.inferred_parameters, $.primary_expression],
[$.argument_list, $.record_pattern_body],
[$.yield_statement, $._reserved_identifier],
],

word: $ => $.identifier,
Expand Down Expand Up @@ -1266,17 +1267,19 @@ module.exports = grammar({
field('body', $.block),
),

_reserved_identifier: $ => prec(-3, alias(
choice(
'open',
'module',
'record',
'with',
'yield',
'sealed',
),
$.identifier,
)),
_reserved_identifier: $ => choice(
prec(-3, alias(
choice(
'open',
'module',
'record',
'with',
'sealed',
),
$.identifier,
)),
alias('yield', $.identifier),
),

this: _ => 'this',

Expand Down
9 changes: 8 additions & 1 deletion test/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ public class Keywords {
public void demo() {
int sealed = 0;
bool yield = false;
yield(1, 2);
}
}

Expand Down Expand Up @@ -1113,7 +1114,13 @@ public class Keywords {
(type_identifier)
(variable_declarator
(identifier)
(false))))))))
(false)))
(expression_statement
(method_invocation
(identifier)
(argument_list
(decimal_integer_literal)
(decimal_integer_literal)))))))))

================================================================================
Annontations
Expand Down

0 comments on commit e75fda2

Please # to comment.