From ac8786809782d1a7a11827a2969bfb4ff4d9316f Mon Sep 17 00:00:00 2001 From: Taus Date: Fri, 25 Oct 2024 15:59:37 +0000 Subject: [PATCH] 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. --- python/extractor/tsg-python/tsp/grammar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/extractor/tsg-python/tsp/grammar.js b/python/extractor/tsg-python/tsp/grammar.js index 7016eea5b18..b41906d9d7b 100644 --- a/python/extractor/tsg-python/tsp/grammar.js +++ b/python/extractor/tsg-python/tsp/grammar.js @@ -751,7 +751,6 @@ module.exports = grammar({ $.comparison_operator, $.not_operator, $.boolean_operator, - $.await, $.lambda, $.primary_expression, $.conditional_expression, @@ -759,6 +758,7 @@ module.exports = grammar({ ), primary_expression: $ => choice( + $.await, $.binary_operator, $.identifier, $.keyword_identifier, @@ -1202,7 +1202,7 @@ module.exports = grammar({ await: $ => prec(PREC.unary, seq( 'await', - $.expression + $.primary_expression )), comment: $ => token(seq('#', /.*/)),