diff --git a/Grammar/python.gram b/Grammar/python.gram index 8c86661..1de43be 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -1074,14 +1074,14 @@ starred_expression[expr_ty]: kwarg_or_starred[KeywordOrStarred*]: | invalid_kwarg - | a=NAME '=' b=expression { - _PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _PyAST_keyword(a->v.Name.id, b, EXTRA)), 1) } + | a=NAME '=' b=expression? { + _PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _PyAST_keyword(a->v.Name.id, b ? b : a, EXTRA)), 1) } | a=starred_expression { _PyPegen_keyword_or_starred(p, a, 0) } kwarg_or_double_starred[KeywordOrStarred*]: | invalid_kwarg - | a=NAME '=' b=expression { - _PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _PyAST_keyword(a->v.Name.id, b, EXTRA)), 1) } + | a=NAME '=' b=expression? { + _PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _PyAST_keyword(a->v.Name.id, b ? b : a, EXTRA)), 1) } | '**' a=expression { _PyPegen_keyword_or_starred(p, CHECK(keyword_ty, _PyAST_keyword(NULL, a, EXTRA)), 1) } # ASSIGNMENT TARGETS diff --git a/Parser/parser.c b/Parser/parser.c index 6f42f27..140818c 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -19098,7 +19098,7 @@ starred_expression_rule(Parser *p) return _res; } -// kwarg_or_starred: invalid_kwarg | NAME '=' expression | starred_expression +// kwarg_or_starred: invalid_kwarg | NAME '=' expression? | starred_expression static KeywordOrStarred* kwarg_or_starred_rule(Parser *p) { @@ -19140,24 +19140,24 @@ kwarg_or_starred_rule(Parser *p) D(fprintf(stderr, "%*c%s kwarg_or_starred[%d-%d]: %s failed!\n", p->level, ' ', p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_kwarg")); } - { // NAME '=' expression + { // NAME '=' expression? if (p->error_indicator) { p->level--; return NULL; } - D(fprintf(stderr, "%*c> kwarg_or_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); + D(fprintf(stderr, "%*c> kwarg_or_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME '=' expression?")); Token * _literal; expr_ty a; - expr_ty b; + void *b; if ( (a = _PyPegen_name_token(p)) // NAME && (_literal = _PyPegen_expect_token(p, 22)) // token='=' && - (b = expression_rule(p)) // expression + (b = expression_rule(p), !p->error_indicator) // expression? ) { - D(fprintf(stderr, "%*c+ kwarg_or_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); + D(fprintf(stderr, "%*c+ kwarg_or_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME '=' expression?")); Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); if (_token == NULL) { p->level--; @@ -19167,7 +19167,7 @@ kwarg_or_starred_rule(Parser *p) UNUSED(_end_lineno); // Only used by EXTRA macro int _end_col_offset = _token->end_col_offset; UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _PyPegen_keyword_or_starred ( p , CHECK ( keyword_ty , _PyAST_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); + _res = _PyPegen_keyword_or_starred ( p , CHECK ( keyword_ty , _PyAST_keyword ( a -> v . Name . id , b ? b : a , EXTRA ) ) , 1 ); if (_res == NULL && PyErr_Occurred()) { p->error_indicator = 1; p->level--; @@ -19177,7 +19177,7 @@ kwarg_or_starred_rule(Parser *p) } p->mark = _mark; D(fprintf(stderr, "%*c%s kwarg_or_starred[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME '=' expression")); + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME '=' expression?")); } { // starred_expression if (p->error_indicator) { @@ -19209,7 +19209,7 @@ kwarg_or_starred_rule(Parser *p) return _res; } -// kwarg_or_double_starred: invalid_kwarg | NAME '=' expression | '**' expression +// kwarg_or_double_starred: invalid_kwarg | NAME '=' expression? | '**' expression static KeywordOrStarred* kwarg_or_double_starred_rule(Parser *p) { @@ -19251,24 +19251,24 @@ kwarg_or_double_starred_rule(Parser *p) D(fprintf(stderr, "%*c%s kwarg_or_double_starred[%d-%d]: %s failed!\n", p->level, ' ', p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_kwarg")); } - { // NAME '=' expression + { // NAME '=' expression? if (p->error_indicator) { p->level--; return NULL; } - D(fprintf(stderr, "%*c> kwarg_or_double_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); + D(fprintf(stderr, "%*c> kwarg_or_double_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME '=' expression?")); Token * _literal; expr_ty a; - expr_ty b; + void *b; if ( (a = _PyPegen_name_token(p)) // NAME && (_literal = _PyPegen_expect_token(p, 22)) // token='=' && - (b = expression_rule(p)) // expression + (b = expression_rule(p), !p->error_indicator) // expression? ) { - D(fprintf(stderr, "%*c+ kwarg_or_double_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); + D(fprintf(stderr, "%*c+ kwarg_or_double_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME '=' expression?")); Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); if (_token == NULL) { p->level--; @@ -19278,7 +19278,7 @@ kwarg_or_double_starred_rule(Parser *p) UNUSED(_end_lineno); // Only used by EXTRA macro int _end_col_offset = _token->end_col_offset; UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _PyPegen_keyword_or_starred ( p , CHECK ( keyword_ty , _PyAST_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); + _res = _PyPegen_keyword_or_starred ( p , CHECK ( keyword_ty , _PyAST_keyword ( a -> v . Name . id , b ? b : a , EXTRA ) ) , 1 ); if (_res == NULL && PyErr_Occurred()) { p->error_indicator = 1; p->level--; @@ -19288,7 +19288,7 @@ kwarg_or_double_starred_rule(Parser *p) } p->mark = _mark; D(fprintf(stderr, "%*c%s kwarg_or_double_starred[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME '=' expression")); + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME '=' expression?")); } { // '**' expression if (p->error_indicator) {