summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-02-10 03:37:17 (GMT)
committerGitHub <noreply@github.com>2022-02-10 03:37:17 (GMT)
commitb71dc71905ab674ccaa4a56230d17a28f61c325c (patch)
treeec6148ebc665d0beecc006afd4f6fea6b7139b9a /Grammar
parentcb68788dcadf43b47292bab7816a5ed9efa69730 (diff)
downloadcpython-b71dc71905ab674ccaa4a56230d17a28f61c325c.zip
cpython-b71dc71905ab674ccaa4a56230d17a28f61c325c.tar.gz
cpython-b71dc71905ab674ccaa4a56230d17a28f61c325c.tar.bz2
bpo-46707: Avoid potential exponential backtracking in some syntax errors (GH-31241)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram4
1 files changed, 3 insertions, 1 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index c5a5f1b..230d6ca 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -1095,13 +1095,15 @@ 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:
| 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 '='?") }
- | !(list|tuple|genexp|'True'|'None'|'False') a=bitwise_or b='=' bitwise_or !('='|':=') {
+ | !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 '='?",
_PyPegen_get_expr_name(a)) }