Python 3.5+ BUILD_UNMAP_PACK rules

Towards addressing Issue #98
This commit is contained in:
rocky 2017-04-14 23:33:38 -04:00
parent 47dbc57f3d
commit 03498963d4
5 changed files with 16 additions and 1 deletions

Binary file not shown.

View File

@ -0,0 +1,5 @@
# Python 3.5+ PEP 448 - Additional Unpacking Generalizations for dictionaries
{**{}}
{**{'a': 1, 'b': 2}}
{'x': 1, **{'y': 2}}
# {'c': 1, {'d': 2}, **{'e': 3}}

View File

@ -661,7 +661,9 @@ class Python3Parser(PythonParser):
if opname != 'BUILD_MAP_WITH_CALL': if opname != 'BUILD_MAP_WITH_CALL':
rule = kvlist_n + ' ::= ' + 'expr ' * (token.attr*2) rule = kvlist_n + ' ::= ' + 'expr ' * (token.attr*2)
self.add_unique_rule(rule, opname, token.attr, customize) self.add_unique_rule(rule, opname, token.attr, customize)
rule = "mapexpr ::= %s %s" % (kvlist_n, opname) lhs = 'unmapexpr' if opname == 'BUILD_MAP_UNPACK' else' mapexpr'
rule = "%s ::= %s %s" % (lhs, kvlist_n, opname)
# print("XXX", rule)
else: else:
rule = kvlist_n + ' ::= ' + 'expr expr STORE_MAP ' * token.attr rule = kvlist_n + ' ::= ' + 'expr expr STORE_MAP ' * token.attr

View File

@ -116,6 +116,8 @@ class Python35Parser(Python34Parser):
yield_from ::= expr GET_YIELD_FROM_ITER LOAD_CONST YIELD_FROM yield_from ::= expr GET_YIELD_FROM_ITER LOAD_CONST YIELD_FROM
expr ::= unmap_dict
expr ::= unmapexpr
""" """
def add_custom_rules(self, tokens, customize): def add_custom_rules(self, tokens, customize):
@ -134,6 +136,10 @@ class Python35Parser(Python34Parser):
rule = 'call_function ::= expr unmapexpr ' + call_token.type rule = 'call_function ::= expr unmapexpr ' + call_token.type
self.add_unique_rule(rule, opname, token.attr, customize) self.add_unique_rule(rule, opname, token.attr, customize)
pass pass
elif opname == 'BUILD_MAP_UNPACK':
nargs = token.attr % 256
rule = "unmap_dict ::= mapexpr " + opname
self.add_unique_rule(rule, opname, token.attr, customize)
pass pass
return return

View File

@ -338,6 +338,8 @@ class SourceWalker(GenericASTTraversal, object):
'%|async with %c:\n%+%c%-', 0, 7), '%|async with %c:\n%+%c%-', 0, 7),
'async_with_as_stmt': ( 'async_with_as_stmt': (
'%|async with %c as %c:\n%+%c%-', 0, 6, 7), '%|async with %c as %c:\n%+%c%-', 0, 6, 7),
'unmap_dict': ( '{**%c}', 0),
'unmapexpr': ( '{**%c}', 0),
}) })
def n_async_call_function(node): def n_async_call_function(node):