Handle BUILD_MAP_UNPACK in a build_list

This commit is contained in:
rocky
2017-04-29 21:38:48 -04:00
parent 819458564c
commit 364827a2f2
4 changed files with 6 additions and 5 deletions

Binary file not shown.

View File

@@ -4,3 +4,4 @@
{'x': 1, **{'y': 2}}
# {'c': 1, {'d': 2}, **{'e': 3}}
[*[]]
{**{0:0 for a in b}}

View File

@@ -33,6 +33,8 @@ class Python35Parser(Python34Parser):
stmt ::= await_stmt
await_stmt ::= await_expr POP_TOP
unmap_dict ::= mapexpr BUILD_MAP_UNPACK
build_list ::= expr BUILD_MAP_UNPACK
# Python 3.5+ has WITH_CLEANUP_START/FINISH
@@ -151,10 +153,6 @@ class Python35Parser(Python34Parser):
rule = 'call_function ::= expr unmapexpr ' + call_token.type
self.add_unique_rule(rule, opname, token.attr, customize)
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
return

View File

@@ -1553,10 +1553,12 @@ class SourceWalker(GenericASTTraversal, object):
self.write('('); endchar = ')'
elif lastnodetype.startswith('BUILD_SET'):
self.write('{'); endchar = '}'
elif lastnodetype.startswith('BUILD_MAP_UNPACK'):
self.write('{**'); endchar = '}'
elif lastnodetype.startswith('ROT_TWO'):
self.write('('); endchar = ')'
else:
raise 'Internal Error: n_build_list expects list or tuple'
raise 'Internal Error: n_build_list expects list, tuple, set, or unpack'
have_star = False
if lastnodetype.endswith('UNPACK'):
# FIXME: need to handle range of BUILD_LIST_UNPACK