DRY 3.{5,6} SETUP_WITH a little bit

This commit is contained in:
rocky
2017-12-11 21:48:36 -05:00
parent b84c35acf5
commit 41228a5ba9
2 changed files with 21 additions and 5 deletions

View File

@@ -54,9 +54,7 @@ class Python35Parser(Python34Parser):
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
# Python 3.5+ async additions
stmt ::= async_for_stmt
async_for_stmt ::= SETUP_LOOP expr
GET_AITER
@@ -142,6 +140,7 @@ class Python35Parser(Python34Parser):
rule = 'call ::= expr unmapexpr ' + call_token.kind
self.addRule(rule, nop_func)
elif opname == 'BEFORE_ASYNC_WITH':
# Some Python 3.5+ async additions
rules_str = """
async_with_stmt ::= expr
stmt ::= async_with_stmt
@@ -171,6 +170,20 @@ class Python35Parser(Python34Parser):
unmap_dict ::= dict_comp BUILD_MAP_UNPACK
""", nop_func)
elif opname == 'SETUP_WITH':
# Python 3.5+ has WITH_CLEANUP_START/FINISH
rules_str = """
withstmt ::= expr
SETUP_WITH POP_TOP suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
withasstmt ::= expr
SETUP_WITH store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
"""
self.addRule(rules_str, nop_func)
pass
return