You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Reduce 3.x rules, esp. listcomp
This commit is contained in:
@@ -25,9 +25,12 @@ def test_grammar():
|
|||||||
('store', 'DUP_TOP', 'designList'))])
|
('store', 'DUP_TOP', 'designList'))])
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
expect_lhs.add('load_genexpr')
|
expect_lhs.add('load_genexpr')
|
||||||
|
expect_lhs.add('kvlist')
|
||||||
|
expect_lhs.add('kv3')
|
||||||
|
|
||||||
unused_rhs = unused_rhs.union(set("""
|
unused_rhs = unused_rhs.union(set("""
|
||||||
except_pop_except generator_exp classdefdeco2 listcomp
|
except_pop_except generator_exp classdefdeco2 listcomp
|
||||||
|
mapexpr
|
||||||
""".split()))
|
""".split()))
|
||||||
if 3.0 <= PYTHON_VERSION:
|
if 3.0 <= PYTHON_VERSION:
|
||||||
expect_lhs.add("annotate_arg")
|
expect_lhs.add("annotate_arg")
|
||||||
|
@@ -828,7 +828,7 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
# FIXME: Fold test into add_make_function_rule
|
# FIXME: Fold test into add_make_function_rule
|
||||||
j = 1 if self.version < 3.3 else 2
|
j = 1 if self.version < 3.3 else 2
|
||||||
if is_pypy or (i > j and tokens[i-j] == 'LOAD_LAMBDA'):
|
if is_pypy or (i >= j and tokens[i-j] == 'LOAD_LAMBDA'):
|
||||||
rule_pat = ('mklambda ::= %sload_closure LOAD_LAMBDA %%s%s' %
|
rule_pat = ('mklambda ::= %sload_closure LOAD_LAMBDA %%s%s' %
|
||||||
('pos_arg '* args_pos, opname))
|
('pos_arg '* args_pos, opname))
|
||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
@@ -893,7 +893,7 @@ class Python3Parser(PythonParser):
|
|||||||
"GET_ITER CALL_FUNCTION_1" % ('pos_arg '* args_pos, opname))
|
"GET_ITER CALL_FUNCTION_1" % ('pos_arg '* args_pos, opname))
|
||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
|
|
||||||
if is_pypy or (i > 2 and tokens[i-2] == 'LOAD_LAMBDA'):
|
if is_pypy or (i >= 2 and tokens[i-2] == 'LOAD_LAMBDA'):
|
||||||
rule_pat = ('mklambda ::= %s%sLOAD_LAMBDA %%s%s' %
|
rule_pat = ('mklambda ::= %s%sLOAD_LAMBDA %%s%s' %
|
||||||
(('pos_arg '* args_pos),
|
(('pos_arg '* args_pos),
|
||||||
('kwarg '* args_kw),
|
('kwarg '* args_kw),
|
||||||
@@ -916,14 +916,20 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
# FIXME: Fold test into add_make_function_rule
|
# FIXME: Fold test into add_make_function_rule
|
||||||
j = 1 if self.version < 3.3 else 2
|
j = 1 if self.version < 3.3 else 2
|
||||||
if is_pypy or (i > j and tokens[i-j] == 'LOAD_LAMBDA'):
|
if is_pypy or (i >= j and tokens[i-j] == 'LOAD_LAMBDA'):
|
||||||
rule_pat = ('mklambda ::= %s%sLOAD_LAMBDA %%s%s' %
|
rule_pat = ('mklambda ::= %s%sLOAD_LAMBDA %%s%s' %
|
||||||
(('pos_arg '* args_pos),
|
(('pos_arg '* args_pos),
|
||||||
('kwarg '* args_kw),
|
('kwarg '* args_kw),
|
||||||
opname))
|
opname))
|
||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
|
|
||||||
if seen_LOAD_LISTCOMP and has_get_iter_call_function1:
|
if (seen_LOAD_LISTCOMP and has_get_iter_call_function1 and
|
||||||
|
(is_pypy or (i >= j and tokens[i-j] == 'LOAD_LISTCOMP'))):
|
||||||
|
# In the tokens we saw:
|
||||||
|
# LOAD_LISTCOMP LOAD_CONST MAKE_FUNCTION (>= 3.3) or
|
||||||
|
# LOAD_LISTCOMP MAKE_FUNCTION (< 3.3) or
|
||||||
|
# and have GET_ITER CALL_FUNCTION_1
|
||||||
|
# Todo: For Pypy we need to modify this slightly
|
||||||
rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr "
|
rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr "
|
||||||
"GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname))
|
"GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname))
|
||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
|
@@ -54,7 +54,6 @@ class Python32Parser(Python3Parser):
|
|||||||
list_compr ::= BUILD_LIST_0 list_iter
|
list_compr ::= BUILD_LIST_0 list_iter
|
||||||
lc_body ::= expr LIST_APPEND
|
lc_body ::= expr LIST_APPEND
|
||||||
|
|
||||||
kvlist ::= kvlist kv3
|
|
||||||
kv3 ::= expr expr STORE_MAP
|
kv3 ::= expr expr STORE_MAP
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
@@ -24,7 +24,6 @@ class Python33Parser(Python32Parser):
|
|||||||
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||||
try_middle
|
try_middle
|
||||||
jump_excepts come_from_except_clauses
|
jump_excepts come_from_except_clauses
|
||||||
mapexpr ::= BUILD_MAP kvlist
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def add_custom_rules(self, tokens, customize):
|
def add_custom_rules(self, tokens, customize):
|
||||||
|
Reference in New Issue
Block a user