Python: Fix parsing of await inside expressions

Found when parsing `Lib/test/test_coroutines.py` using the new parser.

For whatever reason, having `await` be an `expression` (with an argument
of the same kind) resulted in a bad parse. Consulting the official
grammar, we see that `await` should actually be a `primary_expression`
instead. This is also more in line with the other unary operators, whose
precedence is shared by the `await` syntax.
This commit is contained in:
Taus
2024-10-25 15:59:37 +00:00
parent 1e51703ce9
commit ac87868097

View File

@@ -751,7 +751,6 @@ module.exports = grammar({
$.comparison_operator, $.comparison_operator,
$.not_operator, $.not_operator,
$.boolean_operator, $.boolean_operator,
$.await,
$.lambda, $.lambda,
$.primary_expression, $.primary_expression,
$.conditional_expression, $.conditional_expression,
@@ -759,6 +758,7 @@ module.exports = grammar({
), ),
primary_expression: $ => choice( primary_expression: $ => choice(
$.await,
$.binary_operator, $.binary_operator,
$.identifier, $.identifier,
$.keyword_identifier, $.keyword_identifier,
@@ -1202,7 +1202,7 @@ module.exports = grammar({
await: $ => prec(PREC.unary, seq( await: $ => prec(PREC.unary, seq(
'await', 'await',
$.expression $.primary_expression
)), )),
comment: $ => token(seq('#', /.*/)), comment: $ => token(seq('#', /.*/)),