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

adim at codespeak.net adim at codespeak.net
Wed Aug 10 14:45:24 CEST 2005


Author: adim
Date: Wed Aug 10 14:45:22 2005
New Revision: 15910

Modified:
   pypy/dist/pypy/interpreter/pyparser/astbuilder.py
   pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
Log:
make more tests pass 


Modified: pypy/dist/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/astbuilder.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/astbuilder.py	Wed Aug 10 14:45:22 2005
@@ -146,6 +146,23 @@
             builder.push(ast.Getattr(L[0], L[2].value))
         else:
             builder.push(ast.Power([L[0], L[2]]))
+    # FIXME: find a more general way to do this
+    elif isinstance(L[-1], ArglistObject):
+        # for an expression like 'a.b.c.append(3)', we want ['a', 'b', 'c']
+        names = []
+        for index in range(0, len(L)-1, 2):
+            names.append(L[index])
+        while len(names) > 1:
+            left = names.pop(0)
+            right = names.pop(0)
+            assert isinstance(right, TokenObject)
+            names.insert(0, ast.Getattr(left, right.value))
+        left = names[0]
+        arglist = L[-1]
+        assert isinstance(arglist, ArglistObject)
+        arguments, stararg, dstararg = arglist.value
+        builder.push(ast.CallFunc(left, arguments, stararg, dstararg))
+    # FIXME: isinstance(L[-1], (SubscriptObject, SliceObject))
     else:
         raise ValueError, "unexpected tokens: %s" % L
 
@@ -1004,13 +1021,14 @@
     if not isinstance(stmt, ast.Stmt):
         return None
     doc = None
-    first_child = stmt.nodes[0]
-    if isinstance(first_child, ast.Discard):
-        expr = first_child.expr
-        if isinstance(expr, ast.Const):
-            # This *is* a docstring, remove it from stmt list
-            del stmt.nodes[0]
-            doc = expr.value
+    if len(stmt.nodes):
+        first_child = stmt.nodes[0]
+        if isinstance(first_child, ast.Discard):
+            expr = first_child.expr
+            if isinstance(expr, ast.Const):
+                # This *is* a docstring, remove it from stmt list
+                del stmt.nodes[0]
+                doc = expr.value
     return doc
 
 ASTRULES = {

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 Aug 10 14:45:22 2005
@@ -38,6 +38,8 @@
     "l = func(10, 12, a, b=c, **kwargs)",
     "l = func(10, 12, a, b=c, *args, **kwargs)",
     "l = func(10, 12, a, b=c)",
+    "e = l.pop(3)",
+    "e = k.l.pop(3)",
     ]
 
 listmakers = [
@@ -351,26 +353,26 @@
     'snippet_exceptions.py',
     'snippet_classes.py',
     'snippet_simple_class.py',
-    'snippet_docstring.py'
-#    'snippet_2.py',
-#    'snippet_3.py',
-#    'snippet_4.py',
-#    'snippet_comment.py',
-#    'snippet_encoding_declaration2.py',
-#    'snippet_encoding_declaration3.py',
-#    'snippet_encoding_declaration.py',
-#    'snippet_function_calls.py',
-#    'snippet_import_statements.py',
-#    'snippet_list_comps.py',
-#    'snippet_multiline.py',
-#    'snippet_numbers.py',
-#    'snippet_only_one_comment.py',
-#    'snippet_redirected_prints.py',
+    'snippet_docstring.py',
+    'snippet_2.py',
+    'snippet_3.py',
+    'snippet_4.py',
+    'snippet_comment.py',
+    'snippet_encoding_declaration2.py',
+    'snippet_encoding_declaration3.py',
+    'snippet_encoding_declaration.py',
+    'snippet_function_calls.py',
+    'snippet_import_statements.py',
+    'snippet_list_comps.py',
+    'snippet_multiline.py',
+    'snippet_numbers.py',
+    'snippet_only_one_comment.py',
+    'snippet_redirected_prints.py',
+    'snippet_simple_assignment.py',
+    'snippet_simple_in_expr.py',
+    'snippet_slice.py',
+    'snippet_whitespaces.py',
 #    'snippet_samples.py',
-#    'snippet_simple_assignment.py',
-#    'snippet_simple_in_expr.py',
-#    'snippet_slice.py',
-#    'snippet_whitespaces.py',
     ]
 
 def test_snippets():



More information about the Pypy-commit mailing list