summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-02-10 13:12:14 (GMT)
committerGitHub <noreply@github.com>2022-02-10 13:12:14 (GMT)
commit390459de6db1e68b79c0897cc88c0d562693ec5c (patch)
tree797c720a46e689baa63cc29c59a3f41511a0fb6c /Grammar
parent2cea8c29cf975a8ad7d8c3ff19d1e836c2d54707 (diff)
downloadcpython-390459de6db1e68b79c0897cc88c0d562693ec5c.zip
cpython-390459de6db1e68b79c0897cc88c0d562693ec5c.tar.gz
cpython-390459de6db1e68b79c0897cc88c0d562693ec5c.tar.bz2
Allow the parser to avoid nested processing of invalid rules (GH-31252)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram11
1 files changed, 5 insertions, 6 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 230d6ca..c0a6469 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -1078,6 +1078,7 @@ invalid_kwarg:
RAISE_SYNTAX_ERROR_KNOWN_RANGE(
a, b, "expression cannot contain assignment, perhaps you meant \"==\"?") }
+# IMPORTANT: Note that the "_without_invalid" suffix causes the rule to not call invalid rules under it
expression_without_invalid[expr_ty]:
| a=disjunction 'if' b=disjunction 'else' c=expression { _PyAST_IfExp(b, a, c, EXTRA) }
| disjunction
@@ -1095,16 +1096,14 @@ invalid_expression:
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") }
| a=disjunction 'if' b=disjunction !('else'|':') { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected 'else' after 'if' expression") }
-invalid_left_assignment_prefixes(memo): list|tuple|genexp|'True'|'None'|'False'
-
-invalid_named_expression:
+invalid_named_expression(memo):
| a=expression ':=' expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
| a=NAME '=' b=bitwise_or !('='|':=') {
- p->in_raw_rule ? NULL : RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?") }
- | !invalid_left_assignment_prefixes a=bitwise_or b='=' bitwise_or !('='|':=') {
- p->in_raw_rule ? NULL : RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot assign to %s here. Maybe you meant '==' instead of '='?",
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?") }
+ | !(list|tuple|genexp|'True'|'None'|'False') a=bitwise_or b='=' bitwise_or !('='|':=') {
+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot assign to %s here. Maybe you meant '==' instead of '='?",
_PyPegen_get_expr_name(a)) }
invalid_assignment: