You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
NT dictcomp -> dict_comp to match AST
This commit is contained in:
@@ -389,7 +389,7 @@ class Python2Parser(PythonParser):
|
|||||||
prev_tok = tokens[i-1]
|
prev_tok = tokens[i-1]
|
||||||
if prev_tok == 'LOAD_DICTCOMP':
|
if prev_tok == 'LOAD_DICTCOMP':
|
||||||
self.add_unique_rules([
|
self.add_unique_rules([
|
||||||
('dictcomp ::= %s load_closure LOAD_DICTCOMP %s expr'
|
('dict_comp ::= %s load_closure LOAD_DICTCOMP %s expr'
|
||||||
' GET_ITER CALL_FUNCTION_1' %
|
' GET_ITER CALL_FUNCTION_1' %
|
||||||
('expr '*v, opname))], customize)
|
('expr '*v, opname))], customize)
|
||||||
elif prev_tok == 'LOAD_SETCOMP':
|
elif prev_tok == 'LOAD_SETCOMP':
|
||||||
|
@@ -21,12 +21,12 @@ class Python27Parser(Python2Parser):
|
|||||||
stmt ::= setcomp_func
|
stmt ::= setcomp_func
|
||||||
|
|
||||||
# Dictionary and set comprehensions were added in Python 2.7
|
# Dictionary and set comprehensions were added in Python 2.7
|
||||||
expr ::= dictcomp
|
expr ::= dict_comp
|
||||||
stmt ::= dictcomp_func
|
dict_comp ::= LOAD_DICTCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1
|
||||||
dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
|
|
||||||
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
|
|
||||||
|
|
||||||
dictcomp ::= LOAD_DICTCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1
|
stmt ::= dictcomp_func
|
||||||
|
dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
|
||||||
|
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
|
||||||
|
|
||||||
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
|
setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter
|
||||||
JUMP_BACK RETURN_VALUE RETURN_LAST
|
JUMP_BACK RETURN_VALUE RETURN_LAST
|
||||||
|
@@ -71,11 +71,12 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
def p_dictcomp3(self, args):
|
def p_dictcomp3(self, args):
|
||||||
""""
|
""""
|
||||||
expr ::= dictcomp
|
expr ::= dict_comp
|
||||||
stmt ::= dictcomp_func
|
stmt ::= dictcomp_func
|
||||||
dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
|
dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
|
||||||
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
|
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
|
||||||
dictcomp ::= LOAD_DICTCOMP LOAD_CONST MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1
|
dict_comp ::= LOAD_DICTCOMP LOAD_CONST MAKE_FUNCTION_0 expr
|
||||||
|
GET_ITER CALL_FUNCTION_1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_grammar(self, args):
|
def p_grammar(self, args):
|
||||||
@@ -409,7 +410,7 @@ class Python3Parser(PythonParser):
|
|||||||
load_genexpr ::= BUILD_TUPLE_1 LOAD_GENEXPR LOAD_CONST
|
load_genexpr ::= BUILD_TUPLE_1 LOAD_GENEXPR LOAD_CONST
|
||||||
|
|
||||||
# Is there something general going on here?
|
# Is there something general going on here?
|
||||||
dictcomp ::= load_closure LOAD_DICTCOMP LOAD_CONST MAKE_CLOSURE_0 expr GET_ITER CALL_FUNCTION_1
|
dict_comp ::= load_closure LOAD_DICTCOMP LOAD_CONST MAKE_CLOSURE_0 expr GET_ITER CALL_FUNCTION_1
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def p_expr3(self, args):
|
def p_expr3(self, args):
|
||||||
@@ -588,8 +589,8 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
# Is there something more general than this? adding pos_arg?
|
# Is there something more general than this? adding pos_arg?
|
||||||
# Is there something corresponding using MAKE_CLOSURE?
|
# Is there something corresponding using MAKE_CLOSURE?
|
||||||
dictcomp ::= LOAD_DICTCOMP [LOAD_CONST] MAKE_FUNCTION_0 expr
|
dict_comp ::= LOAD_DICTCOMP [LOAD_CONST] MAKE_FUNCTION_0 expr
|
||||||
GET_ITER CALL_FUNCTION_1
|
GET_ITER CALL_FUNCTION_1
|
||||||
|
|
||||||
generator_exp ::= {pos_arg}^n load_genexpr [LOAD_CONST] MAKE_FUNCTION_n expr
|
generator_exp ::= {pos_arg}^n load_genexpr [LOAD_CONST] MAKE_FUNCTION_n expr
|
||||||
GET_ITER CALL_FUNCTION_1
|
GET_ITER CALL_FUNCTION_1
|
||||||
@@ -797,7 +798,7 @@ class Python3Parser(PythonParser):
|
|||||||
continue
|
continue
|
||||||
elif opname == 'LOAD_DICTCOMP':
|
elif opname == 'LOAD_DICTCOMP':
|
||||||
if has_get_iter_call_function1:
|
if has_get_iter_call_function1:
|
||||||
rule_pat = ("dictcomp ::= LOAD_DICTCOMP %sMAKE_FUNCTION_0 expr "
|
rule_pat = ("dict_comp ::= LOAD_DICTCOMP %sMAKE_FUNCTION_0 expr "
|
||||||
"GET_ITER CALL_FUNCTION_1")
|
"GET_ITER CALL_FUNCTION_1")
|
||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
elif opname == 'LOAD_SETCOMP':
|
elif opname == 'LOAD_SETCOMP':
|
||||||
@@ -845,7 +846,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 >= j and tokens[i-j] == 'LOAD_DICTCOMP')):
|
if (is_pypy or (i >= j and tokens[i-j] == 'LOAD_DICTCOMP')):
|
||||||
self.add_unique_rule('dictcomp ::= %sload_closure LOAD_DICTCOMP %s '
|
self.add_unique_rule('dict_comp ::= %sload_closure LOAD_DICTCOMP %s '
|
||||||
'expr GET_ITER CALL_FUNCTION_1' %
|
'expr GET_ITER CALL_FUNCTION_1' %
|
||||||
('pos_arg '* args_pos, opname),
|
('pos_arg '* args_pos, opname),
|
||||||
opname, token.attr, customize)
|
opname, token.attr, customize)
|
||||||
|
@@ -36,7 +36,7 @@ class Python35Parser(Python34Parser):
|
|||||||
expr ::= unmap_dict
|
expr ::= unmap_dict
|
||||||
expr ::= unmapexpr
|
expr ::= unmapexpr
|
||||||
|
|
||||||
unmap_dict ::= dictcomp BUILD_MAP_UNPACK
|
unmap_dict ::= dict_comp BUILD_MAP_UNPACK
|
||||||
|
|
||||||
unmap_dict ::= kv_lists BUILD_MAP_UNPACK
|
unmap_dict ::= kv_lists BUILD_MAP_UNPACK
|
||||||
kv_lists ::= kv_list kv_lists
|
kv_lists ::= kv_list kv_lists
|
||||||
|
@@ -301,7 +301,7 @@ PRECEDENCE = {
|
|||||||
'build_list': 0,
|
'build_list': 0,
|
||||||
'mapexpr': 0,
|
'mapexpr': 0,
|
||||||
'unary_convert': 0,
|
'unary_convert': 0,
|
||||||
'dictcomp': 0,
|
'dict_comp': 0,
|
||||||
'set_comp': 0,
|
'set_comp': 0,
|
||||||
'list_comp': 0,
|
'list_comp': 0,
|
||||||
'generator_exp': 0,
|
'generator_exp': 0,
|
||||||
|
@@ -568,7 +568,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
self.prec = 27
|
self.prec = 27
|
||||||
|
|
||||||
# FIXME: clean this up
|
# FIXME: clean this up
|
||||||
if self.version > 3.0 and node == 'dictcomp':
|
if self.version > 3.0 and node == 'dict_comp':
|
||||||
cn = node[1]
|
cn = node[1]
|
||||||
elif self.version > 3.0 and node == 'generator_exp':
|
elif self.version > 3.0 and node == 'generator_exp':
|
||||||
if node[0] == 'load_genexpr':
|
if node[0] == 'load_genexpr':
|
||||||
@@ -793,7 +793,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||||
self.prune()
|
self.prune()
|
||||||
|
|
||||||
# FIXME: Not sure if below is general. Also, add dictcomp_func.
|
# FIXME: Not sure if below is general. Also, add dict_comp_func.
|
||||||
# 'setcomp_func': ("%|lambda %c: {%c for %c in %c%c}\n", 1, 3, 3, 1, 4)
|
# 'setcomp_func': ("%|lambda %c: {%c for %c in %c%c}\n", 1, 3, 3, 1, 4)
|
||||||
def n_setcomp_func(self, node):
|
def n_setcomp_func(self, node):
|
||||||
setcomp_start = len(self.f.getvalue())
|
setcomp_start = len(self.f.getvalue())
|
||||||
|
@@ -1157,7 +1157,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
self.prec = 27
|
self.prec = 27
|
||||||
|
|
||||||
# FIXME: clean this up
|
# FIXME: clean this up
|
||||||
if self.version > 3.0 and node == 'dictcomp':
|
if self.version > 3.0 and node == 'dict_comp':
|
||||||
cn = node[1]
|
cn = node[1]
|
||||||
elif self.version < 2.7 and node == 'generator_exp':
|
elif self.version < 2.7 and node == 'generator_exp':
|
||||||
if node[0] == 'LOAD_GENEXPR':
|
if node[0] == 'LOAD_GENEXPR':
|
||||||
@@ -1375,7 +1375,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
self.write(']')
|
self.write(']')
|
||||||
self.prune()
|
self.prune()
|
||||||
|
|
||||||
n_dictcomp = n_set_comp
|
n_dict_comp = n_set_comp
|
||||||
|
|
||||||
def setcomprehension_walk3(self, node, collection_index):
|
def setcomprehension_walk3(self, node, collection_index):
|
||||||
"""List comprehensions the way they are done in Python3.
|
"""List comprehensions the way they are done in Python3.
|
||||||
|
Reference in New Issue
Block a user