From fcdea73b4f7fbe814c6829d69ba0cd79b7d61c70 Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 29 Nov 2017 21:26:31 -0500 Subject: [PATCH] list_compr -> list_comp to match AST... more Python 3 custom rule cleanup --- uncompyle6/parser.py | 2 +- uncompyle6/parsers/parse2.py | 4 ++-- uncompyle6/parsers/parse23.py | 2 +- uncompyle6/parsers/parse26.py | 4 ++-- uncompyle6/parsers/parse27.py | 6 +++--- uncompyle6/parsers/parse3.py | 8 -------- uncompyle6/parsers/parse32.py | 7 +++---- uncompyle6/semantics/consts.py | 3 +-- uncompyle6/semantics/fragments.py | 4 ++-- uncompyle6/semantics/pysource.py | 12 +++++------- 10 files changed, 20 insertions(+), 32 deletions(-) diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 1cea77a3..369ce13c 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -403,7 +403,7 @@ class PythonParser(GenericASTBuilder): def p_list_comprehension(self, args): """ - expr ::= list_compr + expr ::= list_comp list_iter ::= list_for list_iter ::= list_if diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index 7c93af55..ee59d34a 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -253,8 +253,8 @@ class Python2Parser(PythonParser): stmt ::= assign2_pypy assign3_pypy ::= expr expr expr store store store assign2_pypy ::= expr expr store store - list_compr ::= expr BUILD_LIST_FROM_ARG _for store list_iter - JUMP_BACK + list_comp ::= expr BUILD_LIST_FROM_ARG _for store list_iter + JUMP_BACK """, nop_func) for i, token in enumerate(tokens): opname = token.kind diff --git a/uncompyle6/parsers/parse23.py b/uncompyle6/parsers/parse23.py index 5d7a30ab..56178e92 100644 --- a/uncompyle6/parsers/parse23.py +++ b/uncompyle6/parsers/parse23.py @@ -35,7 +35,7 @@ class Python23Parser(Python24Parser): while1stmt ::= _while1test l_stmts_opt JUMP_BACK COME_FROM POP_TOP POP_BLOCK COME_FROM - list_compr ::= BUILD_LIST_0 DUP_TOP LOAD_ATTR store list_iter del_stmt + list_comp ::= BUILD_LIST_0 DUP_TOP LOAD_ATTR store list_iter del_stmt list_for ::= expr _for store list_iter JUMP_BACK come_froms POP_TOP JUMP_BACK lc_body ::= LOAD_NAME expr CALL_FUNCTION_1 POP_TOP diff --git a/uncompyle6/parsers/parse26.py b/uncompyle6/parsers/parse26.py index a259c184..fdb0bdf1 100644 --- a/uncompyle6/parsers/parse26.py +++ b/uncompyle6/parsers/parse26.py @@ -195,9 +195,9 @@ class Python26Parser(Python2Parser): list_iter ::= list_if JUMP_BACK list_iter ::= list_if JUMP_BACK COME_FROM POP_TOP - list_compr ::= BUILD_LIST_0 DUP_TOP + list_comp ::= BUILD_LIST_0 DUP_TOP store list_iter del_stmt - list_compr ::= BUILD_LIST_0 DUP_TOP + list_comp ::= BUILD_LIST_0 DUP_TOP store list_iter JUMP_BACK del_stmt lc_body ::= LOAD_NAME expr LIST_APPEND lc_body ::= LOAD_FAST expr LIST_APPEND diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index 15ba5566..8e054283 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -14,9 +14,9 @@ class Python27Parser(Python2Parser): def p_comprehension27(self, args): """ - list_for ::= expr _for store list_iter JUMP_BACK - list_compr ::= BUILD_LIST_0 list_iter - lc_body ::= expr LIST_APPEND + list_for ::= expr _for store list_iter JUMP_BACK + list_comp ::= BUILD_LIST_0 list_iter + lc_body ::= expr LIST_APPEND stmt ::= setcomp_func diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index e14e2fa5..12274618 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -622,9 +622,6 @@ class Python3Parser(PythonParser): """ is_pypy = False seen_LOAD_BUILD_CLASS = False - seen_LOAD_DICTCOMP = False - seen_LOAD_LISTCOMP = False - seen_LOAD_SETCOMP = False seen_GET_AWAITABLE_YIELD_FROM = False # Loop over instructions adding custom grammar rules based on @@ -799,16 +796,11 @@ class Python3Parser(PythonParser): opname, token.attr, customize) continue elif opname == 'LOAD_DICTCOMP': - seen_LOAD_DICTCOMP = True if has_get_iter_call_function1: rule_pat = ("dictcomp ::= LOAD_DICTCOMP %sMAKE_FUNCTION_0 expr " "GET_ITER CALL_FUNCTION_1") self.add_make_function_rule(rule_pat, opname, token.attr, customize) - elif opname == 'LOAD_LISTCOMP': - seen_LOAD_LISTCOMP = True - continue elif opname == 'LOAD_SETCOMP': - seen_LOAD_SETCOMP = True # Should this be generalized and put under MAKE_FUNCTION? if has_get_iter_call_function1: self.add_unique_rule("expr ::= setcomp", diff --git a/uncompyle6/parsers/parse32.py b/uncompyle6/parsers/parse32.py index 3811eecb..cf6d0620 100644 --- a/uncompyle6/parsers/parse32.py +++ b/uncompyle6/parsers/parse32.py @@ -51,10 +51,9 @@ class Python32Parser(Python3Parser): stmt ::= del_deref_stmt del_deref_stmt ::= DELETE_DEREF - list_compr ::= BUILD_LIST_0 list_iter - lc_body ::= expr LIST_APPEND - - kv3 ::= expr expr STORE_MAP + list_comp ::= BUILD_LIST_0 list_iter + lc_body ::= expr LIST_APPEND + kv3 ::= expr expr STORE_MAP """ pass diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index 339a0bf7..841a93d2 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -156,7 +156,6 @@ TABLE_DIRECT = { 'unpack_list': ( '[%C]', (1, maxint, ', ') ), 'build_tuple2': ( '%P', (0, -1, ', ', 100) ), - # 'list_compr': ( '[ %c ]', -2), # handled by n_list_compr 'list_iter': ( '%c', 0 ), 'list_for': ( ' for %c in %c%c', 2, 0, 3 ), 'list_if': ( ' if %c%c', 0, 2 ), @@ -304,7 +303,7 @@ PRECEDENCE = { 'unary_convert': 0, 'dictcomp': 0, 'setcomp': 0, - 'list_compr': 0, + 'list_comp': 0, 'generator_exp': 0, 'load_attr': 2, diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index eac67023..23c3f8d6 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -540,8 +540,8 @@ class FragmentsWalker(pysource.SourceWalker, object): self.indent_less() self.prune() # stop recursing - def n_list_compr(self, node): - """List comprehensions the way they are done in Python 2.""" + def n_list_comp(self, node): + """List comprehensions""" p = self.prec self.prec = 27 n = node[-1] diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 20cdbf10..c2cc1d54 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1060,14 +1060,13 @@ class SourceWalker(GenericASTTraversal, object): self.make_function(node, is_lambda=True, codeNode=node[-2]) self.prune() # stop recursing - def n_list_compr(self, node): - """List comprehensions the way they are done in Python 2. - """ + def n_list_comp(self, node): + """List comprehensions""" p = self.prec self.prec = 27 if self.version >= 2.7: if self.is_pypy: - self.n_list_compr_pypy27(node) + self.n_list_comp_pypy27(node) return n = node[-1] elif node[-1] == 'del_stmt': @@ -1112,9 +1111,8 @@ class SourceWalker(GenericASTTraversal, object): self.prec = p self.prune() # stop recursing - def n_list_compr_pypy27(self, node): - """List comprehensions the way they are done in PYPY Python 2.7. - """ + def n_list_comp_pypy27(self, node): + """List comprehensions in PYPY.""" p = self.prec self.prec = 27 if node[-1].kind == 'list_iter':