mirror of https://github.com/python/cpython.git
gh-129858: Special syntax error for `elif` block after `else` (#129902)
This commit is contained in:
parent
c3a7118065
commit
99b71efe8e
|
@ -348,6 +348,21 @@ Improved error messages
|
||||||
^^^^^^^
|
^^^^^^^
|
||||||
ValueError: too many values to unpack (expected 3, got 4)
|
ValueError: too many values to unpack (expected 3, got 4)
|
||||||
|
|
||||||
|
* :keyword:`elif` statements that follow an :keyword:`else` block now have a specific error message.
|
||||||
|
(Contributed by Steele Farnsworth in :gh:`129902`.)
|
||||||
|
|
||||||
|
.. code-block:: pycon
|
||||||
|
|
||||||
|
>>> if who == "me":
|
||||||
|
... print("It's me!")
|
||||||
|
... else:
|
||||||
|
... print("It's not me!")
|
||||||
|
... elif who is None:
|
||||||
|
... print("Who is it?")
|
||||||
|
File "<stdin>", line 5
|
||||||
|
elif who is None:
|
||||||
|
^^^^
|
||||||
|
SyntaxError: 'elif' block follows an 'else' block
|
||||||
|
|
||||||
* If a statement (:keyword:`pass`, :keyword:`del`, :keyword:`return`,
|
* If a statement (:keyword:`pass`, :keyword:`del`, :keyword:`return`,
|
||||||
:keyword:`yield`, :keyword:`raise`, :keyword:`break`, :keyword:`continue`,
|
:keyword:`yield`, :keyword:`raise`, :keyword:`break`, :keyword:`continue`,
|
||||||
|
|
|
@ -1422,6 +1422,7 @@ invalid_elif_stmt:
|
||||||
invalid_else_stmt:
|
invalid_else_stmt:
|
||||||
| a='else' ':' NEWLINE !INDENT {
|
| a='else' ':' NEWLINE !INDENT {
|
||||||
RAISE_INDENTATION_ERROR("expected an indented block after 'else' statement on line %d", a->lineno) }
|
RAISE_INDENTATION_ERROR("expected an indented block after 'else' statement on line %d", a->lineno) }
|
||||||
|
| 'else' ':' block 'elif' { RAISE_SYNTAX_ERROR("'elif' block follows an 'else' block")}
|
||||||
invalid_while_stmt:
|
invalid_while_stmt:
|
||||||
| 'while' named_expression NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
|
| 'while' named_expression NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
|
||||||
| a='while' named_expression ':' NEWLINE !INDENT {
|
| a='while' named_expression ':' NEWLINE !INDENT {
|
||||||
|
|
|
@ -948,6 +948,18 @@
|
||||||
...
|
...
|
||||||
SyntaxError: 'break' outside loop
|
SyntaxError: 'break' outside loop
|
||||||
|
|
||||||
|
elif can't come after an else.
|
||||||
|
|
||||||
|
>>> if a % 2 == 0:
|
||||||
|
... pass
|
||||||
|
... else:
|
||||||
|
... pass
|
||||||
|
... elif a % 2 == 1:
|
||||||
|
... pass
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
SyntaxError: 'elif' block follows an 'else' block
|
||||||
|
|
||||||
Misuse of the nonlocal and global statement can lead to a few unique syntax errors.
|
Misuse of the nonlocal and global statement can lead to a few unique syntax errors.
|
||||||
|
|
||||||
>>> def f():
|
>>> def f():
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
``elif`` statements that follow an ``else`` block now have a specific error message.
|
|
@ -23,26 +23,26 @@ static KeywordToken *reserved_keywords[] = {
|
||||||
(KeywordToken[]) {
|
(KeywordToken[]) {
|
||||||
{"if", 677},
|
{"if", 677},
|
||||||
{"as", 675},
|
{"as", 675},
|
||||||
{"in", 688},
|
{"in", 690},
|
||||||
{"or", 586},
|
{"or", 586},
|
||||||
{"is", 594},
|
{"is", 594},
|
||||||
{NULL, -1},
|
{NULL, -1},
|
||||||
},
|
},
|
||||||
(KeywordToken[]) {
|
(KeywordToken[]) {
|
||||||
{"del", 622},
|
{"del", 622},
|
||||||
{"def", 692},
|
{"def", 694},
|
||||||
{"for", 687},
|
{"for", 689},
|
||||||
{"try", 651},
|
{"try", 651},
|
||||||
{"and", 587},
|
{"and", 587},
|
||||||
{"not", 696},
|
{"not", 698},
|
||||||
{NULL, -1},
|
{NULL, -1},
|
||||||
},
|
},
|
||||||
(KeywordToken[]) {
|
(KeywordToken[]) {
|
||||||
{"from", 630},
|
{"from", 630},
|
||||||
{"pass", 526},
|
{"pass", 526},
|
||||||
{"with", 642},
|
{"with", 642},
|
||||||
{"elif", 679},
|
{"elif", 682},
|
||||||
{"else", 680},
|
{"else", 681},
|
||||||
{"None", 620},
|
{"None", 620},
|
||||||
{"True", 619},
|
{"True", 619},
|
||||||
{NULL, -1},
|
{NULL, -1},
|
||||||
|
@ -51,9 +51,9 @@ static KeywordToken *reserved_keywords[] = {
|
||||||
{"raise", 525},
|
{"raise", 525},
|
||||||
{"yield", 585},
|
{"yield", 585},
|
||||||
{"break", 527},
|
{"break", 527},
|
||||||
{"async", 691},
|
{"async", 693},
|
||||||
{"class", 694},
|
{"class", 696},
|
||||||
{"while", 682},
|
{"while", 684},
|
||||||
{"False", 621},
|
{"False", 621},
|
||||||
{"await", 595},
|
{"await", 595},
|
||||||
{NULL, -1},
|
{NULL, -1},
|
||||||
|
@ -2013,7 +2013,7 @@ compound_stmt_rule(Parser *p)
|
||||||
D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'while' while_stmt"));
|
D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'while' while_stmt"));
|
||||||
stmt_ty while_stmt_var;
|
stmt_ty while_stmt_var;
|
||||||
if (
|
if (
|
||||||
_PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 682) // token='while'
|
_PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 684) // token='while'
|
||||||
&&
|
&&
|
||||||
(while_stmt_var = while_stmt_rule(p)) // while_stmt
|
(while_stmt_var = while_stmt_rule(p)) // while_stmt
|
||||||
)
|
)
|
||||||
|
@ -4336,7 +4336,7 @@ class_def_raw_rule(Parser *p)
|
||||||
asdl_stmt_seq* c;
|
asdl_stmt_seq* c;
|
||||||
void *t;
|
void *t;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 694)) // token='class'
|
(_keyword = _PyPegen_expect_token(p, 696)) // token='class'
|
||||||
&&
|
&&
|
||||||
(a = _PyPegen_name_token(p)) // NAME
|
(a = _PyPegen_name_token(p)) // NAME
|
||||||
&&
|
&&
|
||||||
|
@ -4503,7 +4503,7 @@ function_def_raw_rule(Parser *p)
|
||||||
void *t;
|
void *t;
|
||||||
void *tc;
|
void *tc;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 692)) // token='def'
|
(_keyword = _PyPegen_expect_token(p, 694)) // token='def'
|
||||||
&&
|
&&
|
||||||
(n = _PyPegen_name_token(p)) // NAME
|
(n = _PyPegen_name_token(p)) // NAME
|
||||||
&&
|
&&
|
||||||
|
@ -4564,9 +4564,9 @@ function_def_raw_rule(Parser *p)
|
||||||
void *t;
|
void *t;
|
||||||
void *tc;
|
void *tc;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 691)) // token='async'
|
(_keyword = _PyPegen_expect_token(p, 693)) // token='async'
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 692)) // token='def'
|
(_keyword_1 = _PyPegen_expect_token(p, 694)) // token='def'
|
||||||
&&
|
&&
|
||||||
(n = _PyPegen_name_token(p)) // NAME
|
(n = _PyPegen_name_token(p)) // NAME
|
||||||
&&
|
&&
|
||||||
|
@ -6044,7 +6044,7 @@ elif_stmt_rule(Parser *p)
|
||||||
asdl_stmt_seq* b;
|
asdl_stmt_seq* b;
|
||||||
stmt_ty c;
|
stmt_ty c;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 679)) // token='elif'
|
(_keyword = _PyPegen_expect_token(p, 682)) // token='elif'
|
||||||
&&
|
&&
|
||||||
(a = named_expression_rule(p)) // named_expression
|
(a = named_expression_rule(p)) // named_expression
|
||||||
&&
|
&&
|
||||||
|
@ -6089,7 +6089,7 @@ elif_stmt_rule(Parser *p)
|
||||||
asdl_stmt_seq* b;
|
asdl_stmt_seq* b;
|
||||||
void *c;
|
void *c;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 679)) // token='elif'
|
(_keyword = _PyPegen_expect_token(p, 682)) // token='elif'
|
||||||
&&
|
&&
|
||||||
(a = named_expression_rule(p)) // named_expression
|
(a = named_expression_rule(p)) // named_expression
|
||||||
&&
|
&&
|
||||||
|
@ -6170,7 +6170,7 @@ else_block_rule(Parser *p)
|
||||||
Token * _literal;
|
Token * _literal;
|
||||||
asdl_stmt_seq* b;
|
asdl_stmt_seq* b;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 680)) // token='else'
|
(_keyword = _PyPegen_expect_token(p, 681)) // token='else'
|
||||||
&&
|
&&
|
||||||
(_literal = _PyPegen_expect_forced_token(p, 11, ":")) // forced_token=':'
|
(_literal = _PyPegen_expect_forced_token(p, 11, ":")) // forced_token=':'
|
||||||
&&
|
&&
|
||||||
|
@ -6249,7 +6249,7 @@ while_stmt_rule(Parser *p)
|
||||||
asdl_stmt_seq* b;
|
asdl_stmt_seq* b;
|
||||||
void *c;
|
void *c;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 682)) // token='while'
|
(_keyword = _PyPegen_expect_token(p, 684)) // token='while'
|
||||||
&&
|
&&
|
||||||
(a = named_expression_rule(p)) // named_expression
|
(a = named_expression_rule(p)) // named_expression
|
||||||
&&
|
&&
|
||||||
|
@ -6349,11 +6349,11 @@ for_stmt_rule(Parser *p)
|
||||||
expr_ty t;
|
expr_ty t;
|
||||||
void *tc;
|
void *tc;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 687)) // token='for'
|
(_keyword = _PyPegen_expect_token(p, 689)) // token='for'
|
||||||
&&
|
&&
|
||||||
(t = star_targets_rule(p)) // star_targets
|
(t = star_targets_rule(p)) // star_targets
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 688)) // token='in'
|
(_keyword_1 = _PyPegen_expect_token(p, 690)) // token='in'
|
||||||
&&
|
&&
|
||||||
(_cut_var = 1)
|
(_cut_var = 1)
|
||||||
&&
|
&&
|
||||||
|
@ -6411,13 +6411,13 @@ for_stmt_rule(Parser *p)
|
||||||
expr_ty t;
|
expr_ty t;
|
||||||
void *tc;
|
void *tc;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 691)) // token='async'
|
(_keyword = _PyPegen_expect_token(p, 693)) // token='async'
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 687)) // token='for'
|
(_keyword_1 = _PyPegen_expect_token(p, 689)) // token='for'
|
||||||
&&
|
&&
|
||||||
(t = star_targets_rule(p)) // star_targets
|
(t = star_targets_rule(p)) // star_targets
|
||||||
&&
|
&&
|
||||||
(_keyword_2 = _PyPegen_expect_token(p, 688)) // token='in'
|
(_keyword_2 = _PyPegen_expect_token(p, 690)) // token='in'
|
||||||
&&
|
&&
|
||||||
(_cut_var = 1)
|
(_cut_var = 1)
|
||||||
&&
|
&&
|
||||||
|
@ -6646,7 +6646,7 @@ with_stmt_rule(Parser *p)
|
||||||
asdl_withitem_seq* a;
|
asdl_withitem_seq* a;
|
||||||
asdl_stmt_seq* b;
|
asdl_stmt_seq* b;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 691)) // token='async'
|
(_keyword = _PyPegen_expect_token(p, 693)) // token='async'
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 642)) // token='with'
|
(_keyword_1 = _PyPegen_expect_token(p, 642)) // token='with'
|
||||||
&&
|
&&
|
||||||
|
@ -6698,7 +6698,7 @@ with_stmt_rule(Parser *p)
|
||||||
asdl_stmt_seq* b;
|
asdl_stmt_seq* b;
|
||||||
void *tc;
|
void *tc;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 691)) // token='async'
|
(_keyword = _PyPegen_expect_token(p, 693)) // token='async'
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 642)) // token='with'
|
(_keyword_1 = _PyPegen_expect_token(p, 642)) // token='with'
|
||||||
&&
|
&&
|
||||||
|
@ -11254,7 +11254,7 @@ expression_rule(Parser *p)
|
||||||
&&
|
&&
|
||||||
(b = disjunction_rule(p)) // disjunction
|
(b = disjunction_rule(p)) // disjunction
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 680)) // token='else'
|
(_keyword_1 = _PyPegen_expect_token(p, 681)) // token='else'
|
||||||
&&
|
&&
|
||||||
(c = expression_rule(p)) // expression
|
(c = expression_rule(p)) // expression
|
||||||
)
|
)
|
||||||
|
@ -12136,7 +12136,7 @@ inversion_rule(Parser *p)
|
||||||
Token * _keyword;
|
Token * _keyword;
|
||||||
expr_ty a;
|
expr_ty a;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 696)) // token='not'
|
(_keyword = _PyPegen_expect_token(p, 698)) // token='not'
|
||||||
&&
|
&&
|
||||||
(a = inversion_rule(p)) // inversion
|
(a = inversion_rule(p)) // inversion
|
||||||
)
|
)
|
||||||
|
@ -12790,9 +12790,9 @@ notin_bitwise_or_rule(Parser *p)
|
||||||
Token * _keyword_1;
|
Token * _keyword_1;
|
||||||
expr_ty a;
|
expr_ty a;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 696)) // token='not'
|
(_keyword = _PyPegen_expect_token(p, 698)) // token='not'
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 688)) // token='in'
|
(_keyword_1 = _PyPegen_expect_token(p, 690)) // token='in'
|
||||||
&&
|
&&
|
||||||
(a = bitwise_or_rule(p)) // bitwise_or
|
(a = bitwise_or_rule(p)) // bitwise_or
|
||||||
)
|
)
|
||||||
|
@ -12838,7 +12838,7 @@ in_bitwise_or_rule(Parser *p)
|
||||||
Token * _keyword;
|
Token * _keyword;
|
||||||
expr_ty a;
|
expr_ty a;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 688)) // token='in'
|
(_keyword = _PyPegen_expect_token(p, 690)) // token='in'
|
||||||
&&
|
&&
|
||||||
(a = bitwise_or_rule(p)) // bitwise_or
|
(a = bitwise_or_rule(p)) // bitwise_or
|
||||||
)
|
)
|
||||||
|
@ -12887,7 +12887,7 @@ isnot_bitwise_or_rule(Parser *p)
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 594)) // token='is'
|
(_keyword = _PyPegen_expect_token(p, 594)) // token='is'
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 696)) // token='not'
|
(_keyword_1 = _PyPegen_expect_token(p, 698)) // token='not'
|
||||||
&&
|
&&
|
||||||
(a = bitwise_or_rule(p)) // bitwise_or
|
(a = bitwise_or_rule(p)) // bitwise_or
|
||||||
)
|
)
|
||||||
|
@ -17058,13 +17058,13 @@ for_if_clause_rule(Parser *p)
|
||||||
expr_ty b;
|
expr_ty b;
|
||||||
asdl_expr_seq* c;
|
asdl_expr_seq* c;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 691)) // token='async'
|
(_keyword = _PyPegen_expect_token(p, 693)) // token='async'
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 687)) // token='for'
|
(_keyword_1 = _PyPegen_expect_token(p, 689)) // token='for'
|
||||||
&&
|
&&
|
||||||
(a = star_targets_rule(p)) // star_targets
|
(a = star_targets_rule(p)) // star_targets
|
||||||
&&
|
&&
|
||||||
(_keyword_2 = _PyPegen_expect_token(p, 688)) // token='in'
|
(_keyword_2 = _PyPegen_expect_token(p, 690)) // token='in'
|
||||||
&&
|
&&
|
||||||
(_cut_var = 1)
|
(_cut_var = 1)
|
||||||
&&
|
&&
|
||||||
|
@ -17103,11 +17103,11 @@ for_if_clause_rule(Parser *p)
|
||||||
expr_ty b;
|
expr_ty b;
|
||||||
asdl_expr_seq* c;
|
asdl_expr_seq* c;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 687)) // token='for'
|
(_keyword = _PyPegen_expect_token(p, 689)) // token='for'
|
||||||
&&
|
&&
|
||||||
(a = star_targets_rule(p)) // star_targets
|
(a = star_targets_rule(p)) // star_targets
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 688)) // token='in'
|
(_keyword_1 = _PyPegen_expect_token(p, 690)) // token='in'
|
||||||
&&
|
&&
|
||||||
(_cut_var = 1)
|
(_cut_var = 1)
|
||||||
&&
|
&&
|
||||||
|
@ -20412,7 +20412,7 @@ expression_without_invalid_rule(Parser *p)
|
||||||
&&
|
&&
|
||||||
(b = disjunction_rule(p)) // disjunction
|
(b = disjunction_rule(p)) // disjunction
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 680)) // token='else'
|
(_keyword_1 = _PyPegen_expect_token(p, 681)) // token='else'
|
||||||
&&
|
&&
|
||||||
(c = expression_rule(p)) // expression
|
(c = expression_rule(p)) // expression
|
||||||
)
|
)
|
||||||
|
@ -20748,7 +20748,7 @@ invalid_expression_rule(Parser *p)
|
||||||
&&
|
&&
|
||||||
(b = disjunction_rule(p)) // disjunction
|
(b = disjunction_rule(p)) // disjunction
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 680)) // token='else'
|
(_keyword_1 = _PyPegen_expect_token(p, 681)) // token='else'
|
||||||
&&
|
&&
|
||||||
_PyPegen_lookahead(0, (void *(*)(Parser *)) expression_rule, p)
|
_PyPegen_lookahead(0, (void *(*)(Parser *)) expression_rule, p)
|
||||||
)
|
)
|
||||||
|
@ -20784,7 +20784,7 @@ invalid_expression_rule(Parser *p)
|
||||||
&&
|
&&
|
||||||
(b = disjunction_rule(p)) // disjunction
|
(b = disjunction_rule(p)) // disjunction
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 680)) // token='else'
|
(_keyword_1 = _PyPegen_expect_token(p, 681)) // token='else'
|
||||||
&&
|
&&
|
||||||
(c = simple_stmt_rule(p)) // simple_stmt
|
(c = simple_stmt_rule(p)) // simple_stmt
|
||||||
)
|
)
|
||||||
|
@ -22770,13 +22770,13 @@ invalid_for_if_clause_rule(Parser *p)
|
||||||
UNUSED(_opt_var); // Silence compiler warnings
|
UNUSED(_opt_var); // Silence compiler warnings
|
||||||
void *_tmp_133_var;
|
void *_tmp_133_var;
|
||||||
if (
|
if (
|
||||||
(_opt_var = _PyPegen_expect_token(p, 691), !p->error_indicator) // 'async'?
|
(_opt_var = _PyPegen_expect_token(p, 693), !p->error_indicator) // 'async'?
|
||||||
&&
|
&&
|
||||||
(_keyword = _PyPegen_expect_token(p, 687)) // token='for'
|
(_keyword = _PyPegen_expect_token(p, 689)) // token='for'
|
||||||
&&
|
&&
|
||||||
(_tmp_133_var = _tmp_133_rule(p)) // bitwise_or ((',' bitwise_or))* ','?
|
(_tmp_133_var = _tmp_133_rule(p)) // bitwise_or ((',' bitwise_or))* ','?
|
||||||
&&
|
&&
|
||||||
_PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 688) // token='in'
|
_PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 690) // token='in'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
D(fprintf(stderr, "%*c+ invalid_for_if_clause[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'async'? 'for' (bitwise_or ((',' bitwise_or))* ','?) !'in'"));
|
D(fprintf(stderr, "%*c+ invalid_for_if_clause[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'async'? 'for' (bitwise_or ((',' bitwise_or))* ','?) !'in'"));
|
||||||
|
@ -22822,9 +22822,9 @@ invalid_for_target_rule(Parser *p)
|
||||||
UNUSED(_opt_var); // Silence compiler warnings
|
UNUSED(_opt_var); // Silence compiler warnings
|
||||||
expr_ty a;
|
expr_ty a;
|
||||||
if (
|
if (
|
||||||
(_opt_var = _PyPegen_expect_token(p, 691), !p->error_indicator) // 'async'?
|
(_opt_var = _PyPegen_expect_token(p, 693), !p->error_indicator) // 'async'?
|
||||||
&&
|
&&
|
||||||
(_keyword = _PyPegen_expect_token(p, 687)) // token='for'
|
(_keyword = _PyPegen_expect_token(p, 689)) // token='for'
|
||||||
&&
|
&&
|
||||||
(a = star_expressions_rule(p)) // star_expressions
|
(a = star_expressions_rule(p)) // star_expressions
|
||||||
)
|
)
|
||||||
|
@ -23109,7 +23109,7 @@ invalid_with_stmt_rule(Parser *p)
|
||||||
UNUSED(_opt_var); // Silence compiler warnings
|
UNUSED(_opt_var); // Silence compiler warnings
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(_opt_var = _PyPegen_expect_token(p, 691), !p->error_indicator) // 'async'?
|
(_opt_var = _PyPegen_expect_token(p, 693), !p->error_indicator) // 'async'?
|
||||||
&&
|
&&
|
||||||
(_keyword = _PyPegen_expect_token(p, 642)) // token='with'
|
(_keyword = _PyPegen_expect_token(p, 642)) // token='with'
|
||||||
&&
|
&&
|
||||||
|
@ -23147,7 +23147,7 @@ invalid_with_stmt_rule(Parser *p)
|
||||||
UNUSED(_opt_var_1); // Silence compiler warnings
|
UNUSED(_opt_var_1); // Silence compiler warnings
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(_opt_var = _PyPegen_expect_token(p, 691), !p->error_indicator) // 'async'?
|
(_opt_var = _PyPegen_expect_token(p, 693), !p->error_indicator) // 'async'?
|
||||||
&&
|
&&
|
||||||
(_keyword = _PyPegen_expect_token(p, 642)) // token='with'
|
(_keyword = _PyPegen_expect_token(p, 642)) // token='with'
|
||||||
&&
|
&&
|
||||||
|
@ -23209,7 +23209,7 @@ invalid_with_stmt_indent_rule(Parser *p)
|
||||||
Token * a;
|
Token * a;
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(_opt_var = _PyPegen_expect_token(p, 691), !p->error_indicator) // 'async'?
|
(_opt_var = _PyPegen_expect_token(p, 693), !p->error_indicator) // 'async'?
|
||||||
&&
|
&&
|
||||||
(a = _PyPegen_expect_token(p, 642)) // token='with'
|
(a = _PyPegen_expect_token(p, 642)) // token='with'
|
||||||
&&
|
&&
|
||||||
|
@ -23252,7 +23252,7 @@ invalid_with_stmt_indent_rule(Parser *p)
|
||||||
Token * a;
|
Token * a;
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(_opt_var = _PyPegen_expect_token(p, 691), !p->error_indicator) // 'async'?
|
(_opt_var = _PyPegen_expect_token(p, 693), !p->error_indicator) // 'async'?
|
||||||
&&
|
&&
|
||||||
(a = _PyPegen_expect_token(p, 642)) // token='with'
|
(a = _PyPegen_expect_token(p, 642)) // token='with'
|
||||||
&&
|
&&
|
||||||
|
@ -24477,7 +24477,7 @@ invalid_elif_stmt_rule(Parser *p)
|
||||||
expr_ty named_expression_var;
|
expr_ty named_expression_var;
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 679)) // token='elif'
|
(_keyword = _PyPegen_expect_token(p, 682)) // token='elif'
|
||||||
&&
|
&&
|
||||||
(named_expression_var = named_expression_rule(p)) // named_expression
|
(named_expression_var = named_expression_rule(p)) // named_expression
|
||||||
&&
|
&&
|
||||||
|
@ -24508,7 +24508,7 @@ invalid_elif_stmt_rule(Parser *p)
|
||||||
expr_ty named_expression_var;
|
expr_ty named_expression_var;
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(a = _PyPegen_expect_token(p, 679)) // token='elif'
|
(a = _PyPegen_expect_token(p, 682)) // token='elif'
|
||||||
&&
|
&&
|
||||||
(named_expression_var = named_expression_rule(p)) // named_expression
|
(named_expression_var = named_expression_rule(p)) // named_expression
|
||||||
&&
|
&&
|
||||||
|
@ -24538,7 +24538,7 @@ invalid_elif_stmt_rule(Parser *p)
|
||||||
return _res;
|
return _res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// invalid_else_stmt: 'else' ':' NEWLINE !INDENT
|
// invalid_else_stmt: 'else' ':' NEWLINE !INDENT | 'else' ':' block 'elif'
|
||||||
static void *
|
static void *
|
||||||
invalid_else_stmt_rule(Parser *p)
|
invalid_else_stmt_rule(Parser *p)
|
||||||
{
|
{
|
||||||
|
@ -24561,7 +24561,7 @@ invalid_else_stmt_rule(Parser *p)
|
||||||
Token * a;
|
Token * a;
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(a = _PyPegen_expect_token(p, 680)) // token='else'
|
(a = _PyPegen_expect_token(p, 681)) // token='else'
|
||||||
&&
|
&&
|
||||||
(_literal = _PyPegen_expect_token(p, 11)) // token=':'
|
(_literal = _PyPegen_expect_token(p, 11)) // token=':'
|
||||||
&&
|
&&
|
||||||
|
@ -24583,6 +24583,39 @@ invalid_else_stmt_rule(Parser *p)
|
||||||
D(fprintf(stderr, "%*c%s invalid_else_stmt[%d-%d]: %s failed!\n", p->level, ' ',
|
D(fprintf(stderr, "%*c%s invalid_else_stmt[%d-%d]: %s failed!\n", p->level, ' ',
|
||||||
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'else' ':' NEWLINE !INDENT"));
|
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'else' ':' NEWLINE !INDENT"));
|
||||||
}
|
}
|
||||||
|
{ // 'else' ':' block 'elif'
|
||||||
|
if (p->error_indicator) {
|
||||||
|
p->level--;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
D(fprintf(stderr, "%*c> invalid_else_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'else' ':' block 'elif'"));
|
||||||
|
Token * _keyword;
|
||||||
|
Token * _keyword_1;
|
||||||
|
Token * _literal;
|
||||||
|
asdl_stmt_seq* block_var;
|
||||||
|
if (
|
||||||
|
(_keyword = _PyPegen_expect_token(p, 681)) // token='else'
|
||||||
|
&&
|
||||||
|
(_literal = _PyPegen_expect_token(p, 11)) // token=':'
|
||||||
|
&&
|
||||||
|
(block_var = block_rule(p)) // block
|
||||||
|
&&
|
||||||
|
(_keyword_1 = _PyPegen_expect_token(p, 682)) // token='elif'
|
||||||
|
)
|
||||||
|
{
|
||||||
|
D(fprintf(stderr, "%*c+ invalid_else_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'else' ':' block 'elif'"));
|
||||||
|
_res = RAISE_SYNTAX_ERROR ( "'elif' block follows an 'else' block" );
|
||||||
|
if (_res == NULL && PyErr_Occurred()) {
|
||||||
|
p->error_indicator = 1;
|
||||||
|
p->level--;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
p->mark = _mark;
|
||||||
|
D(fprintf(stderr, "%*c%s invalid_else_stmt[%d-%d]: %s failed!\n", p->level, ' ',
|
||||||
|
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'else' ':' block 'elif'"));
|
||||||
|
}
|
||||||
_res = NULL;
|
_res = NULL;
|
||||||
done:
|
done:
|
||||||
p->level--;
|
p->level--;
|
||||||
|
@ -24614,7 +24647,7 @@ invalid_while_stmt_rule(Parser *p)
|
||||||
expr_ty named_expression_var;
|
expr_ty named_expression_var;
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 682)) // token='while'
|
(_keyword = _PyPegen_expect_token(p, 684)) // token='while'
|
||||||
&&
|
&&
|
||||||
(named_expression_var = named_expression_rule(p)) // named_expression
|
(named_expression_var = named_expression_rule(p)) // named_expression
|
||||||
&&
|
&&
|
||||||
|
@ -24645,7 +24678,7 @@ invalid_while_stmt_rule(Parser *p)
|
||||||
expr_ty named_expression_var;
|
expr_ty named_expression_var;
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(a = _PyPegen_expect_token(p, 682)) // token='while'
|
(a = _PyPegen_expect_token(p, 684)) // token='while'
|
||||||
&&
|
&&
|
||||||
(named_expression_var = named_expression_rule(p)) // named_expression
|
(named_expression_var = named_expression_rule(p)) // named_expression
|
||||||
&&
|
&&
|
||||||
|
@ -24704,13 +24737,13 @@ invalid_for_stmt_rule(Parser *p)
|
||||||
expr_ty star_expressions_var;
|
expr_ty star_expressions_var;
|
||||||
expr_ty star_targets_var;
|
expr_ty star_targets_var;
|
||||||
if (
|
if (
|
||||||
(_opt_var = _PyPegen_expect_token(p, 691), !p->error_indicator) // 'async'?
|
(_opt_var = _PyPegen_expect_token(p, 693), !p->error_indicator) // 'async'?
|
||||||
&&
|
&&
|
||||||
(_keyword = _PyPegen_expect_token(p, 687)) // token='for'
|
(_keyword = _PyPegen_expect_token(p, 689)) // token='for'
|
||||||
&&
|
&&
|
||||||
(star_targets_var = star_targets_rule(p)) // star_targets
|
(star_targets_var = star_targets_rule(p)) // star_targets
|
||||||
&&
|
&&
|
||||||
(_keyword_1 = _PyPegen_expect_token(p, 688)) // token='in'
|
(_keyword_1 = _PyPegen_expect_token(p, 690)) // token='in'
|
||||||
&&
|
&&
|
||||||
(star_expressions_var = star_expressions_rule(p)) // star_expressions
|
(star_expressions_var = star_expressions_rule(p)) // star_expressions
|
||||||
&&
|
&&
|
||||||
|
@ -24745,13 +24778,13 @@ invalid_for_stmt_rule(Parser *p)
|
||||||
expr_ty star_expressions_var;
|
expr_ty star_expressions_var;
|
||||||
expr_ty star_targets_var;
|
expr_ty star_targets_var;
|
||||||
if (
|
if (
|
||||||
(_opt_var = _PyPegen_expect_token(p, 691), !p->error_indicator) // 'async'?
|
(_opt_var = _PyPegen_expect_token(p, 693), !p->error_indicator) // 'async'?
|
||||||
&&
|
&&
|
||||||
(a = _PyPegen_expect_token(p, 687)) // token='for'
|
(a = _PyPegen_expect_token(p, 689)) // token='for'
|
||||||
&&
|
&&
|
||||||
(star_targets_var = star_targets_rule(p)) // star_targets
|
(star_targets_var = star_targets_rule(p)) // star_targets
|
||||||
&&
|
&&
|
||||||
(_keyword = _PyPegen_expect_token(p, 688)) // token='in'
|
(_keyword = _PyPegen_expect_token(p, 690)) // token='in'
|
||||||
&&
|
&&
|
||||||
(star_expressions_var = star_expressions_rule(p)) // star_expressions
|
(star_expressions_var = star_expressions_rule(p)) // star_expressions
|
||||||
&&
|
&&
|
||||||
|
@ -24817,9 +24850,9 @@ invalid_def_raw_rule(Parser *p)
|
||||||
expr_ty name_var;
|
expr_ty name_var;
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(_opt_var = _PyPegen_expect_token(p, 691), !p->error_indicator) // 'async'?
|
(_opt_var = _PyPegen_expect_token(p, 693), !p->error_indicator) // 'async'?
|
||||||
&&
|
&&
|
||||||
(a = _PyPegen_expect_token(p, 692)) // token='def'
|
(a = _PyPegen_expect_token(p, 694)) // token='def'
|
||||||
&&
|
&&
|
||||||
(name_var = _PyPegen_name_token(p)) // NAME
|
(name_var = _PyPegen_name_token(p)) // NAME
|
||||||
&&
|
&&
|
||||||
|
@ -24876,9 +24909,9 @@ invalid_def_raw_rule(Parser *p)
|
||||||
asdl_stmt_seq* block_var;
|
asdl_stmt_seq* block_var;
|
||||||
expr_ty name_var;
|
expr_ty name_var;
|
||||||
if (
|
if (
|
||||||
(_opt_var = _PyPegen_expect_token(p, 691), !p->error_indicator) // 'async'?
|
(_opt_var = _PyPegen_expect_token(p, 693), !p->error_indicator) // 'async'?
|
||||||
&&
|
&&
|
||||||
(_keyword = _PyPegen_expect_token(p, 692)) // token='def'
|
(_keyword = _PyPegen_expect_token(p, 694)) // token='def'
|
||||||
&&
|
&&
|
||||||
(name_var = _PyPegen_name_token(p)) // NAME
|
(name_var = _PyPegen_name_token(p)) // NAME
|
||||||
&&
|
&&
|
||||||
|
@ -24942,7 +24975,7 @@ invalid_class_def_raw_rule(Parser *p)
|
||||||
expr_ty name_var;
|
expr_ty name_var;
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 694)) // token='class'
|
(_keyword = _PyPegen_expect_token(p, 696)) // token='class'
|
||||||
&&
|
&&
|
||||||
(name_var = _PyPegen_name_token(p)) // NAME
|
(name_var = _PyPegen_name_token(p)) // NAME
|
||||||
&&
|
&&
|
||||||
|
@ -24981,7 +25014,7 @@ invalid_class_def_raw_rule(Parser *p)
|
||||||
expr_ty name_var;
|
expr_ty name_var;
|
||||||
Token * newline_var;
|
Token * newline_var;
|
||||||
if (
|
if (
|
||||||
(a = _PyPegen_expect_token(p, 694)) // token='class'
|
(a = _PyPegen_expect_token(p, 696)) // token='class'
|
||||||
&&
|
&&
|
||||||
(name_var = _PyPegen_name_token(p)) // NAME
|
(name_var = _PyPegen_name_token(p)) // NAME
|
||||||
&&
|
&&
|
||||||
|
@ -25799,7 +25832,7 @@ invalid_arithmetic_rule(Parser *p)
|
||||||
&&
|
&&
|
||||||
(_tmp_150_var = _tmp_150_rule(p)) // '+' | '-' | '*' | '/' | '%' | '//' | '@'
|
(_tmp_150_var = _tmp_150_rule(p)) // '+' | '-' | '*' | '/' | '%' | '//' | '@'
|
||||||
&&
|
&&
|
||||||
(a = _PyPegen_expect_token(p, 696)) // token='not'
|
(a = _PyPegen_expect_token(p, 698)) // token='not'
|
||||||
&&
|
&&
|
||||||
(b = inversion_rule(p)) // inversion
|
(b = inversion_rule(p)) // inversion
|
||||||
)
|
)
|
||||||
|
@ -25848,7 +25881,7 @@ invalid_factor_rule(Parser *p)
|
||||||
if (
|
if (
|
||||||
(_tmp_151_var = _tmp_151_rule(p)) // '+' | '-' | '~'
|
(_tmp_151_var = _tmp_151_rule(p)) // '+' | '-' | '~'
|
||||||
&&
|
&&
|
||||||
(a = _PyPegen_expect_token(p, 696)) // token='not'
|
(a = _PyPegen_expect_token(p, 698)) // token='not'
|
||||||
&&
|
&&
|
||||||
(b = factor_rule(p)) // factor
|
(b = factor_rule(p)) // factor
|
||||||
)
|
)
|
||||||
|
@ -26252,7 +26285,7 @@ _tmp_6_rule(Parser *p)
|
||||||
D(fprintf(stderr, "%*c> _tmp_6[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'def'"));
|
D(fprintf(stderr, "%*c> _tmp_6[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'def'"));
|
||||||
Token * _keyword;
|
Token * _keyword;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 692)) // token='def'
|
(_keyword = _PyPegen_expect_token(p, 694)) // token='def'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
D(fprintf(stderr, "%*c+ _tmp_6[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'def'"));
|
D(fprintf(stderr, "%*c+ _tmp_6[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'def'"));
|
||||||
|
@ -26290,7 +26323,7 @@ _tmp_6_rule(Parser *p)
|
||||||
D(fprintf(stderr, "%*c> _tmp_6[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'async'"));
|
D(fprintf(stderr, "%*c> _tmp_6[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'async'"));
|
||||||
Token * _keyword;
|
Token * _keyword;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 691)) // token='async'
|
(_keyword = _PyPegen_expect_token(p, 693)) // token='async'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
D(fprintf(stderr, "%*c+ _tmp_6[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'async'"));
|
D(fprintf(stderr, "%*c+ _tmp_6[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'async'"));
|
||||||
|
@ -26328,7 +26361,7 @@ _tmp_7_rule(Parser *p)
|
||||||
D(fprintf(stderr, "%*c> _tmp_7[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'class'"));
|
D(fprintf(stderr, "%*c> _tmp_7[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'class'"));
|
||||||
Token * _keyword;
|
Token * _keyword;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 694)) // token='class'
|
(_keyword = _PyPegen_expect_token(p, 696)) // token='class'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
D(fprintf(stderr, "%*c+ _tmp_7[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'class'"));
|
D(fprintf(stderr, "%*c+ _tmp_7[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'class'"));
|
||||||
|
@ -26404,7 +26437,7 @@ _tmp_8_rule(Parser *p)
|
||||||
D(fprintf(stderr, "%*c> _tmp_8[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'async'"));
|
D(fprintf(stderr, "%*c> _tmp_8[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'async'"));
|
||||||
Token * _keyword;
|
Token * _keyword;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 691)) // token='async'
|
(_keyword = _PyPegen_expect_token(p, 693)) // token='async'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
D(fprintf(stderr, "%*c+ _tmp_8[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'async'"));
|
D(fprintf(stderr, "%*c+ _tmp_8[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'async'"));
|
||||||
|
@ -26442,7 +26475,7 @@ _tmp_9_rule(Parser *p)
|
||||||
D(fprintf(stderr, "%*c> _tmp_9[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'for'"));
|
D(fprintf(stderr, "%*c> _tmp_9[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'for'"));
|
||||||
Token * _keyword;
|
Token * _keyword;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 687)) // token='for'
|
(_keyword = _PyPegen_expect_token(p, 689)) // token='for'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
D(fprintf(stderr, "%*c+ _tmp_9[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'for'"));
|
D(fprintf(stderr, "%*c+ _tmp_9[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'for'"));
|
||||||
|
@ -26461,7 +26494,7 @@ _tmp_9_rule(Parser *p)
|
||||||
D(fprintf(stderr, "%*c> _tmp_9[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'async'"));
|
D(fprintf(stderr, "%*c> _tmp_9[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'async'"));
|
||||||
Token * _keyword;
|
Token * _keyword;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 691)) // token='async'
|
(_keyword = _PyPegen_expect_token(p, 693)) // token='async'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
D(fprintf(stderr, "%*c+ _tmp_9[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'async'"));
|
D(fprintf(stderr, "%*c+ _tmp_9[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'async'"));
|
||||||
|
@ -32819,7 +32852,7 @@ _tmp_113_rule(Parser *p)
|
||||||
D(fprintf(stderr, "%*c> _tmp_113[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'else'"));
|
D(fprintf(stderr, "%*c> _tmp_113[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'else'"));
|
||||||
Token * _keyword;
|
Token * _keyword;
|
||||||
if (
|
if (
|
||||||
(_keyword = _PyPegen_expect_token(p, 680)) // token='else'
|
(_keyword = _PyPegen_expect_token(p, 681)) // token='else'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
D(fprintf(stderr, "%*c+ _tmp_113[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'else'"));
|
D(fprintf(stderr, "%*c+ _tmp_113[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'else'"));
|
||||||
|
|
Loading…
Reference in New Issue