From 946d46a574eddaef1da8b557367603a6f1dc499a Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 8 Feb 2020 05:21:42 -0500 Subject: [PATCH] Fix Python 3.6 "if" parse failures in loops... This fixes all the pyenv parse errors that were introduced in the last refactor. --- uncompyle6/parsers/parse36.py | 11 ++++++++++- uncompyle6/semantics/customize36.py | 25 +++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index 38f40afb..728cae6a 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -113,9 +113,16 @@ class Python36Parser(Python35Parser): except_suite ::= c_stmts_opt COME_FROM POP_EXCEPT jump_except COME_FROM jb_cfs ::= JUMP_BACK come_froms + + # If statement inside a loop? FIXME: NO not always - fix this up. + stmt ::= ifstmtl + ifstmtl ::= testexpr _ifstmts_jumpl + _ifstmts_jumpl ::= c_stmts JUMP_BACK + ifelsestmtl ::= testexpr c_stmts_opt jb_cfs else_suitel ifelsestmtl ::= testexpr c_stmts_opt cf_jf_else else_suitel - ifelsestmt ::= testexpr c_stmts_opt cf_jf_else else_suite _come_froms + ifelsestmt ::= testexpr c_stmts_opt cf_jf_else else_suite _come_froms + ifelsestmt ::= testexpr c_stmts come_froms else_suite come_froms # In 3.6+, A sequence of statements ending in a RETURN can cause # JUMP_FORWARD END_FINALLY to be omitted from try middle @@ -169,6 +176,8 @@ class Python36Parser(Python35Parser): # """) super(Python36Parser, self).customize_grammar_rules(tokens, customize) self.remove_rules(""" + _ifstmts_jumpl ::= c_stmts_opt + _ifstmts_jumpl ::= _ifstmts_jump except_handler ::= JUMP_FORWARD COME_FROM_EXCEPT except_stmts END_FINALLY COME_FROM async_for_stmt ::= SETUP_LOOP expr GET_AITER diff --git a/uncompyle6/semantics/customize36.py b/uncompyle6/semantics/customize36.py index 518671e3..944b28e3 100644 --- a/uncompyle6/semantics/customize36.py +++ b/uncompyle6/semantics/customize36.py @@ -49,12 +49,12 @@ def customize_for_version36(self, version): TABLE_DIRECT.update( { - "tryfinally36": ("%|try:\n%+%c%-%|finally:\n%+%c%-\n\n", (1, "returns"), 3), - "func_args36": ("%c(**", 0), - "try_except36": ("%|try:\n%+%c%-%c\n\n", 1, -2), - "except_return": ("%|except:\n%+%c%-", 3), - "unpack_list": ("*%c", (0, "list")), - "tryfinally_return_stmt": ("%|try:\n%+%c%-%|finally:\n%+%|return%-\n\n", 1), + "ann_assign_init_value": ( + "%|%c = %p\n", + (-1, "store_annotation"), + (0, "expr", 200), + ), + "ann_assign_no_init": ("%|%c\n", (0, "store_annotation")), "async_for_stmt36": ( "%|async for %c in %c:\n%+%c%-\n\n", (9, "store"), @@ -62,16 +62,17 @@ def customize_for_version36(self, version): (18, "for_block"), ), "call_ex": ("%c(%p)", (0, "expr"), (1, 100)), + "except_return": ("%|except:\n%+%c%-", 3), + "func_args36": ("%c(**", 0), # This comes from 3.7. Eventually we will rebase from 3.7 # and then this can go away "if_exp37": ("%p if %c else %c", (1, "expr", 27), 0, 3), + "ifstmtl": ("%|if %c:\n%+%c%-", (0, "testexpr"), (1, "_ifstmts_jumpl")), + "try_except36": ("%|try:\n%+%c%-%c\n\n", 1, -2), + "tryfinally36": ("%|try:\n%+%c%-%|finally:\n%+%c%-\n\n", (1, "returns"), 3), + "tryfinally_return_stmt": ("%|try:\n%+%c%-%|finally:\n%+%|return%-\n\n", 1), + "unpack_list": ("*%c", (0, "list")), "store_annotation": ("%[1]{pattr}: %c", 0), - "ann_assign_init_value": ( - "%|%c = %p\n", - (-1, "store_annotation"), - (0, "expr", 200), - ), - "ann_assign_no_init": ("%|%c\n", (0, "store_annotation")), } )