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

adim at codespeak.net adim at codespeak.net
Wed Aug 10 11:17:06 CEST 2005


Author: adim
Date: Wed Aug 10 11:17:03 2005
New Revision: 15901

Added:
   pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_classes.py
Modified:
   pypy/dist/pypy/interpreter/pyparser/astbuilder.py
   pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
Log:
implemented class statements

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 11:17:03 2005
@@ -442,7 +442,26 @@
     code = L[-1]
     # FIXME: decorators and docstring !
     builder.push(ast.Function(None, funcname, names, default, flags, None, code))
-        
+
+
+def build_classdef(builder, nb):
+    """classdef: 'class' NAME ['(' testlist ')'] ':' suite"""
+    L = get_atoms(builder, nb)
+    l = len(L)
+    # FIXME: docstring
+    classname = L[1].value
+    if l == 4:
+        basenames = []
+        body = L[3]
+    elif l == 7:
+        basenames = []
+        body = L[6]
+        base = L[3]
+        assert isinstance(base, ast.Tuple)
+        for node in base.nodes:
+            assert isinstance(node, ast.Name)
+            basenames.append(node)
+    builder.push(ast.Class(classname, basenames, None, body))
 
 def build_suite(builder, nb):
     """suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT"""
@@ -929,6 +948,7 @@
     sym.arglist : build_arglist,
     sym.listmaker : build_listmaker,
     sym.funcdef : build_funcdef,
+    sym.classdef : build_classdef,
     sym.return_stmt : build_return_stmt,
     sym.suite : build_suite,
     sym.if_stmt : build_if_stmt,

Added: pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_classes.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_classes.py	Wed Aug 10 11:17:03 2005
@@ -0,0 +1,12 @@
+class A:
+    def with_white_spaces_before(self):
+        pass
+
+    def another_method(self, foo):
+        bar = foo
+
+
+class B(object, A):
+    def foo(self, bar):
+        a = 2
+        return "spam"

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 11:17:03 2005
@@ -323,6 +323,7 @@
     'snippet_import_statements.py',
     'snippet_generator.py',
     'snippet_exceptions.py',
+    'snippet_classes.py',
 #    'snippet_2.py',
 #    'snippet_3.py',
 #    'snippet_4.py',



More information about the Pypy-commit mailing list