2.6.9 list comprehension

This commit is contained in:
rocky
2016-06-30 06:51:20 -04:00
parent da9aeecc60
commit 73a043830c
4 changed files with 12 additions and 5 deletions

Binary file not shown.

View File

@@ -0,0 +1,2 @@
# Python 2.6 uses SETUP_LOOP while 2.7 doesn't
(e for s in (self, other) for e in s)

View File

@@ -134,6 +134,9 @@ class Python26Parser(Python2Parser):
lc_body ::= LOAD_NAME expr LIST_APPEND
lc_body ::= LOAD_FAST expr LIST_APPEND
comp_for ::= SETUP_LOOP expr _for designator comp_iter JUMP_BACK POP_BLOCK COME_FROM
# Make sure we keep indices the same as 2.7
setup_loop_lf ::= SETUP_LOOP LOAD_FAST
genexpr_func ::= setup_loop_lf FOR_ITER designator comp_iter JUMP_BACK POP_BLOCK COME_FROM

View File

@@ -1078,15 +1078,17 @@ class SourceWalker(GenericASTTraversal, object):
ast = ast[0][0][0]
n = ast[iter_index]
assert n == 'comp_iter'
assert n == 'comp_iter', n
# find innermost node
while n == 'comp_iter': # list_iter
n = n[0] # recurse one step
if n == 'comp_for': n = n[3]
if n == 'comp_for':
n = n[4] if n[0] == 'SETUP_LOOP' else n[3]
elif n == 'comp_if': n = n[2]
elif n == 'comp_ifnot': n = n[2]
assert n == 'comp_body', ast
assert n == 'comp_body', n
self.preorder(n[0])
self.write(' for ')
@@ -1124,7 +1126,7 @@ class SourceWalker(GenericASTTraversal, object):
self.prec = 27
code = node[code_index].attr
assert iscode(code)
assert iscode(code), node[code_index]
code = Code(code, self.scanner, self.currentclass)
ast = self.build_ast(code._tokens, code._customize)
@@ -1144,7 +1146,7 @@ class SourceWalker(GenericASTTraversal, object):
else:
ast = ast[0][0]
n = ast[iter_index]
assert n == 'list_iter'
assert n == 'list_iter', n
## FIXME: I'm not totally sure this is right.