diff --git a/test/Makefile b/test/Makefile index e401db30..e5f7ba9b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -8,6 +8,7 @@ NATIVE_CHECK = check-$(PYTHON_VERSION) # Set COMPILE='--compile' to force compilation before check COMPILE ?= +COVER_DIR=../tmp/grammar-cover # Run short tests check-short: @@ -118,8 +119,9 @@ grammar-coverage-2.7: #: Get grammar coverage for Python 3.4 grammar-coverage-3.4: - SPARK_PARSER_COVERAGE=/tmp/spark-grammar-34.cover $(PYTHON) test_pythonlib.py --bytecode-3.4 - SPARK_PARSER_COVERAGE=/tmp/spark-grammar-34.cover $(PYTHON) test_pyenvlib.py --3.4.2 + rm $(COVER_DIR)/spark-grammar-34.cover || /bin/true + SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-34.cover $(PYTHON) test_pythonlib.py --bytecode-3.4 + SPARK_PARSER_COVERAGE=$(COVER_DIR)/spark-grammar-34.cover $(PYTHON) test_pyenvlib.py --3.4.2 #: Check deparsing Python 2.6 check-bytecode-2.6: diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index f92e9908..f72611d7 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -507,7 +507,6 @@ class PythonParser(GenericASTBuilder): yield ::= expr YIELD_VALUE - _mklambda ::= load_closure mklambda _mklambda ::= mklambda expr ::= conditional diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index b19c1c44..3dfa8230 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -103,7 +103,8 @@ class Python2Parser(PythonParser): delete_subscr ::= expr expr DELETE_SUBSCR del_stmt ::= expr DELETE_ATTR - kwarg ::= LOAD_CONST expr + _mklambda ::= load_closure mklambda + kwarg ::= LOAD_CONST expr classdef ::= buildclass designator diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 030838bc..35ffb84e 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -489,7 +489,8 @@ class Python3Parser(PythonParser): self.add_unique_rule(rule, opname, token.attr, customize) return - def custom_classfunc_rule(self, opname, token, customize): + def custom_classfunc_rule(self, opname, token, customize, + seen_LOAD_BUILD_CLASS): """ call_function ::= expr {expr}^n CALL_FUNCTION_n call_function ::= expr {expr}^n CALL_FUNCTION_VAR_n @@ -548,9 +549,10 @@ class Python3Parser(PythonParser): self.add_unique_rule(rule, token.kind, uniq_param, customize) self.add_unique_rule('expr ::= async_call_function', token.kind, uniq_param, customize) - rule = ('classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc %s%s_%d' - % (('expr ' * (args_pos-1)), opname, args_pos)) - self.add_unique_rule(rule, token.kind, uniq_param, customize) + if seen_LOAD_BUILD_CLASS: + rule = ('classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc %s%s_%d' + % (('expr ' * (args_pos-1)), opname, args_pos)) + self.add_unique_rule(rule, token.kind, uniq_param, customize) def add_make_function_rule(self, rule, opname, attr, customize): """Python 3.3 added a an addtional LOAD_CONST before MAKE_FUNCTION and @@ -623,6 +625,7 @@ class Python3Parser(PythonParser): load_attr ::= expr LOOKUP_METHOD call_function ::= expr CALL_METHOD """ + seen_LOAD_BUILD_CLASS = False for i, token in enumerate(tokens): opname = token.kind opname_base = opname[:opname.rfind('_')] @@ -638,7 +641,7 @@ class Python3Parser(PythonParser): elif (opname in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR', 'CALL_FUNCTION_VAR_KW', 'CALL_FUNCTION_EX_KW') or opname.startswith('CALL_FUNCTION_KW')): - self.custom_classfunc_rule(opname, token, customize) + self.custom_classfunc_rule(opname, token, customize, seen_LOAD_BUILD_CLASS) elif opname == 'LOAD_DICTCOMP': rule_pat = ("dictcomp ::= LOAD_DICTCOMP %sMAKE_FUNCTION_0 expr " "GET_ITER CALL_FUNCTION_1") @@ -649,6 +652,7 @@ class Python3Parser(PythonParser): "GET_ITER CALL_FUNCTION_1") self.add_make_function_rule(rule_pat, opname, token.attr, customize) elif opname == 'LOAD_BUILD_CLASS': + seen_LOAD_BUILD_CLASS = True self.custom_build_class_rule(opname, i, token, tokens, customize) elif opname.startswith('BUILD_LIST_UNPACK'): v = token.attr diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index 5ca649fa..da149a59 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -98,8 +98,7 @@ class Python36Parser(Python35Parser): """ % (fstring_expr_or_str_n, fstring_expr_or_str_n, "fstring_expr_or_str " * v) self.add_unique_doc_rules(rules_str, customize) - def custom_classfunc_rule(self, opname, token, customize): - + def custom_classfunc_rule(self, opname, token, customize, seen_LOAD_BUILD_CLASS): if opname.startswith('CALL_FUNCTION_KW'): values = 'expr ' * token.attr rule = 'call_function ::= expr kwargs_only_36 {token.kind}'.format(**locals()) @@ -107,7 +106,8 @@ class Python36Parser(Python35Parser): rule = 'kwargs_only_36 ::= {values} LOAD_CONST'.format(**locals()) self.add_unique_rule(rule, token.kind, token.attr, customize) else: - super(Python36Parser, self).custom_classfunc_rule(opname, token, customize) + super(Python36Parser, self).custom_classfunc_rule(opname, token, + customize, seen_LOAD_BUILD_CLASS) class Python36ParserSingle(Python36Parser, PythonParserSingle):