From cdc5642715294c273dcf9de492b9f99783a98388 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 1 Feb 2020 07:10:30 -0500 Subject: [PATCH] More reduction checks... Those in reduce check as well as those listed in parse{2,3}. 3.6 iflastsmtl needs ifstmt checking. --- uncompyle6/parsers/parse2.py | 4 ++-- uncompyle6/parsers/parse3.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index c63399ae..9fd5049e 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -671,8 +671,8 @@ class Python2Parser(PythonParser): fn = self.reduce_check_table.get(lhs, None) if fn: - return fn(self, lhs, n, rule, ast, tokens, first, last) - + if fn(self, lhs, n, rule, ast, tokens, first, last): + return True if rule == ("and", ("expr", "jmp_false", "expr", "\\e_come_from_opt")): # If the instruction after the instructions forming the "and" is an "YIELD_VALUE" # then this is probably an "if" inside a comprehension. diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 8a285f99..92739e65 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -1573,15 +1573,19 @@ class Python3Parser(PythonParser): last = min(last, n-1) fn = self.reduce_check_table.get(lhs, None) if fn: - return fn(self, lhs, n, rule, ast, tokens, first, last) + if fn(self, lhs, n, rule, ast, tokens, first, last): + return True + pass # FIXME: put more in reduce_check_table - elif lhs in ("aug_assign1", "aug_assign2") and ast[0][0] == "and": + if lhs in ("aug_assign1", "aug_assign2") and ast[0][0] == "and": return True elif lhs == "annotate_tuple": return not isinstance(tokens[first].attr, tuple) elif lhs == "kwarg": arg = tokens[first].attr return not (isinstance(arg, str) or isinstance(arg, unicode)) + elif lhs in ("iflaststmt", "iflaststmtl") and self.version == 3.6: + return ifstmt(self, lhs, n, rule, ast, tokens, first, last) elif rule == ("ifstmt", ("testexpr", "_ifstmts_jump")): # FIXME: go over what's up with 3.0. Evetually I'd like to remove RETURN_END_IF if self.version <= 3.0 or tokens[last] == "RETURN_END_IF":