Start to add 3.5+ await and async

This commit is contained in:
rocky
2017-01-07 21:36:37 -05:00
parent e02ebef45d
commit 66741d16ba
5 changed files with 23 additions and 2 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,3 @@
# Python 3.5+ async and await
async def foo():
await bar()

View File

@@ -16,6 +16,10 @@ class Python35Parser(Python34Parser):
def p_35on(self, args): def p_35on(self, args):
""" """
# Python 3.5+ Await statement
sstmt ::= await_stmt
await_stmt ::= call_function GET_AWAITABLE LOAD_CONST YIELD_FROM POP_TOP
# Python 3.5+ has WITH_CLEANUP_START/FINISH # Python 3.5+ has WITH_CLEANUP_START/FINISH
withstmt ::= expr SETUP_WITH exprlist suite_stmts_opt withstmt ::= expr SETUP_WITH exprlist suite_stmts_opt

View File

@@ -60,7 +60,7 @@ methods implement most of the below.
%{...} evaluate ... in context of N %{...} evaluate ... in context of N
%% literal '%' %% literal '%'
%p evaluate N setting precedence %p evaluate N setting precedence
n
* indicates an argument (A) required. * indicates an argument (A) required.
@@ -73,6 +73,8 @@ import sys, re
from uncompyle6 import PYTHON3 from uncompyle6 import PYTHON3
from xdis.code import iscode from xdis.code import iscode
from xdis.util import COMPILER_FLAG_BIT
from uncompyle6.parser import get_python_parser from uncompyle6.parser import get_python_parser
from uncompyle6.parsers.astnode import AST from uncompyle6.parsers.astnode import AST
from spark_parser import GenericASTTraversal, DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG from spark_parser import GenericASTTraversal, DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
@@ -648,6 +650,19 @@ class SourceWalker(GenericASTTraversal, object):
'LOAD_CLASSDEREF': ( '%{pattr}', ), 'LOAD_CLASSDEREF': ( '%{pattr}', ),
}) })
if version >= 3.5: if version >= 3.5:
TABLE_DIRECT.update({
'await_stmt': ( '%|await %c', 0),
})
def n_funcdef(node):
code_node = node[0][1]
if (code_node == 'LOAD_CONST' and iscode(code_node.attr)
and code_node.attr.co_flags & COMPILER_FLAG_BIT['COROUTINE']):
self.engine(('\n\n%|async def %c\n', -2), node)
else:
self.engine(('\n\n%|def %c\n', -2), node)
self.prune()
self.n_funcdef = n_funcdef
def n_unmapexpr(node): def n_unmapexpr(node):
last_n = node[0][-1] last_n = node[0][-1]
for n in node[0]: for n in node[0]:
@@ -1895,7 +1910,6 @@ class SourceWalker(GenericASTTraversal, object):
beginning of this module for the how we interpret format specifications such as beginning of this module for the how we interpret format specifications such as
%c, %C, and so on. %c, %C, and so on.
""" """
# self.println("----> ", startnode.type) # self.println("----> ", startnode.type)
fmt = entry[0] fmt = entry[0]
arg = 1 arg = 1