From dfdd5c6c1ce4c0db1b08acc17e4e79702f2512bd Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 1 Dec 2017 03:55:31 -0500 Subject: [PATCH] NT build_list -> list to match AST --- pytest/test_grammar.py | 2 +- uncompyle6/parser.py | 2 +- uncompyle6/parsers/parse2.py | 6 +++--- uncompyle6/parsers/parse3.py | 20 ++++++++++---------- uncompyle6/semantics/consts.py | 2 +- uncompyle6/semantics/fragments.py | 8 ++++---- uncompyle6/semantics/pysource.py | 10 +++++----- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/pytest/test_grammar.py b/pytest/test_grammar.py index 2f075941..850f9b13 100644 --- a/pytest/test_grammar.py +++ b/pytest/test_grammar.py @@ -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',]) diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 196625e5..b64665b0 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -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 diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index ce1a4adf..b3f94e5b 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -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': diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index bf833732..e7458068 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -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,9 +722,9 @@ 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) + - 'expr32 ' * int((v//32) % 32) + - 'expr ' * (v % 32) + opname) + rule = ('list ::= ' + 'expr1024 ' * int(v//1024) + + 'expr32 ' * int((v//32) % 32) + + 'expr ' * (v % 32) + opname) self.add_unique_rule(rule, opname, token.attr, customize) continue elif opname_base == 'BUILD_SLICE': diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index c55355ed..c53c2166 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -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, diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index 362909c0..47a1ad42 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -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) diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 412f0173..e40fd9e1 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -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