summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-08-02 19:05:33 (GMT)
committerGitHub <noreply@github.com>2021-08-02 19:05:33 (GMT)
commit567176249ea95c074eb80199aaf19f3a55aa3954 (patch)
treef480151241cd690cfea6c753645bb701243752ae /Grammar
parentc6e7c9860d5ac968c7a1073fdbfbd44e0e87f582 (diff)
downloadcpython-567176249ea95c074eb80199aaf19f3a55aa3954.zip
cpython-567176249ea95c074eb80199aaf19f3a55aa3954.tar.gz
cpython-567176249ea95c074eb80199aaf19f3a55aa3954.tar.bz2
bpo-44792: Improve syntax errors for if expressions (GH-27506) (GH-27565)
(cherry picked from commit 28b6dc9dd5d1ce6f8aff7e06d4ef9afdc2bc8332) Co-authored-by: Miguel Brito <5544985+miguendes@users.noreply.github.com>
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram1
1 files changed, 1 insertions, 0 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 057bcb6..3e7475a 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -859,6 +859,7 @@ invalid_expression:
# Soft keywords need to also be ignored because they can be parsed as NAME NAME
| !(NAME STRING | SOFT_KEYWORD) a=disjunction b=expression_without_invalid {
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_named_expression:
| a=expression ':=' expression {