NT dictcomp -> dict_comp to match AST

This commit is contained in:
rocky 2017-11-30 08:50:00 -05:00
parent 0b284f8230
commit ac4d4d1da9
7 changed files with 20 additions and 19 deletions

View File

@ -389,7 +389,7 @@ class Python2Parser(PythonParser):
prev_tok = tokens[i-1]
if prev_tok == 'LOAD_DICTCOMP':
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' %
('expr '*v, opname))], customize)
elif prev_tok == 'LOAD_SETCOMP':

View File

@ -21,12 +21,12 @@ class Python27Parser(Python2Parser):
stmt ::= setcomp_func
# Dictionary and set comprehensions were added in Python 2.7
expr ::= dictcomp
stmt ::= dictcomp_func
dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
expr ::= dict_comp
dict_comp ::= LOAD_DICTCOMP MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1
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
JUMP_BACK RETURN_VALUE RETURN_LAST

View File

@ -71,11 +71,12 @@ class Python3Parser(PythonParser):
def p_dictcomp3(self, args):
""""
expr ::= dictcomp
expr ::= dict_comp
stmt ::= dictcomp_func
dictcomp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store
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):
@ -409,7 +410,7 @@ class Python3Parser(PythonParser):
load_genexpr ::= BUILD_TUPLE_1 LOAD_GENEXPR LOAD_CONST
# 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):
@ -588,8 +589,8 @@ class Python3Parser(PythonParser):
# Is there something more general than this? adding pos_arg?
# Is there something corresponding using MAKE_CLOSURE?
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
generator_exp ::= {pos_arg}^n load_genexpr [LOAD_CONST] MAKE_FUNCTION_n expr
GET_ITER CALL_FUNCTION_1
@ -797,7 +798,7 @@ class Python3Parser(PythonParser):
continue
elif opname == 'LOAD_DICTCOMP':
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")
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
elif opname == 'LOAD_SETCOMP':
@ -845,7 +846,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_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' %
('pos_arg '* args_pos, opname),
opname, token.attr, customize)

View File

@ -36,7 +36,7 @@ class Python35Parser(Python34Parser):
expr ::= unmap_dict
expr ::= unmapexpr
unmap_dict ::= dictcomp BUILD_MAP_UNPACK
unmap_dict ::= dict_comp BUILD_MAP_UNPACK
unmap_dict ::= kv_lists BUILD_MAP_UNPACK
kv_lists ::= kv_list kv_lists

View File

@ -301,7 +301,7 @@ PRECEDENCE = {
'build_list': 0,
'mapexpr': 0,
'unary_convert': 0,
'dictcomp': 0,
'dict_comp': 0,
'set_comp': 0,
'list_comp': 0,
'generator_exp': 0,

View File

@ -568,7 +568,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.prec = 27
# FIXME: clean this up
if self.version > 3.0 and node == 'dictcomp':
if self.version > 3.0 and node == 'dict_comp':
cn = node[1]
elif self.version > 3.0 and node == 'generator_exp':
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.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)
def n_setcomp_func(self, node):
setcomp_start = len(self.f.getvalue())

View File

@ -1157,7 +1157,7 @@ class SourceWalker(GenericASTTraversal, object):
self.prec = 27
# FIXME: clean this up
if self.version > 3.0 and node == 'dictcomp':
if self.version > 3.0 and node == 'dict_comp':
cn = node[1]
elif self.version < 2.7 and node == 'generator_exp':
if node[0] == 'LOAD_GENEXPR':
@ -1375,7 +1375,7 @@ class SourceWalker(GenericASTTraversal, object):
self.write(']')
self.prune()
n_dictcomp = n_set_comp
n_dict_comp = n_set_comp
def setcomprehension_walk3(self, node, collection_index):
"""List comprehensions the way they are done in Python3.