From d8628e79fb6b60f13ef626993abcfa8af8ce2c6e Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 7 Jan 2020 20:51:44 -0500 Subject: [PATCH] 2.6 "if" vs "if/else" disambiguation via reduction rule. --- test/stdlib/runtests.sh | 3 --- uncompyle6/parsers/parse26.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/test/stdlib/runtests.sh b/test/stdlib/runtests.sh index 342ebe76..26badf00 100755 --- a/test/stdlib/runtests.sh +++ b/test/stdlib/runtests.sh @@ -71,13 +71,10 @@ case $PYVERSION in 2.6) SKIP_TESTS=( [test_aepack.py]=1 # Fails on its own - [test_compile.py]=1 # Intermittent - sometimes works and sometimes doesn't [test_dis.py]=1 # We change line numbers - duh! [test_generators.py]=1 # Investigate [test_grp.py]=1 # Long test - might work Control flow? [test_pep352.py]=1 # Investigate - [test_pprint.py]=1 - [test_pty.py]=1 [test_pyclbr.py]=1 # Investigate [test_pwd.py]=1 # Long test - might work? Control flow? [test_trace.py]=1 # Line numbers are expected to be different diff --git a/uncompyle6/parsers/parse26.py b/uncompyle6/parsers/parse26.py index f85d8f45..f061d8ea 100644 --- a/uncompyle6/parsers/parse26.py +++ b/uncompyle6/parsers/parse26.py @@ -343,6 +343,7 @@ class Python26Parser(Python2Parser): super(Python26Parser, self).customize_grammar_rules(tokens, customize) self.check_reduce['and'] = 'AST' self.check_reduce['assert_expr_and'] = 'AST' + self.check_reduce["ifstmt"] = "tokens" self.check_reduce['list_for'] = 'AST' self.check_reduce['try_except'] = 'tokens' self.check_reduce['tryelsestmt'] = 'AST' @@ -382,6 +383,16 @@ class Python26Parser(Python2Parser): return not (jmp_target == tokens[test_index].offset or tokens[last].pattr == jmp_false.pattr) + + elif rule == ("ifstmt", ("testexpr", "_ifstmts_jump")): + for i in range(last-1, last-4, -1): + t = tokens[i] + if t == "JUMP_FORWARD": + return t.attr > tokens[min(last, len(tokens)-1)].off2int() + elif t not in ("POP_TOP", "COME_FROM"): + break + pass + pass elif rule == ( 'list_for', ('expr', 'for_iter', 'store', 'list_iter',