3.8 exception handling

This commit is contained in:
rocky
2019-04-11 12:09:24 -04:00
parent 94eff282f8
commit 5e1340a2fc
5 changed files with 42 additions and 9 deletions

View File

@@ -29,6 +29,10 @@ class Python38Parser(Python37Parser):
stmt ::= forelsestmt38
stmt ::= forelselaststmt38
stmt ::= forelselaststmtl38
stmt ::= tryfinally38
# FIXME this should be restricted to being inside a try block
stmt ::= except_ret38
for38 ::= expr get_iter store for_block JUMP_BACK
for38 ::= expr for_iter store for_block JUMP_BACK
@@ -39,21 +43,38 @@ class Python38Parser(Python37Parser):
forelselaststmtl38 ::= expr for_iter store for_block POP_BLOCK else_suitel
whilestmt ::= testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK
whilestmt ::= testexpr l_stmts_opt JUMP_BACK POP_BLOCK
whilestmt ::= testexpr returns POP_BLOCK
whilestmt ::= testexpr returns POP_BLOCK
while1elsestmt ::= l_stmts JUMP_BACK
whileelsestmt ::= testexpr l_stmts_opt JUMP_BACK POP_BLOCK
whileTruestmt ::= l_stmts_opt JUMP_BACK POP_BLOCK
whileelsestmt ::= testexpr l_stmts JUMP_BACK POP_BLOCK
whileTruestmt ::= l_stmts JUMP_BACK POP_BLOCK
while1stmt ::= l_stmts COME_FROM_LOOP
while1stmt ::= l_stmts COME_FROM JUMP_BACK COME_FROM_LOOP
while1elsestmt ::= l_stmts JUMP_BACK
whileTruestmt ::= l_stmts_opt JUMP_BACK NOP
whileTruestmt ::= l_stmts_opt JUMP_BACK POP_BLOCK NOP
whileTruestmt ::= l_stmts JUMP_BACK NOP
whileTruestmt ::= l_stmts JUMP_BACK POP_BLOCK NOP
for_block ::= l_stmts_opt _come_from_loops JUMP_BACK
except_cond1 ::= DUP_TOP expr COMPARE_OP jmp_false
POP_TOP POP_TOP POP_TOP
POP_EXCEPT
try_except ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK
except_handler38
except_ret38 ::= SETUP_FINALLY expr ROT_FOUR POP_BLOCK POP_EXCEPT
CALL_FINALLY RETURN_VALUE COME_FROM_FINALLY
suite_stmts_opt END_FINALLY
except_handler38 ::= JUMP_FORWARD COME_FROM_FINALLY
except_stmts END_FINALLY opt_come_from_except
tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK
BEGIN_FINALLY COME_FROM_FINALLY suite_stmts_opt
END_FINALLY
tryfinally38 ::= SETUP_FINALLY POP_BLOCK CALL_FINALLY
returns
COME_FROM_FINALLY END_FINALLY suite_stmts
tryfinally38 ::= SETUP_FINALLY POP_BLOCK CALL_FINALLY
returns
COME_FROM_FINALLY POP_FINALLY returns
END_FINALLY
"""
def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG):
@@ -64,14 +85,23 @@ class Python38Parser(Python37Parser):
self.remove_rules("""
stmt ::= for
stmt ::= forelsestmt
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 NOP
for_block ::= l_stmts_opt COME_FROM_LOOP JUMP_BACK
forelsestmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suite
forelselaststmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitec
forelselaststmtl ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitel
try_except ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
except_handler opt_come_from_except
tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK
LOAD_CONST COME_FROM_FINALLY suite_stmts_opt
END_FINALLY
tryfinally36 ::= SETUP_FINALLY returns
COME_FROM_FINALLY suite_stmts_opt END_FINALLY
""")
super(Python37Parser, self).customize_grammar_rules(tokens, customize)