Add async_call_function for 3.5+

This commit is contained in:
rocky
2017-01-09 07:03:51 -05:00
parent d050dd3adb
commit ad345ef94a
5 changed files with 22 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,8 +1,8 @@
# Python 3.5+ async and await
async def await_test():
async def await_test(asyncio):
reader, writer = await asyncio.open_connection(80)
await bar()
async def afor_test():
async for i in [1,2,3]:

View File

@@ -453,6 +453,15 @@ class Python3Parser(PythonParser):
('kwarg ' * args_kw) +
'expr ' * nak + token.type)
self.add_unique_rule(rule, token.type, args_pos, customize)
if self.version >= 3.5:
rule = ('async_call_function ::= expr ' +
('pos_arg ' * args_pos) +
('kwarg ' * args_kw) +
'expr ' * nak + token.type +
' GET_AWAITABLE LOAD_CONST YIELD_FROM')
self.add_unique_rule(rule, token.type, args_pos, customize)
self.add_unique_rule('expr ::= async_call_function', token.type, args_pos, customize)
rule = ('classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc %s%s_%d'
% (('expr ' * (args_pos-1)), opname, args_pos))
self.add_unique_rule(rule, token.type, args_pos, customize)

View File

@@ -332,6 +332,16 @@ class SourceWalker(GenericASTTraversal, object):
'%|async with %c as %c:\n%+%c%-', 0, 6, 7),
})
def n_async_call_function(node):
self.f.write('async ')
node.type == 'call_function'
p = self.prec
self.prec = 80
self.engine(('%c(%P)', 0, (1, -4, ', ', 100)), node)
self.prec = p
self.prune()
self.n_async_call_function = n_async_call_function
def n_funcdef(node):
code_node = node[0][1]
if (code_node == 'LOAD_CONST' and iscode(code_node.attr)
@@ -1589,7 +1599,7 @@ class SourceWalker(GenericASTTraversal, object):
beginning of this module for the how we interpret format specifications such as
%c, %C, and so on.
"""
# self.println("----> ", startnode.type)
# self.println("----> ", startnode.type, ', ', entry[0])
fmt = entry[0]
arg = 1
i = 0