diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-07-27 17:52:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-27 17:52:32 (GMT) |
commit | b977f8510e2ff4f11e3bda920722098a242fc8cc (patch) | |
tree | 2e482298654ce04f9a484606f75ee6b63ba7ea2c /Grammar | |
parent | be2415487ab80e4bd5ace2954651e78b107b17e4 (diff) | |
download | cpython-b977f8510e2ff4f11e3bda920722098a242fc8cc.zip cpython-b977f8510e2ff4f11e3bda920722098a242fc8cc.tar.gz cpython-b977f8510e2ff4f11e3bda920722098a242fc8cc.tar.bz2 |
[3.10] bpo-34013: Generalize the invalid legacy statement error message (GH-27389). (GH-27391)
(cherry picked from commit 6948964ecf94e858448dd28eea634317226d2913)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 6b2fa6a..d3b0fd5 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -848,10 +848,15 @@ expression_without_invalid[expr_ty]: | a=disjunction 'if' b=disjunction 'else' c=expression { _PyAST_IfExp(b, a, c, EXTRA) } | disjunction | lambdef +invalid_legacy_expression: + | a=NAME b=expression_without_invalid { + _PyPegen_check_legacy_stmt(p, a) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "Missing parentheses in call to '%U'.", a->v.Name.id) : NULL} + invalid_expression: + | invalid_legacy_expression # !(NAME STRING) is not matched so we don't show this error with some invalid string prefixes like: kf"dsfsdf" # 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 { + | !(NAME STRING | SOFT_KEYWORD) a=disjunction b=expression_without_invalid { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") } invalid_named_expression: |