list_compr -> list_comp to match AST...

more Python 3 custom rule cleanup
This commit is contained in:
rocky
2017-11-29 21:26:31 -05:00
parent 6fee7fdfe3
commit fcdea73b4f
10 changed files with 20 additions and 32 deletions

View File

@@ -403,7 +403,7 @@ class PythonParser(GenericASTBuilder):
def p_list_comprehension(self, args): def p_list_comprehension(self, args):
""" """
expr ::= list_compr expr ::= list_comp
list_iter ::= list_for list_iter ::= list_for
list_iter ::= list_if list_iter ::= list_if

View File

@@ -253,8 +253,8 @@ class Python2Parser(PythonParser):
stmt ::= assign2_pypy stmt ::= assign2_pypy
assign3_pypy ::= expr expr expr store store store assign3_pypy ::= expr expr expr store store store
assign2_pypy ::= expr expr store store assign2_pypy ::= expr expr store store
list_compr ::= expr BUILD_LIST_FROM_ARG _for store list_iter list_comp ::= expr BUILD_LIST_FROM_ARG _for store list_iter
JUMP_BACK JUMP_BACK
""", nop_func) """, nop_func)
for i, token in enumerate(tokens): for i, token in enumerate(tokens):
opname = token.kind opname = token.kind

View File

@@ -35,7 +35,7 @@ class Python23Parser(Python24Parser):
while1stmt ::= _while1test l_stmts_opt JUMP_BACK while1stmt ::= _while1test l_stmts_opt JUMP_BACK
COME_FROM POP_TOP POP_BLOCK COME_FROM COME_FROM POP_TOP POP_BLOCK COME_FROM
list_compr ::= BUILD_LIST_0 DUP_TOP LOAD_ATTR store list_iter del_stmt list_comp ::= BUILD_LIST_0 DUP_TOP LOAD_ATTR store list_iter del_stmt
list_for ::= expr _for store list_iter JUMP_BACK come_froms POP_TOP JUMP_BACK list_for ::= expr _for store list_iter JUMP_BACK come_froms POP_TOP JUMP_BACK
lc_body ::= LOAD_NAME expr CALL_FUNCTION_1 POP_TOP lc_body ::= LOAD_NAME expr CALL_FUNCTION_1 POP_TOP

View File

@@ -195,9 +195,9 @@ class Python26Parser(Python2Parser):
list_iter ::= list_if JUMP_BACK list_iter ::= list_if JUMP_BACK
list_iter ::= list_if JUMP_BACK COME_FROM POP_TOP list_iter ::= list_if JUMP_BACK COME_FROM POP_TOP
list_compr ::= BUILD_LIST_0 DUP_TOP list_comp ::= BUILD_LIST_0 DUP_TOP
store list_iter del_stmt store list_iter del_stmt
list_compr ::= BUILD_LIST_0 DUP_TOP list_comp ::= BUILD_LIST_0 DUP_TOP
store list_iter JUMP_BACK del_stmt store list_iter JUMP_BACK del_stmt
lc_body ::= LOAD_NAME expr LIST_APPEND lc_body ::= LOAD_NAME expr LIST_APPEND
lc_body ::= LOAD_FAST expr LIST_APPEND lc_body ::= LOAD_FAST expr LIST_APPEND

View File

@@ -14,9 +14,9 @@ class Python27Parser(Python2Parser):
def p_comprehension27(self, args): def p_comprehension27(self, args):
""" """
list_for ::= expr _for store list_iter JUMP_BACK list_for ::= expr _for store list_iter JUMP_BACK
list_compr ::= BUILD_LIST_0 list_iter list_comp ::= BUILD_LIST_0 list_iter
lc_body ::= expr LIST_APPEND lc_body ::= expr LIST_APPEND
stmt ::= setcomp_func stmt ::= setcomp_func

View File

