You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
3.8 try/except handling - again (and more to come)
This commit is contained in:
@@ -31,6 +31,7 @@ class Python38Parser(Python37Parser):
|
|||||||
stmt ::= forelselaststmtl38
|
stmt ::= forelselaststmtl38
|
||||||
stmt ::= tryfinally38
|
stmt ::= tryfinally38
|
||||||
stmt ::= try_except_ret38
|
stmt ::= try_except_ret38
|
||||||
|
stmt ::= try_except38
|
||||||
|
|
||||||
# FIXME this should be restricted to being inside a try block
|
# FIXME this should be restricted to being inside a try block
|
||||||
stmt ::= except_ret38
|
stmt ::= except_ret38
|
||||||
@@ -60,8 +61,11 @@ class Python38Parser(Python37Parser):
|
|||||||
POP_EXCEPT
|
POP_EXCEPT
|
||||||
try_except ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK
|
try_except ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK
|
||||||
except_handler38
|
except_handler38
|
||||||
|
try_except38 ::= SETUP_FINALLY POP_BLOCK POP_TOP suite_stmts_opt
|
||||||
|
except_handler38a
|
||||||
try_except_ret38 ::= SETUP_FINALLY expr POP_BLOCK
|
try_except_ret38 ::= SETUP_FINALLY expr POP_BLOCK
|
||||||
RETURN_VALUE except_ret38a
|
RETURN_VALUE except_ret38a
|
||||||
|
|
||||||
except_ret38 ::= SETUP_FINALLY expr ROT_FOUR POP_BLOCK POP_EXCEPT
|
except_ret38 ::= SETUP_FINALLY expr ROT_FOUR POP_BLOCK POP_EXCEPT
|
||||||
CALL_FINALLY RETURN_VALUE COME_FROM_FINALLY
|
CALL_FINALLY RETURN_VALUE COME_FROM_FINALLY
|
||||||
suite_stmts_opt END_FINALLY
|
suite_stmts_opt END_FINALLY
|
||||||
@@ -70,6 +74,9 @@ class Python38Parser(Python37Parser):
|
|||||||
POP_EXCEPT RETURN_VALUE END_FINALLY
|
POP_EXCEPT RETURN_VALUE END_FINALLY
|
||||||
except_handler38 ::= JUMP_FORWARD COME_FROM_FINALLY
|
except_handler38 ::= JUMP_FORWARD COME_FROM_FINALLY
|
||||||
except_stmts END_FINALLY opt_come_from_except
|
except_stmts END_FINALLY opt_come_from_except
|
||||||
|
except_handler38a ::= COME_FROM_FINALLY POP_TOP POP_TOP POP_TOP
|
||||||
|
POP_EXCEPT POP_TOP stmts END_FINALLY
|
||||||
|
|
||||||
tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK
|
tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK
|
||||||
BEGIN_FINALLY COME_FROM_FINALLY suite_stmts_opt
|
BEGIN_FINALLY COME_FROM_FINALLY suite_stmts_opt
|
||||||
END_FINALLY
|
END_FINALLY
|
||||||
@@ -94,7 +101,7 @@ class Python38Parser(Python37Parser):
|
|||||||
self.remove_rules("""
|
self.remove_rules("""
|
||||||
stmt ::= for
|
stmt ::= for
|
||||||
stmt ::= forelsestmt
|
stmt ::= forelsestmt
|
||||||
stmt ::= try_except38
|
stmt ::= try_except36
|
||||||
|
|
||||||
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
||||||
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK NOP
|
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK NOP
|
||||||
|
@@ -967,11 +967,16 @@ def customize_for_version3(self, version):
|
|||||||
'%|try:\n%+%c%-%|finally:\n%+%c%-\n\n',
|
'%|try:\n%+%c%-%|finally:\n%+%c%-\n\n',
|
||||||
(3, 'returns'), 6 ),
|
(3, 'returns'), 6 ),
|
||||||
'except_ret38': ( '%|return %c\n', (1, 'expr') ),
|
'except_ret38': ( '%|return %c\n', (1, 'expr') ),
|
||||||
|
'try_except38': (
|
||||||
|
'%|try:\n%+%c\n%-%|except:\n%|%-%c\n\n',
|
||||||
|
(-2, 'suite_stmts_opt'), (-1, 'except_handler38a') ),
|
||||||
'try_except_ret38': (
|
'try_except_ret38': (
|
||||||
'%|try:\n%+%|return %c%-\n%|except:\n%+%|%c%-\n\n',
|
'%|try:\n%+%|return %c%-\n%|except:\n%+%|%c%-\n\n',
|
||||||
(1, 'expr'), (-1, 'except_ret38a') ),
|
(1, 'expr'), (-1, 'except_ret38a') ),
|
||||||
'except_ret38a': (
|
'except_ret38a': (
|
||||||
'return %c', (4, 'expr') )
|
'return %c', (4, 'expr') ),
|
||||||
|
'except_handler38a': (
|
||||||
|
'%c', (-2, 'stmts') )
|
||||||
})
|
})
|
||||||
pass # version >= 3.8
|
pass # version >= 3.8
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user