NT build_list -> list to match AST

This commit is contained in:
rocky
2017-12-01 03:55:31 -05:00
parent 0744a549dd
commit dfdd5c6c1c
7 changed files with 25 additions and 25 deletions

View File

@@ -17,7 +17,7 @@ def test_grammar():
(lhs, rhs, tokens,
right_recursive, dup_rhs) = p.check_sets()
expect_lhs = set(['expr1024', 'pos_arg'])
unused_rhs = set(['build_list', 'call', 'mkfunc',
unused_rhs = set(['list', 'call', 'mkfunc',
'mklambda',
'unpack',])

View File

@@ -435,7 +435,7 @@ class PythonParser(GenericASTBuilder):
expr ::= LOAD_DEREF
expr ::= load_attr
expr ::= binary_expr
expr ::= build_list
expr ::= list
expr ::= compare
expr ::= dict
expr ::= and

View File

@@ -226,8 +226,8 @@ class Python2Parser(PythonParser):
Special handling for opcodes such as those that take a variable number
of arguments -- we add a new rule for each:
build_list ::= {expr}^n BUILD_LIST_n
build_list ::= {expr}^n BUILD_TUPLE_n
list ::= {expr}^n BUILD_LIST_n
list ::= {expr}^n BUILD_TUPLE_n
unpack_list ::= UNPACK_LIST {expr}^n
unpack ::= UNPACK_TUPLE {expr}^n
unpack ::= UNPACK_SEQEUENCE {expr}^n
@@ -277,7 +277,7 @@ class Python2Parser(PythonParser):
self.add_unique_rule("expr1024 ::=%s" % (' expr32' * 32),
opname_base, v, customize)
self.seen1024 = True
rule = ('build_list ::= ' + 'expr1024 '*thousands +
rule = ('list ::= ' + 'expr1024 '*thousands +
'expr32 '*thirty32s + 'expr '*(v % 32) + opname)
elif opname_base == 'BUILD_MAP':
if opname == 'BUILD_MAP_n':

View File

@@ -563,14 +563,14 @@ class Python3Parser(PythonParser):
# Even the below say _list, in the semantic rules we
# disambiguate tuples, and sets from lists
build_list ::= {expr}^n BUILD_LIST_n
build_list ::= {expr}^n BUILD_TUPLE_n
build_list ::= {expr}^n BUILD_LIST_UNPACK_n
build_list ::= {expr}^n BUILD_TUPLE_UNPACK_n
list ::= {expr}^n BUILD_LIST_n
list ::= {expr}^n BUILD_TUPLE_n
list ::= {expr}^n BUILD_LIST_UNPACK_n
list ::= {expr}^n BUILD_TUPLE_UNPACK_n
# FIXME:
build_list ::= {expr}^n BUILD_SET_n
build_list ::= {expr}^n BUILD_SET_UNPACK_n
list ::= {expr}^n BUILD_SET_n
list ::= {expr}^n BUILD_SET_UNPACK_n
should be
build_set ::= {expr}^n BUILD_SET_n
build_set ::= {expr}^n BUILD_SET_UNPACK_n
@@ -712,7 +712,7 @@ class Python3Parser(PythonParser):
is_LOAD_CLOSURE = False
if opname_base == 'BUILD_TUPLE':
# If is part of a "load_closure", then it is not part of a
# "build_list".
# "list".
is_LOAD_CLOSURE = True
for j in range(v):
if tokens[i-j-1].kind != 'LOAD_CLOSURE':
@@ -722,7 +722,7 @@ class Python3Parser(PythonParser):
rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname))
self.add_unique_rule(rule, opname, token.attr, customize)
if not is_LOAD_CLOSURE or v == 0:
rule = ('build_list ::= ' + 'expr1024 ' * int(v//1024) +
rule = ('list ::= ' + 'expr1024 ' * int(v//1024) +
'expr32 ' * int((v//32) % 32) +
'expr ' * (v % 32) + opname)
self.add_unique_rule(rule, opname, token.attr, customize)

View File

@@ -297,7 +297,7 @@ MAP = {
# or https://docs.python.org/3/reference/expressions.html
# for a list.
PRECEDENCE = {
'build_list': 0,
'list': 0,
'dict': 0,
'unary_convert': 0,
'dict_comp': 0,

View File

@@ -1397,7 +1397,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.prec = p
self.prune()
def n_build_list(self, node):
def n_list(self, node):
"""
prettyprint a list or tuple
"""
@@ -1415,7 +1415,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
elif lastnode.startswith('ROT_TWO'):
self.write('('); endchar = ')'
else:
raise RuntimeError('Internal Error: n_build_list expects list or tuple')
raise RuntimeError('Internal Error: n_list expects list or tuple')
flat_elems = []
for elem in node:
@@ -1828,7 +1828,7 @@ if __name__ == '__main__':
# deparse_test(get_code_for_fn(gcd))
# deparse_test(get_code_for_fn(test))
# deparse_test(get_code_for_fn(FragmentsWalker.fixup_offsets))
# deparse_test(get_code_for_fn(FragmentsWalker.n_build_list))
# deparse_test(get_code_for_fn(FragmentsWalker.n_list))
print('=' * 30)
deparse_test_around(408, 'n_build_list', get_code_for_fn(FragmentsWalker.n_build_list))
deparse_test_around(408, 'n_list', get_code_for_fn(FragmentsWalker.n_build_list))
# deparse_test(inspect.currentframe().f_code)

View File

@@ -446,7 +446,7 @@ class SourceWalker(GenericASTTraversal, object):
node.kind == 'async_call'
self.prune()
self.n_async_call = n_async_call
self.n_build_list_unpack = self.n_build_list
self.n_build_list_unpack = self.n_list
if version == 3.5:
def n_call(node):
@@ -1537,7 +1537,7 @@ class SourceWalker(GenericASTTraversal, object):
n_classdefdeco2 = n_classdef
def print_super_classes(self, node):
if not (node == 'build_list'):
if not (node == 'list'):
return
n_subclasses = len(node[:-1])
@@ -1737,7 +1737,7 @@ class SourceWalker(GenericASTTraversal, object):
self.prec = p
self.prune()
def n_build_list(self, node):
def n_list(self, node):
"""
prettyprint a list or tuple
"""
@@ -1828,7 +1828,7 @@ class SourceWalker(GenericASTTraversal, object):
self.prune()
return
n_build_set = n_build_list
n_build_set = n_list
def n_unpack(self, node):
if node[0].kind.startswith('UNPACK_EX'):
@@ -2057,7 +2057,7 @@ class SourceWalker(GenericASTTraversal, object):
pass
# handled by n_dict:
# if op == 'BUILD_SLICE': TABLE_R[k] = ('%C' , (0,-1,':'))
# handled by n_build_list:
# handled by n_list:
# if op == 'BUILD_LIST': TABLE_R[k] = ('[%C]' , (0,-1,', '))
# elif op == 'BUILD_TUPLE': TABLE_R[k] = ('(%C%,)', (0,-1,', '))
pass