mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2024-11-23 21:20:06 +00:00
NT setcomp -> set_comp to match AST
This commit is contained in:
parent
fcdea73b4f
commit
0b284f8230
@ -414,7 +414,7 @@ class PythonParser(GenericASTBuilder):
|
||||
list_if_not ::= expr jmp_true list_iter
|
||||
"""
|
||||
|
||||
def p_setcomp(self, args):
|
||||
def p_set_comp(self, args):
|
||||
"""
|
||||
comp_iter ::= comp_for
|
||||
comp_iter ::= comp_body
|
||||
|
@ -353,8 +353,8 @@ class Python2Parser(PythonParser):
|
||||
continue
|
||||
elif opname == 'LOAD_SETCOMP':
|
||||
self.add_unique_rules([
|
||||
"expr ::= setcomp",
|
||||
"setcomp ::= LOAD_SETCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1"
|
||||
"expr ::= set_comp",
|
||||
"set_comp ::= LOAD_SETCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1"
|
||||
], customize)
|
||||
continue
|
||||
elif opname == 'LOOKUP_METHOD':
|
||||
@ -394,8 +394,8 @@ class Python2Parser(PythonParser):
|
||||
('expr '*v, opname))], customize)
|
||||
elif prev_tok == 'LOAD_SETCOMP':
|
||||
self.add_unique_rules([
|
||||
"expr ::= setcomp",
|
||||
('setcomp ::= %s load_closure LOAD_SETCOMP %s expr'
|
||||
"expr ::= set_comp",
|
||||
('set_comp ::= %s load_closure LOAD_SETCOMP %s expr'
|
||||
' GET_ITER CALL_FUNCTION_1' %
|
||||
('expr '*v, opname))
|
||||
], customize)
|
||||
|
@ -603,12 +603,12 @@ class Python3Parser(PythonParser):
|
||||
# Is there something more general than this? adding pos_arg?
|
||||
# Is there something corresponding using MAKE_CLOSURE?
|
||||
For example:
|
||||
# setcomp ::= {pos_arg}^n LOAD_SETCOMP [LOAD_CONST] MAKE_CLOSURE_n
|
||||
# set_comp ::= {pos_arg}^n LOAD_SETCOMP [LOAD_CONST] MAKE_CLOSURE_n
|
||||
GET_ITER CALL_FUNCTION_1
|
||||
|
||||
setcomp ::= LOAD_SETCOMP [LOAD_CONST] MAKE_FUNCTION_0 expr
|
||||
set_comp ::= LOAD_SETCOMP [LOAD_CONST] MAKE_FUNCTION_0 expr
|
||||
GET_ITER CALL_FUNCTION_1
|
||||
setcomp ::= {pos_arg}^n load_closure LOAD_SETCOMP [LOAD_CONST]
|
||||
set_comp ::= {pos_arg}^n load_closure LOAD_SETCOMP [LOAD_CONST]
|
||||
MAKE_CLOSURE_n expr GET_ITER CALL_FUNCTION_1
|
||||
|
||||
mkfunc ::= {pos_arg}^n load_closure [LOAD_CONST] MAKE_FUNCTION_n
|
||||
@ -803,9 +803,9 @@ class Python3Parser(PythonParser):
|
||||
elif opname == 'LOAD_SETCOMP':
|
||||
# Should this be generalized and put under MAKE_FUNCTION?
|
||||
if has_get_iter_call_function1:
|
||||
self.add_unique_rule("expr ::= setcomp",
|
||||
self.add_unique_rule("expr ::= set_comp",
|
||||
opname, token.attr, customize)
|
||||
rule_pat = ("setcomp ::= LOAD_SETCOMP %sMAKE_FUNCTION_0 expr "
|
||||
rule_pat = ("set_comp ::= LOAD_SETCOMP %sMAKE_FUNCTION_0 expr "
|
||||
"GET_ITER CALL_FUNCTION_1")
|
||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||
elif opname == 'LOOKUP_METHOD':
|
||||
@ -841,7 +841,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 >= j and tokens[i-j] == 'LOAD_SETCOMP')):
|
||||
rule_pat = ('setcomp ::= %sload_closure LOAD_SETCOMP %%s%s expr '
|
||||
rule_pat = ('set_comp ::= %sload_closure LOAD_SETCOMP %%s%s expr '
|
||||
'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 >= j and tokens[i-j] == 'LOAD_DICTCOMP')):
|
||||
|
@ -302,7 +302,7 @@ PRECEDENCE = {
|
||||
'mapexpr': 0,
|
||||
'unary_convert': 0,
|
||||
'dictcomp': 0,
|
||||
'setcomp': 0,
|
||||
'set_comp': 0,
|
||||
'list_comp': 0,
|
||||
'generator_exp': 0,
|
||||
|
||||
|
@ -778,7 +778,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||
self.prune()
|
||||
|
||||
def n_setcomp(self, node):
|
||||
def n_set_comp(self, node):
|
||||
start = len(self.f.getvalue())
|
||||
self.write('{')
|
||||
if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']:
|
||||
|
@ -1226,7 +1226,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.write(')')
|
||||
self.prune()
|
||||
|
||||
def n_setcomp(self, node):
|
||||
def n_set_comp(self, node):
|
||||
self.write('{')
|
||||
if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']:
|
||||
self.comprehension_walk3(node, 1, 0)
|
||||
@ -1329,7 +1329,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
code = Code(node[1].attr, self.scanner, self.currentclass)
|
||||
ast = self.build_ast(code._tokens, code._customize)
|
||||
self.customize(code._customize)
|
||||
if node == 'setcomp':
|
||||
if node == 'set_comp':
|
||||
ast = ast[0][0][0]
|
||||
else:
|
||||
ast = ast[0][0][0][0][0]
|
||||
@ -1375,7 +1375,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.write(']')
|
||||
self.prune()
|
||||
|
||||
n_dictcomp = n_setcomp
|
||||
n_dictcomp = n_set_comp
|
||||
|
||||
def setcomprehension_walk3(self, node, collection_index):
|
||||
"""List comprehensions the way they are done in Python3.
|
||||
|
Loading…
Reference in New Issue
Block a user