diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index 17158857..e4525bf8 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -308,9 +308,9 @@ class Python2Parser(PythonParser): ], customize) if self.version >= 2.7: self.add_unique_rule( - 'dictcomp_func ::= BUILD_MAP_n LOAD_FAST FOR_ITER store ' + 'dict_comp_func ::= BUILD_MAP_n LOAD_FAST FOR_ITER store ' 'comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST', - 'dictcomp_func', 0, customize) + 'dict_comp_func', 0, customize) else: kvlist_n = "kvlist_%s" % token.attr diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index a9b20372..308cd71f 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -26,9 +26,9 @@ class Python27Parser(Python2Parser): expr ::= dict_comp dict_comp ::= LOAD_DICTCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1 - stmt ::= dictcomp_func - dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store - comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST + stmt ::= dict_comp_func + dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store + comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST set_comp ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 255d989e..23b9d431 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -3,7 +3,18 @@ # Copyright (c) 2000-2002 by hartmut Goebel # Copyright (c) 1999 John Aycock # -# See LICENSE for license +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . """ A spark grammar for Python 3.x. @@ -66,14 +77,14 @@ class Python3Parser(PythonParser): # See also common Python p_list_comprehension """ - def p_dictcomp3(self, args): + def p_dict_comp3(self, args): """" expr ::= dict_comp - stmt ::= dictcomp_func - dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store - comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST - dict_comp ::= LOAD_DICTCOMP LOAD_CONST MAKE_FUNCTION_0 expr - GET_ITER CALL_FUNCTION_1 + stmt ::= dict_comp_func + dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store + comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST + dict_comp ::= LOAD_DICTCOMP LOAD_CONST MAKE_FUNCTION_0 expr + GET_ITER CALL_FUNCTION_1 comp_iter ::= comp_if comp_iter ::= comp_if_not @@ -621,9 +632,9 @@ class Python3Parser(PythonParser): kvlist_n = "kvlist_%s" % token.attr if opname == 'BUILD_MAP_n': # PyPy sometimes has no count. Sigh. - rule = ('dictcomp_func ::= BUILD_MAP_n LOAD_FAST FOR_ITER store ' + rule = ('dict_comp_func ::= BUILD_MAP_n LOAD_FAST FOR_ITER store ' 'comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST') - self.add_unique_rule(rule, 'dictomp_func', 1, customize) + self.add_unique_rule(rule, 'dict_comp_func', 1, customize) kvlist_n = 'kvlist_n' rule = 'kvlist_n ::= kvlist_n kv3' diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index 999d37f4..682899f5 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -323,6 +323,7 @@ PRECEDENCE = { 'unary_convert': 0, 'dict_comp': 0, 'set_comp': 0, + 'set_comp_expr': 0, 'list_comp': 0, 'generator_exp': 0, diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index ef1a0dc8..c7238fdf 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -849,7 +849,7 @@ class FragmentsWalker(pysource.SourceWalker, object): self.set_pos_info(node, start, len(self.f.getvalue())) self.prune() - def n_set_comp(self, node): + def n_set_comp_expr(self, node): start = len(self.f.getvalue()) self.write('{') if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']: diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 1944c344..e1d051cd 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1262,7 +1262,7 @@ class SourceWalker(GenericASTTraversal, object): self.write(')') self.prune() - def n_set_comp(self, node): + def n_set_comp_expr(self, node): self.write('{') if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']: self.comprehension_walk3(node, 1, 0) @@ -1272,6 +1272,7 @@ class SourceWalker(GenericASTTraversal, object): self.comprehension_walk(node, iter_index=4) self.write('}') self.prune() + n_dict_comp = n_set_comp_expr def comprehension_walk3(self, node, iter_index, code_index=-5): """Non-closure-based comprehensions the way they are done in Python3. @@ -1296,7 +1297,7 @@ class SourceWalker(GenericASTTraversal, object): ast = ast[0] store = None - if ast in ['set_comp', 'dictcomp_func']: + if ast in ['set_comp', 'dict_comp_func']: for k in ast: if k == 'comp_iter': n = k @@ -1470,8 +1471,6 @@ class SourceWalker(GenericASTTraversal, object): self.write(']') self.prune() - n_dict_comp = n_set_comp - def setcomprehension_walk3(self, node, collection_index): """Set comprehensions the way they are done in Python3. They're more other comprehensions, e.g. set comprehensions