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

View File

@@ -27,9 +27,6 @@ class Python36Parser(Python35Parser):
return_if_lambda ::= RETURN_END_IF_LAMBDA
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
for_block ::= l_stmts_opt come_from_loops JUMP_BACK
come_from_loops ::= COME_FROM_LOOP*
@@ -107,6 +104,12 @@ class Python36Parser(Python35Parser):
%s ::= %sBUILD_STRING
""" % (joined_str_n, joined_str_n, "formatted_value " * v)
self.add_unique_doc_rules(rules_str, customize)
elif opname == 'SETUP_WITH':
rules_str = """
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
"""
self.addRule(rules_str, nop_func)
def custom_classfunc_rule(self, opname, token, customize,
possible_class_decorator,