diff --git a/Grammar/python.gram b/Grammar/python.gram index 4915cc43e84..80fa90b9192 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -129,6 +129,8 @@ yield_stmt[stmt_ty]: y=yield_expr { _Py_Expr(y, EXTRA) } assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _Py_Assert(a, b, EXTRA) } del_stmt[stmt_ty]: + | 'del' a=star_element { + RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) } | 'del' a=del_targets &(';' | NEWLINE) { _Py_Delete(a, EXTRA) } | invalid_del_stmt diff --git a/Parser/parser.c b/Parser/parser.c index 2559969f86e..b3bfb60d180 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -2829,7 +2829,7 @@ assert_stmt_rule(Parser *p) return _res; } -// del_stmt: 'del' del_targets &(';' | NEWLINE) | invalid_del_stmt +// del_stmt: 'del' star_element | 'del' del_targets &(';' | NEWLINE) | invalid_del_stmt static stmt_ty del_stmt_rule(Parser *p) { @@ -2849,6 +2849,33 @@ del_stmt_rule(Parser *p) UNUSED(_start_lineno); // Only used by EXTRA macro int _start_col_offset = p->tokens[_mark]->col_offset; UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'del' star_element + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'del' star_element")); + Token * _keyword; + expr_ty a; + if ( + (_keyword = _PyPegen_expect_token(p, 503)) // token='del' + && + (a = star_element_rule(p)) // star_element + ) + { + D(fprintf(stderr, "%*c+ del_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'del' star_element")); + _res = RAISE_SYNTAX_ERROR_INVALID_TARGET ( DEL_TARGETS , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'del' star_element")); + } { // 'del' del_targets &(';' | NEWLINE) if (p->error_indicator) { D(p->level--);