More Python 2 and 3 deparsing bugs fixed

* while + if break
* try + finall /pass
This commit is contained in:
rocky
2016-05-05 20:56:41 -04:00
parent 845a4a2003
commit c58481a9eb
10 changed files with 27 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,10 @@
# Tests and empty finally section
# tryfinallystmt ::= SETUP_FINALLY e_suite_stmts_opt
# POP_BLOCK LOAD_CONST COME_FROM e_suite_stmts_opt END_FINALLY
#
try:
pass
finally:
pass
pass

View File

@@ -0,0 +1,10 @@
# Tests
# while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK COME_FROM
# tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK
try:
while 1:
if __file__:
break
finally:
pass

View File

@@ -215,6 +215,5 @@ del def_op, name_op, jrel_op, jabs_op
from uncompyle6 import PYTHON_VERSION
if PYTHON_VERSION == 2.7:
import dis
# print(dis.opmap.items())
print(set(dis.opmap.items()) - set(opmap.items()))
# print(set(dis.opmap.items()) - set(opmap.items()))
assert all(item in opmap.items() for item in dis.opmap.items())

View File

@@ -448,7 +448,7 @@ def python_parser(version, co, out=sys.stdout, showasm=False,
print(t)
# For heavy grammar debugging
# parser_debug = {'rules': True, 'transition': True, 'reduce' : True}
parser_debug = {'rules': True, 'transition': True, 'reduce' : True}
p = get_python_parser(version, parser_debug)
return parse(p, tokens, customize)

View File

@@ -268,7 +268,7 @@ class Python2Parser(PythonParser):
try_middle COME_FROM
# this is nested inside a trystmt
tryfinallystmt ::= SETUP_FINALLY suite_stmts
tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt
POP_BLOCK LOAD_CONST
COME_FROM suite_stmts_opt END_FINALLY
@@ -328,7 +328,10 @@ class Python2Parser(PythonParser):
return_stmts
POP_BLOCK COME_FROM
while1stmt_pre ::= SETUP_LOOP l_stmts JUMP_BACK
while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM
while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK COME_FROM
while1stmt ::= SETUP_LOOP return_stmts COME_FROM
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM

View File

@@ -263,7 +263,7 @@ class Python3Parser(PythonParser):
try_middle _come_from _come_from
# this is nested inside a trystmt
tryfinallystmt ::= SETUP_FINALLY suite_stmts
tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt
POP_BLOCK LOAD_CONST
COME_FROM suite_stmts_opt END_FINALLY