Fix bug in detecting 2.7 except-handler ranges

This commit is contained in:
rocky
2020-07-05 22:11:37 -04:00
parent 8de663ff52
commit 3dc6c31ae5
5 changed files with 23 additions and 1 deletions

View File

@@ -19,7 +19,6 @@ SKIP_TESTS=(
[test_modulefinder.py]=1 # FIX [test_modulefinder.py]=1 # FIX
[test_multiprocessing.py]=1 # On uncompyle2, takes 24 secs [test_multiprocessing.py]=1 # On uncompyle2, takes 24 secs
[test_poll.py]=1 # test takes too long to run: 11 seconds [test_poll.py]=1 # test takes too long to run: 11 seconds
[test_pwd.py]=1 # Takes too long
[test_regrtest.py]=1 # [test_regrtest.py]=1 #
[test_runpy.py]=1 # Long and fails on its own [test_runpy.py]=1 # Long and fails on its own
[test_select.py]=1 # Runs okay but takes 11 seconds [test_select.py]=1 # Runs okay but takes 11 seconds

View File

@@ -6,6 +6,9 @@ spark grammar differences over Python2 for Python 2.6.
from uncompyle6.parser import PythonParserSingle from uncompyle6.parser import PythonParserSingle
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
from uncompyle6.parsers.parse2 import Python2Parser from uncompyle6.parsers.parse2 import Python2Parser
from uncompyle6.parsers.reducecheck import (
except_handler,
)
class Python26Parser(Python2Parser): class Python26Parser(Python2Parser):
@@ -345,6 +348,11 @@ class Python26Parser(Python2Parser):
WITH_CLEANUP END_FINALLY WITH_CLEANUP END_FINALLY
""") """)
super(Python26Parser, self).customize_grammar_rules(tokens, customize) super(Python26Parser, self).customize_grammar_rules(tokens, customize)
self.reduce_check_table = {
"except_handler": except_handler,
}
self.check_reduce['and'] = 'AST' self.check_reduce['and'] = 'AST'
self.check_reduce['assert_expr_and'] = 'AST' self.check_reduce['assert_expr_and'] = 'AST'
self.check_reduce["ifstmt"] = "tokens" self.check_reduce["ifstmt"] = "tokens"

View File

@@ -9,6 +9,7 @@ from uncompyle6.parsers.parse2 import Python2Parser
from uncompyle6.parsers.reducecheck import ( from uncompyle6.parsers.reducecheck import (
or_check, or_check,
tryelsestmt, tryelsestmt,
except_handler,
) )
class Python27Parser(Python2Parser): class Python27Parser(Python2Parser):
@@ -230,6 +231,7 @@ class Python27Parser(Python2Parser):
# FIXME: Put more in this table # FIXME: Put more in this table
self.reduce_check_table = { self.reduce_check_table = {
# "ifelsestmt": ifelsestmt, # "ifelsestmt": ifelsestmt,
"except_handler": except_handler,
"or": or_check, "or": or_check,
"tryelsestmt": tryelsestmt, "tryelsestmt": tryelsestmt,
"tryelsestmtl": tryelsestmt, "tryelsestmtl": tryelsestmt,

View File

@@ -1,4 +1,5 @@
from uncompyle6.parsers.reducecheck.and_check import * from uncompyle6.parsers.reducecheck.and_check import *
from uncompyle6.parsers.reducecheck.except_handler import *
from uncompyle6.parsers.reducecheck.except_handler_else import * from uncompyle6.parsers.reducecheck.except_handler_else import *
from uncompyle6.parsers.reducecheck.ifelsestmt import * from uncompyle6.parsers.reducecheck.ifelsestmt import *
from uncompyle6.parsers.reducecheck.iflaststmt import * from uncompyle6.parsers.reducecheck.iflaststmt import *

View File

@@ -0,0 +1,12 @@
# Copyright (c) 2020 Rocky Bernstein
def except_handler(self, lhs, n, rule, ast, tokens, first, last):
end_token = tokens[last-1]
# for t in range(first, last):
# print(tokens[t])
# print("=" * 30)
# Make sure come froms all come from within "except_handler".
if end_token != "COME_FROM":
return False
return end_token.attr < tokens[first].offset