diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-11-20 17:39:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-20 17:39:17 (GMT) |
commit | 511ee1c0fa4dedf32cc2b9f9fa13aa61e07bd165 (patch) | |
tree | 8eba6bc238085ac83d27012c4fcfee0705aa00e6 /Grammar | |
parent | 82f1a6edfb645abef934ae1b568dd887ff7a56b9 (diff) | |
download | cpython-511ee1c0fa4dedf32cc2b9f9fa13aa61e07bd165.zip cpython-511ee1c0fa4dedf32cc2b9f9fa13aa61e07bd165.tar.gz cpython-511ee1c0fa4dedf32cc2b9f9fa13aa61e07bd165.tar.bz2 |
[3.10] bpo-45727: Make the syntax error for missing comma more consistent (GH-29427) (GH-29647)
(cherry picked from commit 546cefcda75d7150b55c8bc1724bea35a1e12890)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 7934ccd..20cccfd 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -529,6 +529,7 @@ expressions[expr_ty]: | expression expression[expr_ty] (memo): | invalid_expression + | invalid_legacy_expression | a=disjunction 'if' b=disjunction 'else' c=expression { _PyAST_IfExp(b, a, c, EXTRA) } | disjunction | lambdef @@ -666,7 +667,6 @@ await_primary[expr_ty] (memo): | AWAIT a=primary { CHECK_VERSION(expr_ty, 5, "Await expressions are", _PyAST_Await(a, EXTRA)) } | primary primary[expr_ty]: - | invalid_primary # must be before 'primay genexp' because of invalid_genexp | a=primary '.' b=NAME { _PyAST_Attribute(a, b->v.Name.id, Load, EXTRA) } | a=primary b=genexp { _PyAST_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) } | a=primary '(' b=[arguments] ')' { @@ -856,11 +856,11 @@ invalid_legacy_expression: "Missing parentheses in call to '%U'. Did you mean %U(...)?", a->v.Name.id, 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 { - RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") } + _PyPegen_check_legacy_stmt(p, a) ? NULL : 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: @@ -902,8 +902,6 @@ invalid_del_stmt: RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) } invalid_block: | NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") } -invalid_primary: - | primary a='{' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "invalid syntax") } invalid_comprehension: | ('[' | '(' | '{') a=starred_expression for_if_clauses { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable unpacking cannot be used in comprehension") } |