Skip to content

Commit ac87868

Browse files
committed
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.
1 parent 1e51703 commit ac87868

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

python/extractor/tsg-python/tsp/grammar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,14 +751,14 @@ module.exports = grammar({
751751
$.comparison_operator,
752752
$.not_operator,
753753
$.boolean_operator,
754-
$.await,
755754
$.lambda,
756755
$.primary_expression,
757756
$.conditional_expression,
758757
$.named_expression
759758
),
760759

761760
primary_expression: $ => choice(
761+
$.await,
762762
$.binary_operator,
763763
$.identifier,
764764
$.keyword_identifier,
@@ -1202,7 +1202,7 @@ module.exports = grammar({
12021202

12031203
await: $ => prec(PREC.unary, seq(
12041204
'await',
1205-
$.expression
1205+
$.primary_expression
12061206
)),
12071207

12081208
comment: $ => token(seq('#', /.*/)),

0 commit comments

Comments
 (0)