From bd4f2d086c94ae888808678e5a5d5979b545e0d8 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 27 Nov 2017 12:39:33 -0500 Subject: [PATCH] Python 2.5- grammar reduction --- __pkginfo__.py | 2 +- uncompyle6/parsers/parse25.py | 17 +++++++++++++++-- uncompyle6/parsers/parse26.py | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/__pkginfo__.py b/__pkginfo__.py index 01324a7d..ab9268cd 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -39,7 +39,7 @@ entry_points = { 'pydisassemble=uncompyle6.bin.pydisassemble:main', ]} ftp_url = None -install_requires = ['spark-parser >= 1.8.1, < 1.9.0', +install_requires = ['spark-parser >= 1.8.2, < 1.9.0', 'xdis >= 3.6.1, < 3.7.0', 'six'] license = 'MIT' mailing_list = 'python-debugger@googlegroups.com' diff --git a/uncompyle6/parsers/parse25.py b/uncompyle6/parsers/parse25.py index adecc40c..8fc9be6a 100644 --- a/uncompyle6/parsers/parse25.py +++ b/uncompyle6/parsers/parse25.py @@ -50,14 +50,27 @@ class Python25Parser(Python26Parser): """ def add_custom_rules(self, tokens, customize): - # grammar rules inherited from Python 2.6 + # Remove grammar rules inherited from Python 2.6 or Python 2 self.remove_rules(""" setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP withstmt ::= expr setupwith SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY withasstmt ::= expr setupwithas designator suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY - assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1 + assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1 + stmt ::= classdefdeco + classdefdeco ::= classdefdeco1 designator + classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1 + classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1 + classdefdeco2 ::= LOAD_CONST expr mkfunc CALL_FUNCTION_0 BUILD_CLASS + mkfuncdeco ::= expr mkfuncdeco CALL_FUNCTION_1 + ret_cond ::= expr jmp_false_then expr RETURN_END_IF POP_TOP ret_expr_or_cond + return_if_stmt ::= ret_expr RETURN_END_IF POP_TOP + return_if_stmts ::= return_if_stmt + return_stmt ::= ret_expr RETURN_END_IF POP_TOP + return_stmt ::= ret_expr RETURN_VALUE POP_TOP + stmt ::= conditional_lambda + setupwithas ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 setup_finally """) super(Python25Parser, self).add_custom_rules(tokens, customize) if self.version == 2.5: diff --git a/uncompyle6/parsers/parse26.py b/uncompyle6/parsers/parse26.py index 6eb7f2b6..e11d1e02 100644 --- a/uncompyle6/parsers/parse26.py +++ b/uncompyle6/parsers/parse26.py @@ -265,7 +265,7 @@ class Python26Parser(Python2Parser): invalid = super(Python26Parser, self).reduce_is_invalid(rule, ast, tokens, first, last) - if invalid: + if invalid or tokens is None: return invalid if rule == ('and', ('expr', 'jmp_false', 'expr', '\\e_come_from_opt')):