You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Merge branch 'master' into python-2.4
This commit is contained in:
@@ -265,11 +265,11 @@ class Python26Parser(Python2Parser):
|
||||
kvlist ::= kvlist kv3
|
||||
|
||||
# Note: preserve positions 0 2 and 4 for semantic actions
|
||||
conditional_not ::= expr jmp_true expr jf_cf_pop expr COME_FROM
|
||||
conditional ::= expr jmp_false expr jf_cf_pop expr come_from_opt
|
||||
expr ::= conditional_not
|
||||
conditional_not ::= expr jmp_true expr jf_cf_pop expr COME_FROM
|
||||
conditional ::= expr jmp_false expr jf_cf_pop expr come_from_opt
|
||||
expr ::= conditional_not
|
||||
|
||||
and ::= expr JUMP_IF_FALSE POP_TOP expr JUMP_IF_FALSE POP_TOP
|
||||
and ::= expr JUMP_IF_FALSE POP_TOP expr JUMP_IF_FALSE POP_TOP
|
||||
|
||||
# compare_chained is like x <= y <= z
|
||||
compare_chained ::= expr compare_chained1 ROT_TWO COME_FROM POP_TOP _come_froms
|
||||
|
@@ -58,6 +58,7 @@ class Python30Parser(Python31Parser):
|
||||
JUMP_BACK
|
||||
|
||||
|
||||
# JUMP_IF_TRUE POP_TOP as a replacement
|
||||
comp_if ::= expr jmp_false comp_iter
|
||||
comp_iter ::= expr expr SET_ADD
|
||||
comp_iter ::= expr expr LIST_APPEND
|
||||
@@ -68,12 +69,16 @@ class Python30Parser(Python31Parser):
|
||||
except_suite_finalize ::= SETUP_FINALLY c_stmts_opt except_var_finalize END_FINALLY
|
||||
_jump POP_TOP
|
||||
jump_except ::= JUMP_FORWARD POP_TOP
|
||||
or ::= expr jmp_false expr jmp_true expr
|
||||
|
||||
################################################################################
|
||||
# In many ways 3.0 is like 2.6. The below rules in fact are the same or similar.
|
||||
# In many ways 3.0 is like 2.6. One similarity is there is no JUMP_IF_TRUE and
|
||||
# JUMP_IF_FALSE
|
||||
# The below rules in fact are the same or similar.
|
||||
|
||||
jmp_true ::= JUMP_IF_TRUE POP_TOP
|
||||
jmp_false ::= JUMP_IF_FALSE POP_TOP
|
||||
|
||||
for_block ::= l_stmts_opt _come_froms POP_TOP JUMP_BACK
|
||||
|
||||
except_handler ::= JUMP_FORWARD COME_FROM_EXCEPT except_stmts
|
||||
@@ -82,7 +87,7 @@ class Python30Parser(Python31Parser):
|
||||
POP_TOP END_FINALLY
|
||||
|
||||
return_if_stmt ::= ret_expr RETURN_END_IF POP_TOP
|
||||
and ::= expr JUMP_IF_FALSE POP_TOP expr COME_FROM
|
||||
and ::= expr jmp_false expr come_from_opt
|
||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt
|
||||
JUMP_BACK POP_TOP POP_BLOCK COME_FROM_LOOP
|
||||
whilestmt ::= SETUP_LOOP testexpr returns
|
||||
|
@@ -1170,42 +1170,52 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
# collection = node[-3]
|
||||
collections = [node[-3]]
|
||||
list_ifs = []
|
||||
assert n == 'list_iter'
|
||||
|
||||
stores = []
|
||||
if self.version == 3.0 and n != 'list_iter':
|
||||
# FIXME 3.0 is a snowflake here. We need
|
||||
# special code for this. Not sure if this is totally
|
||||
# correct.
|
||||
stores = [ast[3]]
|
||||
assert ast[4] == 'comp_iter'
|
||||
n = ast[4]
|
||||
# Skip over n[0] which is something like: _[1]
|
||||
self.preorder(n[1])
|
||||
|
||||
# Find the list comprehension body. It is the inner-most
|
||||
# node that is not list_.. .
|
||||
while n == 'list_iter':
|
||||
n = n[0] # recurse one step
|
||||
if n == 'list_for':
|
||||
stores.append(n[2])
|
||||
n = n[3]
|
||||
if self.version >= 3.6 and n[0] == 'list_for':
|
||||
# Dog-paddle down largely singleton reductions
|
||||
# to find the collection (expr)
|
||||
c = n[0][0]
|
||||
if c == 'expr':
|
||||
c = c[0]
|
||||
# FIXME: grammar is wonky here? Is this really an attribute?
|
||||
if c == 'attribute':
|
||||
c = c[0]
|
||||
collections.append(c)
|
||||
else:
|
||||
assert n == 'list_iter'
|
||||
stores = []
|
||||
# Find the list comprehension body. It is the inner-most
|
||||
# node that is not list_.. .
|
||||
while n == 'list_iter':
|
||||
n = n[0] # recurse one step
|
||||
if n == 'list_for':
|
||||
stores.append(n[2])
|
||||
n = n[3]
|
||||
if self.version >= 3.6 and n[0] == 'list_for':
|
||||
# Dog-paddle down largely singleton reductions
|
||||
# to find the collection (expr)
|
||||
c = n[0][0]
|
||||
if c == 'expr':
|
||||
c = c[0]
|
||||
# FIXME: grammar is wonky here? Is this really an attribute?
|
||||
if c == 'attribute':
|
||||
c = c[0]
|
||||
collections.append(c)
|
||||
pass
|
||||
elif n in ('list_if', 'list_if_not'):
|
||||
# FIXME: just a guess
|
||||
if n[0].kind == 'expr':
|
||||
list_ifs.append(n)
|
||||
else:
|
||||
list_ifs.append([1])
|
||||
n = n[2]
|
||||
pass
|
||||
elif n in ('list_if', 'list_if_not'):
|
||||
# FIXME: just a guess
|
||||
if n[0].kind == 'expr':
|
||||
list_ifs.append(n)
|
||||
else:
|
||||
list_ifs.append([1])
|
||||
n = n[2]
|
||||
pass
|
||||
pass
|
||||
|
||||
assert n == 'lc_body', ast
|
||||
assert n == 'lc_body', ast
|
||||
self.preorder(n[0])
|
||||
|
||||
# FIXME: add indentation around "for"'s and "in"'s
|
||||
self.preorder(n[0])
|
||||
if self.version < 3.6:
|
||||
self.write(' for ')
|
||||
self.preorder(stores[0])
|
||||
|
Reference in New Issue
Block a user