diff --git a/test/bytecode_2.4_run/02_try_else_loop.pyc b/test/bytecode_2.4_run/02_try_else_loop.pyc new file mode 100644 index 00000000..fcd11b61 Binary files /dev/null and b/test/bytecode_2.4_run/02_try_else_loop.pyc differ diff --git a/test/bytecode_2.4_run/03_try_else.pyc b/test/bytecode_2.4_run/03_try_else.pyc new file mode 100644 index 00000000..58ce4945 Binary files /dev/null and b/test/bytecode_2.4_run/03_try_else.pyc differ diff --git a/test/stdlib/runtests.sh b/test/stdlib/runtests.sh index 10f60c4b..d268576a 100755 --- a/test/stdlib/runtests.sh +++ b/test/stdlib/runtests.sh @@ -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? diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 72855f60..200045cd 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -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 diff --git a/uncompyle6/parsers/parse24.py b/uncompyle6/parsers/parse24.py index e1ee78f9..2c4584af 100644 --- a/uncompyle6/parsers/parse24.py +++ b/uncompyle6/parsers/parse24.py @@ -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 diff --git a/uncompyle6/parsers/parse25.py b/uncompyle6/parsers/parse25.py index 461c713f..cba2cdce 100644 --- a/uncompyle6/parsers/parse25.py +++ b/uncompyle6/parsers/parse25.py @@ -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 diff --git a/uncompyle6/scanners/tok.py b/uncompyle6/scanners/tok.py index f341e049..ae5e9309 100644 --- a/uncompyle6/scanners/tok.py +++ b/uncompyle6/scanners/tok.py @@ -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 # 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)