summaryrefslogtreecommitdiffstats
path: root/Parser/parser.c
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2021-11-19 23:11:57 (GMT)
committerGitHub <noreply@github.com>2021-11-19 23:11:57 (GMT)
commit546cefcda75d7150b55c8bc1724bea35a1e12890 (patch)
tree18d9c398c5d6cdc610bffcedfc74a82c5250a0c6 /Parser/parser.c
parentc8c21bdd199f9feb75fc6cdb398a686dc133b99f (diff)
downloadcpython-546cefcda75d7150b55c8bc1724bea35a1e12890.zip
cpython-546cefcda75d7150b55c8bc1724bea35a1e12890.tar.gz
cpython-546cefcda75d7150b55c8bc1724bea35a1e12890.tar.bz2
bpo-45727: Make the syntax error for missing comma more consistent (GH-29427)
Diffstat (limited to 'Parser/parser.c')
-rw-r--r--Parser/parser.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/Parser/parser.c b/Parser/parser.c
index b508c1d..87f492d 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -9719,6 +9719,7 @@ expressions_rule(Parser *p)
// expression:
// | invalid_expression
+// | invalid_legacy_expression
// | disjunction 'if' disjunction 'else' expression
// | disjunction
// | lambdef
@@ -9764,6 +9765,25 @@ expression_rule(Parser *p)
D(fprintf(stderr, "%*c%s expression[%d-%d]: %s failed!\n", p->level, ' ',
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_expression"));
}
+ if (p->call_invalid_rules) { // invalid_legacy_expression
+ if (p->error_indicator) {
+ D(p->level--);
+ return NULL;
+ }
+ D(fprintf(stderr, "%*c> expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_legacy_expression"));
+ void *invalid_legacy_expression_var;
+ if (
+ (invalid_legacy_expression_var = invalid_legacy_expression_rule(p)) // invalid_legacy_expression
+ )
+ {
+ D(fprintf(stderr, "%*c+ expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_legacy_expression"));
+ _res = invalid_legacy_expression_var;
+ goto done;
+ }
+ p->mark = _mark;
+ D(fprintf(stderr, "%*c%s expression[%d-%d]: %s failed!\n", p->level, ' ',
+ p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_legacy_expression"));
+ }
{ // disjunction 'if' disjunction 'else' expression
if (p->error_indicator) {
D(p->level--);
@@ -18239,7 +18259,6 @@ invalid_legacy_expression_rule(Parser *p)
}
// invalid_expression:
-// | invalid_legacy_expression
// | !(NAME STRING | SOFT_KEYWORD) disjunction expression_without_invalid
// | disjunction 'if' disjunction !('else' | ':')
static void *
@@ -18252,25 +18271,6 @@ invalid_expression_rule(Parser *p)
}
void * _res = NULL;
int _mark = p->mark;
- if (p->call_invalid_rules) { // invalid_legacy_expression
- if (p->error_indicator) {
- D(p->level--);
- return NULL;
- }
- D(fprintf(stderr, "%*c> invalid_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_legacy_expression"));
- void *invalid_legacy_expression_var;
- if (
- (invalid_legacy_expression_var = invalid_legacy_expression_rule(p)) // invalid_legacy_expression
- )
- {
- D(fprintf(stderr, "%*c+ invalid_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_legacy_expression"));
- _res = invalid_legacy_expression_var;
- goto done;
- }
- p->mark = _mark;
- D(fprintf(stderr, "%*c%s invalid_expression[%d-%d]: %s failed!\n", p->level, ' ',
- p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_legacy_expression"));
- }
{ // !(NAME STRING | SOFT_KEYWORD) disjunction expression_without_invalid
if (p->error_indicator) {
D(p->level--);
@@ -18288,7 +18288,7 @@ invalid_expression_rule(Parser *p)
)
{
D(fprintf(stderr, "%*c+ invalid_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "!(NAME STRING | SOFT_KEYWORD) disjunction expression_without_invalid"));
- _res = RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , b , "invalid syntax. Perhaps you forgot a comma?" );
+ _res = _PyPegen_check_legacy_stmt ( p , a ) ? NULL : RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , b , "invalid syntax. Perhaps you forgot a comma?" );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
D(p->level--);