[pypy-svn] r15894 - in pypy/dist/pypy/interpreter/pyparser: . test
adim at codespeak.net
adim at codespeak.net
Wed Aug 10 09:02:28 CEST 2005
Author: adim
Date: Wed Aug 10 09:02:26 2005
New Revision: 15894
Modified:
pypy/dist/pypy/interpreter/pyparser/astbuilder.py
pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
Log:
implementecd prints/execs/asserts
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 09:02:26 2005
@@ -612,6 +612,50 @@
assert isinstance(L[1], ast.Name), "build_del_stmt implementation is incomplete !"
builder.push(ast.AssName(L[1].name, consts.OP_DELETE))
+def build_assert_stmt(builder, nb):
+ """assert_stmt: 'assert' test [',' test]"""
+ L = get_atoms(builder, nb)
+ test = L[1]
+ if len(L) == 4:
+ fail = L[3]
+ else:
+ fail = None
+ builder.push(ast.Assert(test, fail))
+
+def build_exec_stmt(builder, nb):
+ """exec_stmt: 'exec' expr ['in' test [',' test]]"""
+ L = get_atoms(builder, nb)
+ expr = L[1]
+ loc = None
+ glob = None
+ if len(L) > 2:
+ loc = L[3]
+ if len(L) > 4:
+ glob = L[5]
+ builder.push(ast.Exec(expr, loc, glob))
+
+def build_print_stmt(builder, nb):
+ """
+ print_stmt: 'print' ( '>>' test [ (',' test)+ [','] ] | [ test (',' test)* [','] ] )
+ """
+ L = get_atoms(builder, nb)
+ l = len(L)
+ items = []
+ dest = None
+ start = 1
+ if l > 1:
+ if isinstance(L[1], TokenObject) and L[1].name == tok.RIGHTSHIFT:
+ dest = L[2]
+ # skip following comma
+ start = 4
+ for index in range(start, l, 2):
+ items.append(L[index])
+ if isinstance(L[-1], TokenObject) and L[-1].name == tok.COMMA:
+ builder.push(ast.Print(items, dest))
+ else:
+ builder.push(ast.Printnl(items, dest))
+
+
def parse_dotted_names(tokens):
"""parses NAME('.' NAME)* and returns full dotted name
@@ -815,6 +859,9 @@
sym.yield_stmt : build_yield_stmt,
sym.continue_stmt : build_continue_stmt,
sym.del_stmt : build_del_stmt,
+ sym.assert_stmt : build_assert_stmt,
+ sym.exec_stmt : build_exec_stmt,
+ sym.print_stmt : build_print_stmt,
# sym.parameters : build_parameters,
}
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 09:02:26 2005
@@ -131,6 +131,32 @@
"""
]
+asserts = [
+ 'assert False',
+ 'assert a == 1',
+ 'assert a == 1 and b == 2',
+ 'assert a == 1 and b == 2, "assertion failed"',
+ ]
+
+execs = [
+ 'exec a',
+ 'exec "a=b+3"',
+ 'exec a in f()',
+ 'exec a in f(), g()',
+ ]
+
+prints = [
+ 'print',
+ 'print a',
+ 'print a,',
+ 'print a, b',
+ 'print a, "b", c',
+ 'print >> err',
+ 'print >> err, "error"',
+ 'print >> err, "error",',
+ 'print >> err, "error", a',
+ ]
+
one_stmt_funcdefs = [
"def f(): return 1",
"def f(x): return x+1",
@@ -154,6 +180,9 @@
multiexpr,
attraccess,
imports,
+ asserts,
+ execs,
+ prints
]
EXEC_INPUTS = [
More information about the Pypy-commit
mailing list