diff --git a/test/bytecode_3.6_run/01_conditional.pyc b/test/bytecode_3.6_run/01_conditional.pyc new file mode 100644 index 00000000..c24dde9c Binary files /dev/null and b/test/bytecode_3.6_run/01_conditional.pyc differ diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index b2e2445f..fab3eff4 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -1490,7 +1490,7 @@ class Python3Parser(PythonParser): # print("XXX", first, last) # for t in range(first, last): print(tokens[t]) # from trepan.api import debug; debug() - # return condition_jump.attr < condition_jump2.off2int() + return condition_jump.attr < condition_jump2.off2int() return False elif lhs == "ifelsestmt" and rule[1][2] == "jump_forward_else": last = min(last, len(tokens)-1) diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index 5acbc8ec..c5e33791 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -153,6 +153,16 @@ class Python36Parser(Python35Parser): """ + # Some of this is duplicated from parse37. Eventually we'll probably rebase from + # that and then we can remove this. + def p_37conditionals(self, args): + """ + expr ::= conditional37 + conditional37 ::= expr expr jf_cfs expr COME_FROM + jf_cfs ::= JUMP_FORWARD _come_froms + ifelsestmt ::= testexpr c_stmts_opt jf_cfs else_suite opt_come_from_except + """ + def customize_grammar_rules(self, tokens, customize): # self.remove_rules(""" # """) diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index 5b5a567a..343901ec 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -401,7 +401,7 @@ class Python37Parser(Python37BaseParser): def p_32on(self, args): """ - conditional ::= expr jmp_false expr jump_forward_else expr COME_FROM + conditional::= expr jmp_false expr jump_forward_else expr COME_FROM # compare_chained2 is used in a "chained_compare": x <= y <= z # used exclusively in compare_chained @@ -620,6 +620,8 @@ class Python37Parser(Python37BaseParser): def p_37conditionals(self, args): """ + expr ::= conditional37 + conditional37 ::= expr expr jf_cfs expr COME_FROM jf_cfs ::= JUMP_FORWARD _come_froms ifelsestmt ::= testexpr c_stmts_opt jf_cfs else_suite opt_come_from_except diff --git a/uncompyle6/semantics/customize36.py b/uncompyle6/semantics/customize36.py index 729c00c5..ca49d6f4 100644 --- a/uncompyle6/semantics/customize36.py +++ b/uncompyle6/semantics/customize36.py @@ -60,6 +60,12 @@ def customize_for_version36(self, version): 'call_ex' : ( '%c(%p)', (0, 'expr'), (1, 100)), + + # This comes from 3.7. Eventually we will rebase from 3.7 + # and then this can go away + "conditional37": ( "%p if %c else %c", + (1, 'expr', 27), 0, 3 ), + 'store_annotation': ( '%[1]{pattr}: %c', 0 diff --git a/uncompyle6/semantics/customize37.py b/uncompyle6/semantics/customize37.py index d6aab1a1..200b733e 100644 --- a/uncompyle6/semantics/customize37.py +++ b/uncompyle6/semantics/customize37.py @@ -120,6 +120,9 @@ def customize_for_version37(self, version): (0, 19), (6, 19), ), + 'conditional37': ( '%p if %c else %c', + (1, 'expr', 27), 0, 3 ), + "except_return": ("%|except:\n%+%c%-", 3), "if_exp_37a": ( "%p if %p else %p",