NT setcomp -> set_comp to match AST

This commit is contained in:
rocky
2017-11-30 07:14:29 -05:00
parent fcdea73b4f
commit 0b284f8230
6 changed files with 16 additions and 16 deletions

View File

@@ -414,7 +414,7 @@ class PythonParser(GenericASTBuilder):
list_if_not ::= expr jmp_true list_iter 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_for
comp_iter ::= comp_body comp_iter ::= comp_body

View File

@@ -353,8 +353,8 @@ class Python2Parser(PythonParser):
continue continue
elif opname == 'LOAD_SETCOMP': elif opname == 'LOAD_SETCOMP':
self.add_unique_rules([ self.add_unique_rules([
"expr ::= setcomp", "expr ::= set_comp",
"setcomp ::= LOAD_SETCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1" "set_comp ::= LOAD_SETCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1"
], customize) ], customize)
continue continue
elif opname == 'LOOKUP_METHOD': elif opname == 'LOOKUP_METHOD':
@@ -394,8 +394,8 @@ class Python2Parser(PythonParser):
('expr '*v, opname))], customize) ('expr '*v, opname))], customize)
elif prev_tok == 'LOAD_SETCOMP': elif prev_tok == 'LOAD_SETCOMP':
self.add_unique_rules([ self.add_unique_rules([
"expr ::= setcomp", "expr ::= set_comp",
('setcomp ::= %s load_closure LOAD_SETCOMP %s expr' ('set_comp ::= %s load_closure LOAD_SETCOMP %s expr'
' GET_ITER CALL_FUNCTION_1' % ' GET_ITER CALL_FUNCTION_1' %
('expr '*v, opname)) ('expr '*v, opname))
], customize) ], customize)

View File

@@ -603,12 +603,12 @@ 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?
For example: 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 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 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 MAKE_CLOSURE_n expr GET_ITER CALL_FUNCTION_1
mkfunc ::= {pos_arg}^n load_closure [LOAD_CONST] MAKE_FUNCTION_n mkfunc ::= {pos_arg}^n load_closure [LOAD_CONST] MAKE_FUNCTION_n
@@ -803,9 +803,9 @@ class Python3Parser(PythonParser):
elif opname == 'LOAD_SETCOMP': elif opname == 'LOAD_SETCOMP':
# Should this be generalized and put under MAKE_FUNCTION? # Should this be generalized and put under MAKE_FUNCTION?
if has_get_iter_call_function1: if has_get_iter_call_function1:
self.add_unique_rule("expr ::= setcomp", self.add_unique_rule("expr ::= set_comp",
opname, token.attr, customize) 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") "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 == 'LOOKUP_METHOD': elif opname == 'LOOKUP_METHOD':
@@ -841,7 +841,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_SETCOMP')): 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)) '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')):

View File

@@ -302,7 +302,7 @@ PRECEDENCE = {
'mapexpr': 0, 'mapexpr': 0,
'unary_convert': 0, 'unary_convert': 0,
'dictcomp': 0, 'dictcomp': 0,
'setcomp': 0, 'set_comp': 0,
'list_comp': 0, 'list_comp': 0,
'generator_exp': 0, 'generator_exp': 0,

View File

@@ -778,7 +778,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()
def n_setcomp(self, node): def n_set_comp(self, node):
start = len(self.f.getvalue()) start = len(self.f.getvalue())
self.write('{') self.write('{')
if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']: if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']:

View File

@@ -1226,7 +1226,7 @@ class SourceWalker(GenericASTTraversal, object):
self.write(')') self.write(')')
self.prune() self.prune()
def n_setcomp(self, node): def n_set_comp(self, node):
self.write('{') self.write('{')
if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']: if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']:
self.comprehension_walk3(node, 1, 0) self.comprehension_walk3(node, 1, 0)
@@ -1329,7 +1329,7 @@ class SourceWalker(GenericASTTraversal, object):
code = Code(node[1].attr, self.scanner, self.currentclass) code = Code(node[1].attr, self.scanner, self.currentclass)
ast = self.build_ast(code._tokens, code._customize) ast = self.build_ast(code._tokens, code._customize)
self.customize(code._customize) self.customize(code._customize)
if node == 'setcomp': if node == 'set_comp':
ast = ast[0][0][0] ast = ast[0][0][0]
else: else:
ast = ast[0][0][0][0][0] ast = ast[0][0][0][0][0]
@@ -1375,7 +1375,7 @@ class SourceWalker(GenericASTTraversal, object):
self.write(']') self.write(']')
self.prune() self.prune()
n_dictcomp = n_setcomp n_dictcomp = 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.