Skip to content
Prev Previous commit
Next Next commit
pegen: fix more del test cases
  • Loading branch information
hauntsaninja committed May 11, 2020
commit d101ac1a5091cff66b6c8850e9233be06e8410ca
11 changes: 6 additions & 5 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -583,18 +583,19 @@ ann_assign_subscript_attribute_target[expr_ty]:
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }

del_targets[asdl_seq*]: a=','.del_target+ [','] { a }
# The lookaheads to del_target_end ensure that we don't match expressions where a prefix of the
# expression matches our rule, thereby letting these cases fall through to invalid_del_target.
del_target[expr_ty] (memo):
| a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) }
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Del, EXTRA) }
| a=t_primary '.' b=NAME &del_target_end { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) }
| a=t_primary '[' b=slices ']' &del_target_end { _Py_Subscript(a, b, Del, EXTRA) }
| del_t_atom
del_t_atom[expr_ty]:
# The lookahead here ensures that we don't match expressions where a prefix of the expression is
# a name (like `del a + b`), thereby letting these cases fall through to invalid_del_target.
| a=NAME &(')' | ']' | ',' | ';' | NEWLINE) { _PyPegen_set_expr_context(p, a, Del) }
| a=NAME &del_target_end { _PyPegen_set_expr_context(p, a, Del) }
| '(' a=del_target ')' { _PyPegen_set_expr_context(p, a, Del) }
| '(' a=[del_targets] ')' { _Py_Tuple(a, Del, EXTRA) }
| '[' a=[del_targets] ']' { _Py_List(a, Del, EXTRA) }
| invalid_del_target
del_target_end: ')' | ']' | ',' | ';' | NEWLINE
Comment thread
hauntsaninja marked this conversation as resolved.
Outdated

targets[asdl_seq*]: a=','.target+ [','] { a }
target[expr_ty] (memo):
Expand Down