You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Fox some 3.6 async_forelse parsing
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2016-2020 Rocky Bernstein
|
||||
# Copyright (c) 2016-2020, 2022 Rocky Bernstein
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -29,13 +29,13 @@ class Python36Parser(Python35Parser):
|
||||
self.customized = {}
|
||||
|
||||
|
||||
def p_jump_36(self, args):
|
||||
def p_36_jump(self, args):
|
||||
"""
|
||||
# Zero or one COME_FROM
|
||||
# And/or expressions have this
|
||||
come_from_opt ::= COME_FROM?
|
||||
"""
|
||||
def p_misc_36(self, args):
|
||||
def p_36_misc(self, args):
|
||||
"""sstmt ::= sstmt RETURN_LAST
|
||||
|
||||
# long except clauses in a loop can sometimes cause a JUMP_BACK to turn into a
|
||||
@@ -113,6 +113,7 @@ class Python36Parser(Python35Parser):
|
||||
COME_FROM_LOOP
|
||||
|
||||
stmt ::= async_for_stmt36
|
||||
stmt ::= async_forelse_stmt36
|
||||
|
||||
async_forelse_stmt ::= SETUP_LOOP expr
|
||||
GET_AITER
|
||||
@@ -126,6 +127,19 @@ class Python36Parser(Python35Parser):
|
||||
for_block POP_BLOCK
|
||||
else_suite COME_FROM_LOOP
|
||||
|
||||
async_forelse_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
|
||||
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP
|
||||
POP_BLOCK
|
||||
else_suite COME_FROM_LOOP
|
||||
|
||||
# Adds a COME_FROM_ASYNC_WITH over 3.5
|
||||
# FIXME: remove corresponding rule for 3.5?
|
||||
|
||||
@@ -182,7 +196,7 @@ class Python36Parser(Python35Parser):
|
||||
|
||||
# Some of this is duplicated from parse37. Eventually we'll probably rebase from
|
||||
# that and then we can remove this.
|
||||
def p_37conditionals(self, args):
|
||||
def p_36_conditionals(self, args):
|
||||
"""
|
||||
expr ::= if_exp37
|
||||
if_exp37 ::= expr expr jf_cfs expr COME_FROM
|
||||
|
@@ -510,7 +510,7 @@ class Python37Parser(Python37BaseParser):
|
||||
_ifstmts_jump ::= c_stmts_opt JUMP_ABSOLUTE JUMP_FORWARD _come_froms
|
||||
"""
|
||||
|
||||
def p_35on(self, args):
|
||||
def p_35_on(self, args):
|
||||
"""
|
||||
|
||||
while1elsestmt ::= setup_loop l_stmts JUMP_BACK
|
||||
@@ -568,7 +568,7 @@ class Python37Parser(Python37BaseParser):
|
||||
iflaststmt ::= testexpr c_stmts_opt JUMP_FORWARD
|
||||
"""
|
||||
|
||||
def p_37async(self, args):
|
||||
def p_37_async(self, args):
|
||||
"""
|
||||
stmt ::= async_for_stmt37
|
||||
stmt ::= async_for_stmt
|
||||
@@ -616,7 +616,7 @@ class Python37Parser(Python37BaseParser):
|
||||
else_suite COME_FROM_LOOP
|
||||
"""
|
||||
|
||||
def p_37chained(self, args):
|
||||
def p_37_chained(self, args):
|
||||
"""
|
||||
testtrue ::= compare_chained37
|
||||
testfalse ::= compare_chained37_false
|
||||
@@ -661,7 +661,7 @@ class Python37Parser(Python37BaseParser):
|
||||
compare_chained2a_false_37
|
||||
"""
|
||||
|
||||
def p_37conditionals(self, args):
|
||||
def p_37_conditionals(self, args):
|
||||
"""
|
||||
expr ::= if_exp37
|
||||
if_exp37 ::= expr expr jf_cfs expr COME_FROM
|
||||
@@ -1195,7 +1195,7 @@ class Python37Parser(Python37BaseParser):
|
||||
compare_chained2 ::= expr COMPARE_OP come_froms JUMP_FORWARD
|
||||
"""
|
||||
|
||||
def p_37misc(self, args):
|
||||
def p_37_misc(self, args):
|
||||
"""
|
||||
# long except clauses in a loop can sometimes cause a JUMP_BACK to turn into a
|
||||
# JUMP_FORWARD to a JUMP_BACK. And when this happens there is an additional
|
||||
|
@@ -48,7 +48,7 @@ def customize_for_version35(self, version):
|
||||
(9, "store"),
|
||||
(1, "expr"),
|
||||
(25, "for_block"),
|
||||
(27, "else_suite"),
|
||||
(-2, "else_suite"),
|
||||
),
|
||||
"async_with_stmt": (
|
||||
"%|async with %c:\n%+%c%-",
|
||||
|
@@ -63,6 +63,13 @@ def customize_for_version36(self, version):
|
||||
(1, "expr"),
|
||||
(-9, "for_block"), # Count from end, since COME_FROM shifts things in the forward direction
|
||||
),
|
||||
"async_forelse_stmt36": (
|
||||
"%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n",
|
||||
(9, "store"),
|
||||
(1, "expr"),
|
||||
(-9, "for_block"),
|
||||
(-2, "else_suite"),
|
||||
),
|
||||
"call_ex": ("%c(%p)", (0, "expr"), (1, 100)),
|
||||
"except_return": ("%|except:\n%+%c%-", 3),
|
||||
"func_args36": ("%c(**", 0),
|
||||
|
Reference in New Issue
Block a user