You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Correct some Python 2.6 chain compare bugs
This commit is contained in:
@@ -6,7 +6,7 @@ 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, tryelsestmt)
|
from uncompyle6.parsers.reducecheck import (except_handler, tryexcept, tryelsestmt)
|
||||||
|
|
||||||
class Python26Parser(Python2Parser):
|
class Python26Parser(Python2Parser):
|
||||||
|
|
||||||
@@ -318,6 +318,8 @@ class Python26Parser(Python2Parser):
|
|||||||
return_lambda ::= RETURN_VALUE_LAMBDA
|
return_lambda ::= RETURN_VALUE_LAMBDA
|
||||||
|
|
||||||
compare_chained2 ::= expr COMPARE_OP return_expr_lambda
|
compare_chained2 ::= expr COMPARE_OP return_expr_lambda
|
||||||
|
compare_chained2 ::= expr COMPARE_OP RETURN_END_IF_LAMBDA
|
||||||
|
compare_chained2 ::= expr COMPARE_OP RETURN_END_IF COME_FROM
|
||||||
|
|
||||||
return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP
|
return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP
|
||||||
stmt ::= if_exp_lambda
|
stmt ::= if_exp_lambda
|
||||||
@@ -354,6 +356,7 @@ class Python26Parser(Python2Parser):
|
|||||||
self.reduce_check_table = {
|
self.reduce_check_table = {
|
||||||
"except_handler": except_handler,
|
"except_handler": except_handler,
|
||||||
"tryelsestmt": tryelsestmt,
|
"tryelsestmt": tryelsestmt,
|
||||||
|
"try_except": tryexcept,
|
||||||
"tryelsestmtl": tryelsestmt,
|
"tryelsestmtl": tryelsestmt,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +369,7 @@ class Python26Parser(Python2Parser):
|
|||||||
self.check_reduce["forelselaststmtl"] = "tokens"
|
self.check_reduce["forelselaststmtl"] = "tokens"
|
||||||
self.check_reduce["forelsestmt"] = "tokens"
|
self.check_reduce["forelsestmt"] = "tokens"
|
||||||
self.check_reduce['list_for'] = 'AST'
|
self.check_reduce['list_for'] = 'AST'
|
||||||
self.check_reduce['try_except'] = 'tokens'
|
self.check_reduce['try_except'] = 'AST'
|
||||||
self.check_reduce['tryelsestmt'] = 'AST'
|
self.check_reduce['tryelsestmt'] = 'AST'
|
||||||
self.check_reduce['tryelsestmtl'] = 'AST'
|
self.check_reduce['tryelsestmtl'] = 'AST'
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2020 Rocky Bernstein
|
# Copyright (c) 2020, 2022 Rocky Bernstein
|
||||||
|
|
||||||
def tryexcept(self, lhs, n, rule, ast, tokens, first, last):
|
def tryexcept(self, lhs, n, rule, ast, tokens, first, last):
|
||||||
come_from_except = ast[-1]
|
come_from_except = ast[-1]
|
||||||
@@ -13,12 +13,24 @@ def tryexcept(self, lhs, n, rule, ast, tokens, first, last):
|
|||||||
),
|
),
|
||||||
):
|
):
|
||||||
if come_from_except[0] == "COME_FROM":
|
if come_from_except[0] == "COME_FROM":
|
||||||
# There should be at last two COME_FROMs, one from an
|
# There should be at least two COME_FROMs, one from an
|
||||||
# exception handler and one from the try. Otherwise
|
# exception handler and one from the try. Otherwise
|
||||||
# we have a try/else.
|
# we have a try/else.
|
||||||
return True
|
return True
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
elif rule == (
|
||||||
|
"try_except",
|
||||||
|
(
|
||||||
|
"SETUP_EXCEPT",
|
||||||
|
"suite_stmts_opt",
|
||||||
|
"POP_BLOCK",
|
||||||
|
"except_handler",
|
||||||
|
"COME_FROM",
|
||||||
|
),
|
||||||
|
):
|
||||||
|
return come_from_except.attr < tokens[first].offset
|
||||||
|
|
||||||
elif rule == (
|
elif rule == (
|
||||||
'try_except',
|
'try_except',
|
||||||
(
|
(
|
||||||
|
Reference in New Issue
Block a user