You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
3.8 async for/with...
More is needed though.
This commit is contained in:
@@ -160,7 +160,7 @@ class Python35Parser(Python34Parser):
|
|||||||
call_token = tokens[i+1]
|
call_token = tokens[i+1]
|
||||||
rule = 'call ::= expr unmapexpr ' + call_token.kind
|
rule = 'call ::= expr unmapexpr ' + call_token.kind
|
||||||
self.addRule(rule, nop_func)
|
self.addRule(rule, nop_func)
|
||||||
elif opname == 'BEFORE_ASYNC_WITH':
|
elif opname == 'BEFORE_ASYNC_WITH' and self.version < 3.8:
|
||||||
# Some Python 3.5+ async additions
|
# Some Python 3.5+ async additions
|
||||||
rules_str = """
|
rules_str = """
|
||||||
async_with_stmt ::= expr
|
async_with_stmt ::= expr
|
||||||
|
@@ -35,21 +35,40 @@ class Python38Parser(Python37Parser):
|
|||||||
stmt ::= try_except38
|
stmt ::= try_except38
|
||||||
stmt ::= whilestmt38
|
stmt ::= whilestmt38
|
||||||
stmt ::= whileTruestmt38
|
stmt ::= whileTruestmt38
|
||||||
|
stmt ::= call
|
||||||
|
|
||||||
# FIXME this should be restricted to being inside a try block
|
# FIXME this should be restricted to being inside a try block
|
||||||
stmt ::= except_ret38
|
stmt ::= except_ret38
|
||||||
|
|
||||||
async_for_stmt38 ::= expr
|
# FIXME this should be added only when seeing GET_AITER or YIELD_FROM
|
||||||
GET_AITER
|
async_for_stmt38 ::= expr
|
||||||
SETUP_FINALLY
|
GET_AITER
|
||||||
GET_ANEXT
|
SETUP_FINALLY
|
||||||
LOAD_CONST
|
GET_ANEXT
|
||||||
YIELD_FROM
|
LOAD_CONST
|
||||||
POP_BLOCK
|
YIELD_FROM
|
||||||
store for_block
|
POP_BLOCK
|
||||||
COME_FROM_FINALLY
|
store for_block
|
||||||
END_ASYNC_FOR
|
COME_FROM_FINALLY
|
||||||
|
END_ASYNC_FOR
|
||||||
|
|
||||||
|
async_with_stmt ::= expr BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||||
|
SETUP_ASYNC_WITH POP_TOP
|
||||||
|
suite_stmts
|
||||||
|
POP_TOP POP_BLOCK
|
||||||
|
BEGIN_FINALLY
|
||||||
|
WITH_CLEANUP_START
|
||||||
|
GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||||
|
WITH_CLEANUP_FINISH END_FINALLY
|
||||||
|
|
||||||
|
async_with_as_stmt ::= expr BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||||
|
SETUP_ASYNC_WITH store
|
||||||
|
suite_stmts
|
||||||
|
POP_TOP POP_BLOCK
|
||||||
|
BEGIN_FINALLY
|
||||||
|
WITH_CLEANUP_START
|
||||||
|
GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||||
|
WITH_CLEANUP_FINISH END_FINALLY
|
||||||
|
|
||||||
return ::= ret_expr ROT_TWO POP_TOP RETURN_VALUE
|
return ::= ret_expr ROT_TWO POP_TOP RETURN_VALUE
|
||||||
|
|
||||||
@@ -132,7 +151,8 @@ class Python38Parser(Python37Parser):
|
|||||||
END_FINALLY for_block COME_FROM
|
END_FINALLY for_block COME_FROM
|
||||||
POP_TOP POP_TOP POP_TOP POP_EXCEPT
|
POP_TOP POP_TOP POP_TOP POP_EXCEPT
|
||||||
POP_TOP POP_BLOCK
|
POP_TOP POP_BLOCK
|
||||||
COME_FROM_LOOP
|
COME_FROM_LOOP
|
||||||
|
|
||||||
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
||||||
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK NOP
|
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK NOP
|
||||||
|
|
||||||
@@ -154,6 +174,7 @@ class Python38Parser(Python37Parser):
|
|||||||
""")
|
""")
|
||||||
super(Python37Parser, self).customize_grammar_rules(tokens, customize)
|
super(Python37Parser, self).customize_grammar_rules(tokens, customize)
|
||||||
self.check_reduce['ifstmt'] = 'tokens'
|
self.check_reduce['ifstmt'] = 'tokens'
|
||||||
|
self.check_reduce['whileTruestmt38'] = 'tokens'
|
||||||
|
|
||||||
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
||||||
invalid = super(Python38Parser,
|
invalid = super(Python38Parser,
|
||||||
@@ -178,6 +199,12 @@ class Python38Parser(Python37Parser):
|
|||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
elif rule[0] == 'whileTruestmt38':
|
||||||
|
t = tokens[last-1]
|
||||||
|
if t.kind == 'JUMP_BACK':
|
||||||
|
return t.attr != tokens[first].offset
|
||||||
|
pass
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class Python38ParserSingle(Python38Parser, PythonParserSingle):
|
class Python38ParserSingle(Python38Parser, PythonParserSingle):
|
||||||
|
@@ -285,14 +285,16 @@ def customize_for_version3(self, version):
|
|||||||
'await_expr': ( 'await %c', 0),
|
'await_expr': ( 'await %c', 0),
|
||||||
'await_stmt': ( '%|%c\n', 0),
|
'await_stmt': ( '%|%c\n', 0),
|
||||||
'async_for_stmt': (
|
'async_for_stmt': (
|
||||||
'%|async for %c in %c:\n%+%c%-\n\n', 9, 1, 25 ),
|
'%|async for %c in %c:\n%+%|%c%-\n\n', 9, 1, 25 ),
|
||||||
'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, 1, 25, (27, 'else_suite') ),
|
9, 1, 25, (27, 'else_suite') ),
|
||||||
'async_with_stmt': (
|
'async_with_stmt': (
|
||||||
'%|async with %c:\n%+%c%-', 0, 7),
|
'%|async with %c:\n%+%|%c%-',
|
||||||
|
(0, 'expr'), 7 ),
|
||||||
'async_with_as_stmt': (
|
'async_with_as_stmt': (
|
||||||
'%|async with %c as %c:\n%+%c%-', 0, 6, 7),
|
'%|async with %c as %c:\n%+%|%c%-',
|
||||||
|
(0, 'expr'), (6, 'store'), 7),
|
||||||
'unmap_dict': ( '{**%C}', (0, -1, ', **') ),
|
'unmap_dict': ( '{**%C}', (0, -1, ', **') ),
|
||||||
# 'unmapexpr': ( '{**%c}', 0), # done by n_unmapexpr
|
# 'unmapexpr': ( '{**%c}', 0), # done by n_unmapexpr
|
||||||
|
|
||||||
@@ -952,7 +954,16 @@ def customize_for_version3(self, version):
|
|||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({
|
||||||
'async_for_stmt38': (
|
'async_for_stmt38': (
|
||||||
'%|async for %c in %c:\n%+%c%-%-\n\n',
|
'%|async for %c in %c:\n%+%c%-%-\n\n',
|
||||||
(0, 'expr'), (7, 'store'), (8, 'for_block') ),
|
(7, 'store'), (0, 'expr'), (8, 'for_block') ),
|
||||||
|
|
||||||
|
'async_with_stmt38': (
|
||||||
|
'%|async with %c:\n%+%|%c%-',
|
||||||
|
(0, 'expr'), 7),
|
||||||
|
|
||||||
|
'async_with_as_stmt38': (
|
||||||
|
'%|async with %c as %c:\n%+%|%c%-',
|
||||||
|
(0, 'expr'), (6, 'store'),
|
||||||
|
(7, 'suite_stmts') ),
|
||||||
|
|
||||||
'except_handler38a': (
|
'except_handler38a': (
|
||||||
'%c', (-2, 'stmts') ),
|
'%c', (-2, 'stmts') ),
|
||||||
|
Reference in New Issue
Block a user