From 451b18ee573a1ecfb2cc1373f7b4a1c69130f560 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 1 Feb 2020 04:05:50 -0500 Subject: [PATCH] 2.7 tryelse rule check disambiguation. --- uncompyle6/parsers/parse27.py | 9 +++++++-- uncompyle6/parsers/reducecheck/tryelsestmt.py | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index 5837e9cb..5313113d 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -6,7 +6,10 @@ from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG from xdis import next_offset from uncompyle6.parser import PythonParserSingle, nop_func from uncompyle6.parsers.parse2 import Python2Parser -from uncompyle6.parsers.reducecheck import ifelsestmt +from uncompyle6.parsers.reducecheck import ( + ifelsestmt, + tryelsestmt, +) class Python27Parser(Python2Parser): @@ -221,6 +224,8 @@ class Python27Parser(Python2Parser): # FIXME: Put more in this table self.reduce_check_table = { "ifelsestmt": ifelsestmt, + "tryelsestmt": tryelsestmt, + "tryelsestmtl": tryelsestmt, } self.check_reduce["and"] = "AST" @@ -250,7 +255,7 @@ class Python27Parser(Python2Parser): n = len(tokens) fn = self.reduce_check_table.get(lhs, None) if fn: - return fn(self, lhs, n, rule, ast, tokens, first, last) + invalid = fn(self, lhs, n, rule, ast, tokens, first, last) last = min(last, n-1) if invalid: return invalid diff --git a/uncompyle6/parsers/reducecheck/tryelsestmt.py b/uncompyle6/parsers/reducecheck/tryelsestmt.py index eebb7c8e..7af38f37 100644 --- a/uncompyle6/parsers/reducecheck/tryelsestmt.py +++ b/uncompyle6/parsers/reducecheck/tryelsestmt.py @@ -7,6 +7,8 @@ def tryelsestmt(self, lhs, n, rule, ast, tokens, first, last): # inside the except handler to the end. If that happens # then this is a "try" with no "else". except_handler = ast[3] + if except_handler == "except_handler_else": + except_handler = except_handler[0] if except_handler == "except_handler": come_from = except_handler[-1]