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

ac at codespeak.net ac at codespeak.net
Wed Oct 5 11:55:19 CEST 2005


Author: ac
Date: Wed Oct  5 11:55:19 2005
New Revision: 18186

Modified:
   pypy/dist/pypy/interpreter/pyparser/astbuilder.py
   pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
Log:
Fix indexing with slices.

Modified: pypy/dist/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/astbuilder.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/astbuilder.py	Wed Oct  5 11:55:19 2005
@@ -913,12 +913,26 @@
             # push arglist on the stack
             builder.push(atoms[1])
     elif isinstance(first_token, TokenObject) and first_token.name == tok.LSQB:
-        if isinstance(atoms[1], SlicelistObject):
+        if len(atoms) == 3 and isinstance(atoms[1], SlicelistObject):
             builder.push(atoms[1])
         else:
             subs = []
             for index in range(1, len(atoms), 2):
-                subs.append(atoms[index])
+                atom = atoms[index]
+                if isinstance(atom, SlicelistObject):
+                    num_slicevals = 3
+                    slicevals = []
+                    if atom.fake_rulename == 'slice':
+                        num_slicevals = 2
+                    for val in atom.value[:num_slicevals]:
+                        if val is None:
+                            slicevals.append(ast.Const(builder.wrap_none(),
+                                                       atom.lineno))
+                        else:
+                            slicevals.append(val)
+                    subs.append(ast.Sliceobj(slicevals, atom.lineno))
+                else:
+                    subs.append(atom)
             builder.push(SubscriptObject('subscript', subs, first_token.lineno))
     elif len(atoms) == 2:
         # Attribute access: '.' NAME

Modified: pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py	Wed Oct  5 11:55:19 2005
@@ -267,6 +267,22 @@
     "a.b.l[1:]",
     "a.b.l[:2]",
     "a.b.l[0:1:2]",
+    "a[1:2:3, 100]",
+    "a[:2:3, 100]",
+    "a[1::3, 100]",
+    "a[1:2:, 100]",
+    "a[1:2, 100]",
+    "a[1:, 100]",
+    "a[:2, 100]",
+    "a[:, 100]",
+    "a[100, 1:2:3]",
+    "a[100, :2:3]",
+    "a[100, 1::3]",
+    "a[100, 1:2:]",
+    "a[100, 1:2]",
+    "a[100, 1:]",
+    "a[100, :2]",
+    "a[100, :]",
     ]
 
 imports = [



More information about the Pypy-commit mailing list