Fix 3.6 async parsing

This commit is contained in:
rocky
2022-05-04 04:27:38 -04:00
parent d62310f799
commit 9dd4a53ff8
4 changed files with 54 additions and 25 deletions

View File

@@ -12,7 +12,6 @@ SKIP_TESTS=(
[test_aifc.py]=1 # [test_aifc.py]=1 #
[test_argparse.py]=1 # it fails on its own [test_argparse.py]=1 # it fails on its own
[test_asdl_parser.py]=1 # it fails on its own [test_asdl_parser.py]=1 # it fails on its own
[test_asyncgen.py]=1 # parse error
[test_atexit.py]=1 # The atexit test looks for specific comments in error lines [test_atexit.py]=1 # The atexit test looks for specific comments in error lines
[test_baseexception.py]=1 # test assert error [test_baseexception.py]=1 # test assert error
@@ -39,9 +38,9 @@ SKIP_TESTS=(
[test_collections.py]= # it fails on its own [test_collections.py]= # it fails on its own
[test_compile.py]=1 # Code introspects on co_consts in a non-decompilable way [test_compile.py]=1 # Code introspects on co_consts in a non-decompilable way
[test_concurrent_futures.py]=1 # Takes long [test_concurrent_futures.py]=1 # Takes long
[test_contextlib.py]=1 # test assertion failure
[test_contextlib_async.py]=1 # Investigate [test_coroutines.py]=1 # FIXME: async parse error
[test_coroutines.py]=1 # parse error
[test_curses.py]=1 # Parse error [test_curses.py]=1 # Parse error
[test_ctypes.py]=1 # it fails on its own [test_ctypes.py]=1 # it fails on its own

View File

@@ -29,7 +29,13 @@ class Python36Parser(Python35Parser):
self.customized = {} self.customized = {}
def p_36misc(self, args): def p_jump_36(self, args):
"""
# Zero or one COME_FROM
# And/or expressions have this
come_from_opt ::= COME_FROM?
"""
def p_misc_36(self, args):
"""sstmt ::= sstmt RETURN_LAST """sstmt ::= sstmt RETURN_LAST
# long except clauses in a loop can sometimes cause a JUMP_BACK to turn into a # long except clauses in a loop can sometimes cause a JUMP_BACK to turn into a
@@ -67,6 +73,33 @@ class Python36Parser(Python35Parser):
if_exp ::= expr jmp_false expr jf_cf expr COME_FROM if_exp ::= expr jmp_false expr jf_cf expr COME_FROM
async_for_stmt36 ::= SETUP_LOOP expr
GET_AITER
LOAD_CONST YIELD_FROM
SETUP_EXCEPT GET_ANEXT LOAD_CONST
YIELD_FROM
store
POP_BLOCK JUMP_BACK COME_FROM_EXCEPT DUP_TOP
LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
END_FINALLY for_block
COME_FROM
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP POP_BLOCK
COME_FROM_LOOP
async_for_stmt36 ::= SETUP_LOOP expr
GET_AITER
LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST
YIELD_FROM
store
POP_BLOCK JUMP_FORWARD COME_FROM_EXCEPT DUP_TOP
LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
END_FINALLY
COME_FROM
for_block
COME_FROM
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP POP_BLOCK
COME_FROM_LOOP
async_for_stmt ::= SETUP_LOOP expr async_for_stmt ::= SETUP_LOOP expr
GET_AITER GET_AITER
LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST
@@ -81,20 +114,6 @@ class Python36Parser(Python35Parser):
stmt ::= async_for_stmt36 stmt ::= async_for_stmt36
async_for_stmt36 ::= SETUP_LOOP expr
GET_AITER
LOAD_CONST YIELD_FROM
SETUP_EXCEPT GET_ANEXT LOAD_CONST
YIELD_FROM
store
POP_BLOCK JUMP_BACK COME_FROM_EXCEPT DUP_TOP
LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
END_FINALLY for_block
COME_FROM
POP_TOP POP_TOP POP_TOP POP_EXCEPT
POP_TOP POP_BLOCK
COME_FROM_LOOP
async_forelse_stmt ::= SETUP_LOOP expr async_forelse_stmt ::= SETUP_LOOP expr
GET_AITER GET_AITER
LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST

View File

@@ -28,6 +28,7 @@ from uncompyle6.semantics.helper import flatten_list, gen_function_parens_adjust
# Python 3.5+ Changes # # Python 3.5+ Changes #
####################### #######################
def customize_for_version35(self, version): def customize_for_version35(self, version):
# fmt: off
TABLE_DIRECT.update( TABLE_DIRECT.update(
{ {
# nested await expressions like: # nested await expressions like:
@@ -36,15 +37,24 @@ def customize_for_version35(self, version):
"await_expr": ("await %p", (0, PRECEDENCE["await_expr"]-1)), "await_expr": ("await %p", (0, PRECEDENCE["await_expr"]-1)),
"await_stmt": ("%|%c\n", 0), "await_stmt": ("%|%c\n", 0),
"async_for_stmt": ("%|async for %c in %c:\n%+%|%c%-\n\n", 9, 1, 25), "async_for_stmt": (
"%|async for %c in %c:\n%+%|%c%-\n\n",
(9, "store"),
(1, "expr"),
(25, "for_block"),
),
"async_forelse_stmt": ( "async_forelse_stmt": (
"%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n", "%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n",
9, (9, "store"),
1, (1, "expr"),
25, (25, "for_block"),
(27, "else_suite"), (27, "else_suite"),
), ),
"async_with_stmt": ("%|async with %c:\n%+%c%-", (0, "expr"), 3), "async_with_stmt": (
"%|async with %c:\n%+%c%-",
(0, "expr"),
3
),
"async_with_as_stmt": ( "async_with_as_stmt": (
"%|async with %c as %c:\n%+%c%-", "%|async with %c as %c:\n%+%c%-",
(0, "expr"), (0, "expr"),
@@ -55,6 +65,7 @@ def customize_for_version35(self, version):
# "unmapexpr": ( "{**%c}", 0), # done by n_unmapexpr # "unmapexpr": ( "{**%c}", 0), # done by n_unmapexpr
} }
) )
# fmt: on
def async_call(node): def async_call(node):
self.f.write("async ") self.f.write("async ")

View File

@@ -61,7 +61,7 @@ def customize_for_version36(self, version):
"%|async for %c in %c:\n%+%c%-\n\n", "%|async for %c in %c:\n%+%c%-\n\n",
(9, "store"), (9, "store"),
(1, "expr"), (1, "expr"),
(18, "for_block"), (-9, "for_block"), # Count from end, since COME_FROM shifts things in the forward direction
), ),
"call_ex": ("%c(%p)", (0, "expr"), (1, 100)), "call_ex": ("%c(%p)", (0, "expr"), (1, 100)),
"except_return": ("%|except:\n%+%c%-", 3), "except_return": ("%|except:\n%+%c%-", 3),