diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2024-03-26 09:30:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-26 09:30:46 (GMT) |
commit | 61599a48f52e951d8813877ee311d2a830ba2cd8 (patch) | |
tree | 8bd726feb5ade55ac2933472ad60bd1da6622fbf /Grammar | |
parent | 771902c257372e6c4df1ead4e8c46308561db7a7 (diff) | |
download | cpython-61599a48f52e951d8813877ee311d2a830ba2cd8.zip cpython-61599a48f52e951d8813877ee311d2a830ba2cd8.tar.gz cpython-61599a48f52e951d8813877ee311d2a830ba2cd8.tar.bz2 |
bpo-24612: Improve syntax error for 'not' after an operator (GH-28170)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 797c195..6966493 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -778,6 +778,7 @@ bitwise_and[expr_ty]: shift_expr[expr_ty]: | a=shift_expr '<<' b=sum { _PyAST_BinOp(a, LShift, b, EXTRA) } | a=shift_expr '>>' b=sum { _PyAST_BinOp(a, RShift, b, EXTRA) } + | invalid_arithmetic | sum # Arithmetic operators @@ -794,6 +795,7 @@ term[expr_ty]: | a=term '//' b=factor { _PyAST_BinOp(a, FloorDiv, b, EXTRA) } | a=term '%' b=factor { _PyAST_BinOp(a, Mod, b, EXTRA) } | a=term '@' b=factor { CHECK_VERSION(expr_ty, 5, "The '@' operator is", _PyAST_BinOp(a, MatMult, b, EXTRA)) } + | invalid_factor | factor factor[expr_ty] (memo): @@ -1415,3 +1417,8 @@ invalid_replacement_field: invalid_conversion_character: | '!' &(':' | '}') { RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: missing conversion character") } | '!' !NAME { RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: invalid conversion character") } + +invalid_arithmetic: + | sum ('+'|'-'|'*'|'/'|'%'|'//'|'@') a='not' b=inversion { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "'not' after an operator must be parenthesized") } +invalid_factor: + | ('+' | '-' | '~') a='not' b=factor { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "'not' after an operator must be parenthesized") } |