@@ -622,9 +622,6 @@ class Python3Parser(PythonParser):
""" """
is_pypy = False is_pypy = False
seen_LOAD_BUILD_CLASS = False seen_LOAD_BUILD_CLASS = False
seen_LOAD_DICTCOMP = False
seen_LOAD_LISTCOMP = False
seen_LOAD_SETCOMP = False
seen_GET_AWAITABLE_YIELD_FROM = False seen_GET_AWAITABLE_YIELD_FROM = False
# Loop over instructions adding custom grammar rules based on # Loop over instructions adding custom grammar rules based on
@@ -799,16 +796,11 @@ class Python3Parser(PythonParser):
opname, token.attr, customize) opname, token.attr, customize)
continue continue
elif opname == 'LOAD_DICTCOMP': elif opname == 'LOAD_DICTCOMP':
seen_LOAD_DICTCOMP = True
if has_get_iter_call_function1: if has_get_iter_call_function1:
rule_pat = ("dictcomp ::= LOAD_DICTCOMP %sMAKE_FUNCTION_0 expr " rule_pat = ("dictcomp ::= 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_LISTCOMP':
seen_LOAD_LISTCOMP = True
continue
elif opname == 'LOAD_SETCOMP': elif opname == 'LOAD_SETCOMP':
seen_LOAD_SETCOMP = True
# 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 ::= setcomp",

View File

@@ -51,10 +51,9 @@ class Python32Parser(Python3Parser):
stmt ::= del_deref_stmt stmt ::= del_deref_stmt
del_deref_stmt ::= DELETE_DEREF del_deref_stmt ::= DELETE_DEREF
list_compr ::= BUILD_LIST_0 list_iter list_comp ::= BUILD_LIST_0 list_iter
lc_body ::= expr LIST_APPEND lc_body ::= expr LIST_APPEND
kv3 ::= expr expr STORE_MAP
kv3 ::= expr expr STORE_MAP
""" """
pass pass

View File

@@ -156,7 +156,6 @@ TABLE_DIRECT = {
'unpack_list': ( '[%C]', (1, maxint, ', ') ), 'unpack_list': ( '[%C]', (1, maxint, ', ') ),
'build_tuple2': ( '%P', (0, -1, ', ', 100) ), 'build_tuple2': ( '%P', (0, -1, ', ', 100) ),
# 'list_compr': ( '[ %c ]', -2), # handled by n_list_compr
'list_iter': ( '%c', 0 ), 'list_iter': ( '%c', 0 ),
'list_for': ( ' for %c in %c%c', 2, 0, 3 ), 'list_for': ( ' for %c in %c%c', 2, 0, 3 ),
'list_if': ( ' if %c%c', 0, 2 ), 'list_if': ( ' if %c%c', 0, 2 ),
@@ -304,7 +303,7 @@ PRECEDENCE = {
'unary_convert': 0, 'unary_convert': 0,
'dictcomp': 0, 'dictcomp': 0,
'setcomp': 0, 'setcomp': 0,
'list_compr': 0, 'list_comp': 0,
'generator_exp': 0, 'generator_exp': 0,
'load_attr': 2, 'load_attr': 2,

View File

@@ -540,8 +540,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.indent_less() self.indent_less()
self.prune() # stop recursing self.prune() # stop recursing
def n_list_compr(self, node): def n_list_comp(self, node):
"""List comprehensions the way they are done in Python 2.""" """List comprehensions"""
p = self.prec p = self.prec
self.prec = 27 self.prec = 27
n = node[-1] n = node[-1]

View File

@@ -1060,14 +1060,13 @@ class SourceWalker(GenericASTTraversal, object):
self.make_function(node, is_lambda=True, codeNode=node[-2]) self.make_function(node, is_lambda=True, codeNode=node[-2])
self.prune() # stop recursing self.prune() # stop recursing
def n_list_compr(self, node): def n_list_comp(self, node):
"""List comprehensions the way they are done in Python 2. """List comprehensions"""
"""
p = self.prec p = self.prec
self.prec = 27 self.prec = 27
if self.version >= 2.7: if self.version >= 2.7:
if self.is_pypy: if self.is_pypy:
self.n_list_compr_pypy27(node) self.n_list_comp_pypy27(node)
return return
n = node[-1] n = node[-1]
elif node[-1] == 'del_stmt': elif node[-1] == 'del_stmt':
@@ -1112,9 +1111,8 @@ class SourceWalker(GenericASTTraversal, object):
self.prec = p self.prec = p
self.prune() # stop recursing self.prune() # stop recursing
def n_list_compr_pypy27(self, node): def n_list_comp_pypy27(self, node):
"""List comprehensions the way they are done in PYPY Python 2.7. """List comprehensions in PYPY."""
"""
p = self.prec p = self.prec
self.prec = 27 self.prec = 27
if node[-1].kind == 'list_iter': if node[-1].kind == 'list_iter':