2.7 tryelse rule check disambiguation.

This commit is contained in:
rocky
2020-02-01 04:05:50 -05:00
parent 2d1ea6b02b
commit 451b18ee57
2 changed files with 9 additions and 2 deletions

View File

@@ -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

View File

@@ -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]