Towards handling CALL_FUNCTION_EX_KW...

more work is needed though
This commit is contained in:
rocky
2017-12-14 23:12:37 -05:00
parent 78d5d281a8
commit a3e61a710f
3 changed files with 27 additions and 11 deletions

View File

@@ -498,17 +498,11 @@ class Python3Parser(PythonParser):
('pos_arg ' * args_pos) +
('kwarg ' * args_kw) + kw + token.kind)
self.add_unique_rule(rule, token.kind, uniq_param, customize)
if self.version >= 3.6 and opname == 'CALL_FUNCTION_EX_KW':
rule = ('call36 ::= '
'expr build_tuple_unpack_with_call build_map_unpack_with_call '
'CALL_FUNCTION_EX_KW_1')
self.add_unique_rule(rule, token.kind, uniq_param, customize)
rule = 'call ::= call36'
else:
rule = ('call ::= expr ' +
('pos_arg ' * args_pos) +
('kwarg ' * args_kw) +
'expr ' * nak + token.kind)
rule = ('call ::= expr ' +
('pos_arg ' * args_pos) +
('kwarg ' * args_kw) +
'expr ' * nak + token.kind)
self.add_unique_rule(rule, token.kind, uniq_param, customize)
if self.version >= 3.5 and seen_GET_AWAITABLE_YIELD_FROM:

View File

@@ -140,12 +140,17 @@ class Python36Parser(Python35Parser):
elif opname == 'CALL_FUNCTION_EX_KW':
self.addRule("""expr ::= call_ex_kw
expr ::= call_ex_kw2
expr ::= call_ex_kw3
call_ex_kw ::= expr expr build_map_unpack_with_call
CALL_FUNCTION_EX_KW
call_ex_kw2 ::= expr
build_tuple_unpack_with_call
build_map_unpack_with_call
CALL_FUNCTION_EX_KW
call_ex_kw3 ::= expr
tuple
expr
CALL_FUNCTION_EX_KW
""",
nop_func)
elif opname == 'CALL_FUNCTION_EX':

View File

@@ -612,6 +612,23 @@ class SourceWalker(GenericASTTraversal, object):
self.prune()
self.n_call_ex_kw2 = call_ex_kw2
def call_ex_kw3(node):
self.preorder(node[0])
self.write('(')
tup = node[1]
assert tup == 'tuple'
self.call36_tuple(tup)
expr = node[2]
assert expr == 'expr'
if tup[0].attr > 0:
self.write(', ')
self.write('**')
self.preorder(expr)
self.write(')')
self.prune()
self.n_call_ex_kw3 = call_ex_kw3
def call36_tuple(node):
"""
A tuple used in a call, these are like normal tuples but they