mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
bpo-45727: Make the syntax error for missing comma more consistent (GH-29427)
This commit is contained in:
parent
c8c21bdd19
commit
546cefcda7
4 changed files with 27 additions and 24 deletions
|
@ -618,6 +618,7 @@ expressions[expr_ty]:
|
|||
|
||||
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
|
||||
|
@ -1080,11 +1081,10 @@ 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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue