[pypy-svn] r28782 - in pypy/dist/pypy/interpreter/pyparser: . test/samples

mwh at codespeak.net mwh at codespeak.net
Wed Jun 14 18:51:46 CEST 2006


Author: mwh
Date: Wed Jun 14 18:51:44 2006
New Revision: 28782

Modified:
   pypy/dist/pypy/interpreter/pyparser/astbuilder.py
   pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_list_comps.py
Log:
fix + test for problem with list comps like "[x for x in 1,2]".
even tested in a pypy-c! :)


Modified: pypy/dist/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/astbuilder.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/astbuilder.py	Wed Jun 14 18:51:44 2006
@@ -246,9 +246,21 @@
             index += 1 # skip 'for'
             ass_node = to_lvalue(tokens[index], consts.OP_ASSIGN)
             index += 2 # skip 'in'
-            iterable = tokens[index]
+            iterables = [tokens[index]]
             index += 1
             while index < len(tokens):
+                tok2 = tokens[index]
+                if not isinstance(tok2, TokenObject):
+                    break
+                if tok2.name != tok.COMMA:
+                    break
+                iterables.append(tokens[index+1])
+                index += 2
+            if len(iterables) == 1:
+                iterable = iterables[0]
+            else:
+                iterable = ast.Tuple(iterables, token.lineno)
+            while index < len(tokens):
                 token = tokens[index]
                 assert isinstance(token, TokenObject) # rtyper info
                 if token.get_value() == 'if':

Modified: pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_list_comps.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_list_comps.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_list_comps.py	Wed Jun 14 18:51:44 2006
@@ -2,3 +2,5 @@
 # same list on several lines
 [i for i in range(10)
  if i%2 == 0]
+[i for i in 1,2]
+[(i,j) for i in 1,2 for j in 3,4]



More information about the Pypy-commit mailing list