From f6f2d8dd0587d1d61492c404c20765cc26681bb3 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 25 Jan 2020 09:14:55 -0500 Subject: [PATCH] Start to disambiguate stmts in a loop --- uncompyle6/parser.py | 3 +++ uncompyle6/parsers/parse3.py | 12 +++++++----- uncompyle6/parsers/parse32.py | 6 ++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index f45a3f49..162d375d 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -302,6 +302,9 @@ class PythonParser(GenericASTBuilder): c_stmts_opt ::= c_stmts c_stmts_opt ::= pass + stmts_opt ::= _stmts + stmts_opt ::= pass + # statements inside a loop l_stmts ::= _stmts l_stmts ::= returns diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 64773f1d..28a4573b 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -156,8 +156,9 @@ class Python3Parser(PythonParser): testfalse ::= expr jmp_false testtrue ::= expr jmp_true - _ifstmts_jump ::= return_if_stmts - _ifstmts_jump ::= c_stmts_opt come_froms + _ifstmts_jump ::= return_if_stmts + _ifstmts_jump ::= stmts_opt come_froms + _ifstmts_jumpl ::= c_stmts_opt come_froms iflaststmt ::= testexpr c_stmts_opt JUMP_ABSOLUTE @@ -174,9 +175,9 @@ class Python3Parser(PythonParser): # of missing "else" clauses. Therefore we include grammar # rules with and without ELSE. - ifelsestmt ::= testexpr c_stmts_opt JUMP_FORWARD + ifelsestmt ::= testexpr stmts_opt JUMP_FORWARD else_suite opt_come_from_except - ifelsestmt ::= testexpr c_stmts_opt jump_forward_else + ifelsestmt ::= testexpr stmts_opt jump_forward_else else_suite _come_froms # ifelsestmt ::= testexpr c_stmts_opt jump_forward_else @@ -1536,7 +1537,8 @@ class Python3Parser(PythonParser): # elif lhs == "iflaststmtl": # return iflaststmt(self, lhs, n, rule, ast, tokens, first, last) elif rule == ("ifstmt", ("testexpr", "_ifstmts_jump")): - if self.version <= 3.0: + # 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": return False if ifstmt(self, lhs, n, rule, ast, tokens, first, last): return True diff --git a/uncompyle6/parsers/parse32.py b/uncompyle6/parsers/parse32.py index 0f3bbc16..4d3da67e 100644 --- a/uncompyle6/parsers/parse32.py +++ b/uncompyle6/parsers/parse32.py @@ -46,8 +46,10 @@ class Python32Parser(Python3Parser): # Python 3.2+ has more loop optimization that removes # JUMP_FORWARD in some cases, and hence we also don't # see COME_FROM - _ifstmts_jump ::= c_stmts_opt - _ifstmts_jump ::= c_stmts_opt JUMP_FORWARD _come_froms + _ifstmts_jump ::= stmts_opt + _ifstmts_jump ::= stmts_opt JUMP_FORWARD _come_froms + _ifstmts_jumpl ::= c_stmts_opt + _ifstmts_jumpl ::= c_stmts_opt JUMP_FORWARD _come_froms kv3 ::= expr expr STORE_MAP """