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

adim at codespeak.net adim at codespeak.net
Tue Aug 9 14:27:10 CEST 2005


Author: adim
Date: Tue Aug  9 14:27:07 2005
New Revision: 15811

Modified:
   pypy/dist/pypy/interpreter/pyparser/astbuilder.py
   pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_simple_for_loop.py
   pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
Log:
implemented for stmts (+break and pass)

Modified: pypy/dist/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/astbuilder.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/astbuilder.py	Tue Aug  9 14:27:07 2005
@@ -482,6 +482,36 @@
             break # break is not necessary
     builder.push(ast.If(tests, else_))
 
+def build_pass_stmt(builder, nb):
+    """past_stmt: 'pass'"""
+    L = get_atoms(builder, nb)
+    assert len(L) == 1
+    builder.push(ast.Pass())
+
+
+def build_break_stmt(builder, nb):
+    """past_stmt: 'pass'"""
+    L = get_atoms(builder, nb)
+    assert len(L) == 1
+    builder.push(ast.Break())
+
+
+def build_for_stmt(builder, nb):
+    """for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]"""
+    L = get_atoms(builder, nb)
+    else_ = None
+    # skip 'for'
+    assign = to_lvalue(L[1], consts.OP_ASSIGN)
+    # skip 'in'
+    iterable = L[3]
+    # skip ':'
+    body = L[5]
+    # if there is a "else" statement
+    if len(L) > 6:
+        # skip 'else' and ':'
+        else_ = L[8]
+    builder.push(ast.For(assign, iterable, body, else_))
+
 
 def parse_argument(tokens):
     """parses function call arguments"""
@@ -660,6 +690,9 @@
     sym.return_stmt : build_return_stmt,
     sym.suite : build_suite,
     sym.if_stmt : build_if_stmt,
+    sym.pass_stmt : build_pass_stmt,
+    sym.break_stmt : build_break_stmt,
+    sym.for_stmt : build_for_stmt,
     # sym.parameters : build_parameters,
     }
 

Modified: pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_simple_for_loop.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_simple_for_loop.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/test/samples/snippet_simple_for_loop.py	Tue Aug  9 14:27:07 2005
@@ -1,3 +1,11 @@
 for x in range(10):
    pass
 
+for x in range(5):
+   a += x
+   b += 2
+   if False:
+      break
+else:
+   c = 3
+

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	Tue Aug  9 14:27:07 2005
@@ -182,6 +182,7 @@
     'snippet_1.py',
     'snippet_several_statements.py',
     'snippet_simple_function.py',
+    'snippet_simple_for_loop.py',
 #    'snippet_2.py',
 #    'snippet_3.py',
 #    'snippet_4.py',
@@ -200,7 +201,6 @@
 #    'snippet_samples.py',
 #    'snippet_simple_assignment.py',
 #    'snippet_simple_class.py',
-#    'snippet_simple_for_loop.py',
 #    'snippet_simple_in_expr.py',
 #    'snippet_slice.py',
 #    'snippet_whitespaces.py',



More information about the Pypy-commit mailing list