mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2024-11-23 21:20:06 +00:00
Reduce 3.x rules, esp. listcomp
This commit is contained in:
parent
acb4ffb758
commit
c4bfe38ee0
@ -25,9 +25,12 @@ def test_grammar():
|
||||
('store', 'DUP_TOP', 'designList'))])
|
||||
if PYTHON3:
|
||||
expect_lhs.add('load_genexpr')
|
||||
expect_lhs.add('kvlist')
|
||||
expect_lhs.add('kv3')
|
||||
|
||||
unused_rhs = unused_rhs.union(set("""
|
||||
except_pop_except generator_exp classdefdeco2 listcomp
|
||||
mapexpr
|
||||
""".split()))
|
||||
if 3.0 <= PYTHON_VERSION:
|
||||
expect_lhs.add("annotate_arg")
|
||||
|
@ -828,7 +828,7 @@ class Python3Parser(PythonParser):
|
||||
|
||||
# FIXME: Fold test into add_make_function_rule
|
||||
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' %
|
||||
('pos_arg '* args_pos, opname))
|
||||
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))
|
||||
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' %
|
||||
(('pos_arg '* args_pos),
|
||||
('kwarg '* args_kw),
|
||||
@ -916,14 +916,20 @@ class Python3Parser(PythonParser):
|
||||
|
||||
# FIXME: Fold test into add_make_function_rule
|
||||
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' %
|
||||
(('pos_arg '* args_pos),
|
||||
('kwarg '* args_kw),
|
||||
opname))
|
||||
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 "
|
||||
"GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname))
|
||||
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
|
||||
lc_body ::= expr LIST_APPEND
|
||||
|
||||
kvlist ::= kvlist kv3
|
||||
kv3 ::= expr expr STORE_MAP
|
||||
"""
|
||||
pass
|
||||
|
@ -24,7 +24,6 @@ class Python33Parser(Python32Parser):
|
||||
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||
try_middle
|
||||
jump_excepts come_from_except_clauses
|
||||
mapexpr ::= BUILD_MAP kvlist
|
||||
"""
|
||||
|
||||
def add_custom_rules(self, tokens, customize):
|
||||
|
Loading…
Reference in New Issue
Block a user