delete_subscr -> delete_subscript ...

to better (but not exactly) match the Python AST
This commit is contained in:
rocky
2019-05-04 19:43:00 -04:00
parent 5905cce1de
commit bc49469704
4 changed files with 13 additions and 13 deletions

View File

@@ -98,9 +98,9 @@ class Python2Parser(PythonParser):
for ::= SETUP_LOOP expr for_iter store
for_block POP_BLOCK _come_froms
del_stmt ::= delete_subscr
delete_subscr ::= expr expr DELETE_SUBSCR
del_stmt ::= expr DELETE_ATTR
del_stmt ::= delete_subscript
delete_subscript ::= expr expr DELETE_SUBSCR
del_stmt ::= expr DELETE_ATTR
_mklambda ::= load_closure mklambda
kwarg ::= LOAD_CONST expr
@@ -390,10 +390,10 @@ class Python2Parser(PythonParser):
continue
elif opname == 'DELETE_SUBSCR':
self.addRule("""
del_stmt ::= delete_subscr
delete_subscr ::= expr expr DELETE_SUBSCR
del_stmt ::= delete_subscript
delete_subscript ::= expr expr DELETE_SUBSCR
""", nop_func)
self.check_reduce['delete_subscr'] = 'AST'
self.check_reduce['delete_subscript'] = 'AST'
custom_seen_ops.add(opname)
continue
elif opname == 'GET_ITER':
@@ -549,7 +549,7 @@ class Python2Parser(PythonParser):
elif rule == ('or', ('expr', 'jmp_true', 'expr', '\\e_come_from_opt')):
expr2 = ast[2]
return expr2 == 'expr' and expr2[0] == 'LOAD_ASSERT'
elif lhs in ('delete_subscr', 'del_expr'):
elif lhs in ('delete_subscript', 'del_expr'):
op = ast[0][0]
return op.kind in ('and', 'or')

View File

@@ -783,8 +783,8 @@ class Python3Parser(PythonParser):
custom_ops_processed.add(opname)
elif opname == 'DELETE_SUBSCR':
self.addRule("""
del_stmt ::= delete_subscr
delete_subscr ::= expr expr DELETE_SUBSCR
del_stmt ::= delete_subscript
delete_subscript ::= expr expr DELETE_SUBSCR
""", nop_func)
custom_ops_processed.add(opname)
elif opname == 'GET_ITER':

View File

@@ -49,7 +49,7 @@ PRECEDENCE = {
'subscript': 2,
'subscript2': 2,
'store_subscript': 2,
'delete_subscr': 2,
'delete_subscript': 2,
'slice0': 2,
'slice1': 2,
'slice2': 2,
@@ -221,7 +221,7 @@ TABLE_DIRECT = {
'DELETE_FAST': ( '%|del %{pattr}\n', ),
'DELETE_NAME': ( '%|del %{pattr}\n', ),
'DELETE_GLOBAL': ( '%|del %{pattr}\n', ),
'delete_subscr': ( '%|del %p[%c]\n',
'delete_subscript': ( '%|del %p[%c]\n',
(0, 'expr', PRECEDENCE['subscript']), (1, 'expr') ),
'subscript': ( '%p[%c]',
(0, 'expr', PRECEDENCE['subscript']),

View File

@@ -611,13 +611,13 @@ class SourceWalker(GenericASTTraversal, object):
# LOAD_CONST is a terminal, so stop processing/recursing early
self.prune()
def n_delete_subscr(self, node):
def n_delete_subscript(self, node):
if node[-2][0] == 'build_list' and node[-2][0][-1].kind.startswith('BUILD_TUPLE'):
if node[-2][0][-1] != 'BUILD_TUPLE_0':
node[-2][0].kind = 'build_tuple2'
self.default(node)
n_store_subscript = n_subscript = n_delete_subscr
n_store_subscript = n_subscript = n_delete_subscript
# Note: this node is only in Python 2.x
# FIXME: figure out how to get this into customization