You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Fix another 2.5- try/else (in loop) bug
This commit is contained in:
BIN
test/bytecode_2.4_run/02_try_else_loop.pyc
Normal file
BIN
test/bytecode_2.4_run/02_try_else_loop.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.4_run/03_try_else.pyc
Normal file
BIN
test/bytecode_2.4_run/03_try_else.pyc
Normal file
Binary file not shown.
@@ -12,7 +12,6 @@ typeset -A SKIP_TESTS
|
||||
case $PYVERSION in
|
||||
2.4)
|
||||
SKIP_TESTS=(
|
||||
[test_binop.py]=1 # need to fix tryelse
|
||||
[test_codecs.py]=1 # need to fix tryelse
|
||||
[test_decorators.py]=1 # Syntax error decorators?
|
||||
[test_dis.py]=1 # We change line numbers - duh!
|
||||
@@ -20,7 +19,6 @@ case $PYVERSION in
|
||||
[test_grp.py]=1 # Long test - might work Control flow?
|
||||
[test_imp.py]=1 # Control flow?
|
||||
[test_import.py]=1 # Control flow?
|
||||
[test_long_future.py]=1 # Control flow?
|
||||
[test_math.py]=1 # Control flow?
|
||||
[test_pwd.py]=1 # Long test - might work? Control flow?
|
||||
[test_queue.py]=1 # Control flow?
|
||||
@@ -31,7 +29,6 @@ case $PYVERSION in
|
||||
;;
|
||||
2.5)
|
||||
SKIP_TESTS=(
|
||||
[test_binop.py]=1 # need to fix tryelse
|
||||
[test_codecs.py]=1 # need to fix tryelse
|
||||
[test_coercion.py]=1
|
||||
[test_contextlib.py]=1
|
||||
@@ -43,7 +40,6 @@ case $PYVERSION in
|
||||
[test_grammar.py]=1 # Too many stmts. Handle large stmts
|
||||
[test_grp.py]=1 # Long test - might work Control flow?
|
||||
[test_imp.py]=1
|
||||
[test_long_future.py]=1 # Control flow?
|
||||
[test_math.py]=1 # Control flow?
|
||||
[test_pwd.py]=1 # Long test - might work? Control flow?
|
||||
[test_queue.py]=1 # Control flow?
|
||||
|
@@ -263,6 +263,7 @@ class PythonParser(GenericASTBuilder):
|
||||
c_stmts_opt ::= c_stmts
|
||||
c_stmts_opt ::= pass
|
||||
|
||||
# statements inside a loop
|
||||
l_stmts ::= _stmts
|
||||
l_stmts ::= returns
|
||||
l_stmts ::= continues
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2016-2017 Rocky Bernstein
|
||||
# Copyright (c) 2016-2018 Rocky Bernstein
|
||||
"""
|
||||
spark grammar differences over Python2.5 for Python 2.4.
|
||||
"""
|
||||
@@ -69,6 +69,7 @@ class Python24Parser(Python25Parser):
|
||||
super(Python24Parser, self).customize_grammar_rules(tokens, customize)
|
||||
if self.version == 2.4:
|
||||
self.check_reduce['nop_stmt'] = 'tokens'
|
||||
self.check_reduce['try_except'] = 'tokens'
|
||||
|
||||
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
||||
invalid = super(Python24Parser,
|
||||
@@ -82,6 +83,15 @@ class Python24Parser(Python25Parser):
|
||||
l = len(tokens)
|
||||
if 0 <= l < len(tokens):
|
||||
return not int(tokens[first].pattr) == tokens[last].offset
|
||||
elif lhs == 'try_except':
|
||||
if last == len(tokens):
|
||||
last -= 1
|
||||
if tokens[last] != 'COME_FROM' and tokens[last-1] == 'COME_FROM':
|
||||
last -= 1
|
||||
return (tokens[last] == 'COME_FROM'
|
||||
and tokens[last-1] == 'END_FINALLY'
|
||||
and tokens[last-2] == 'POP_TOP'
|
||||
and tokens[last-3].kind != 'JUMP_FORWARD')
|
||||
|
||||
return False
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2016-2017 Rocky Bernstein
|
||||
# Copyright (c) 2016-2018 Rocky Bernstein
|
||||
"""
|
||||
spark grammar differences over Python2.6 for Python 2.5.
|
||||
"""
|
||||
@@ -34,8 +34,13 @@ class Python25Parser(Python26Parser):
|
||||
|
||||
store ::= STORE_NAME
|
||||
|
||||
# tryelsetmtl doesn't need COME_FROM since the jump might not
|
||||
# be the the join point at the end of the "try" but instead back to the
|
||||
# loop. FIXME: should "come_froms" below be a single COME_FROM?
|
||||
tryelsestmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||
except_handler else_suite come_froms
|
||||
tryelsestmtl ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||
except_handler else_suitel
|
||||
|
||||
# Python 2.6 omits the LOAD_FAST DELETE_FAST below
|
||||
# withas is allowed as a "from future" in 2.5
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2016-2017 by Rocky Bernstein
|
||||
# Copyright (c) 2016-2018 by Rocky Bernstein
|
||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||
# Copyright (c) 1999 John Aycock
|
||||
|
||||
@@ -34,14 +34,18 @@ class Token():
|
||||
self.opc = opc
|
||||
|
||||
def __eq__(self, o):
|
||||
""" '==', but it's okay if offsets and linestarts are different"""
|
||||
""" '==' on kind and "pattr" attributes.
|
||||
It is okay if offsets and linestarts are different"""
|
||||
if isinstance(o, Token):
|
||||
# Both are tokens: compare type and attr
|
||||
# It's okay if offsets are different
|
||||
return (self.kind == o.kind) and (self.pattr == o.pattr)
|
||||
else:
|
||||
# ?? do we need this?
|
||||
return self.kind == o
|
||||
|
||||
def __ne__(self, o):
|
||||
""" '!=', but it's okay if offsets and linestarts are different"""
|
||||
return not self.__eq__(o)
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.kind)
|
||||
|
||||
|
Reference in New Issue
Block a user