[pypy-svn] r17588 - in pypy/dist/pypy/interpreter/pyparser: . test
ac at codespeak.net
ac at codespeak.net
Fri Sep 16 11:21:23 CEST 2005
Author: ac
Date: Fri Sep 16 11:21:23 2005
New Revision: 17588
Modified:
pypy/dist/pypy/interpreter/pyparser/astbuilder.py
pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
Log:
Support imaginar constants (e.g. 3.4j)
Modified: pypy/dist/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/astbuilder.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/astbuilder.py Fri Sep 16 11:21:23 2005
@@ -1606,6 +1606,9 @@
if value.endswith('l') or value.endswith('L'):
value = value[:-1]
return string_to_w_long( space, value, base=base )
+ if value.endswith('j') or value.endswith('J'):
+ c = space.builtin.get('complex')
+ return space.call_function(c, space.wrap(value))
try:
return space.wrap(string_to_int(value, base=base))
except ParseStringError:
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 Fri Sep 16 11:21:23 2005
@@ -11,6 +11,7 @@
from pypy.interpreter.astcompiler import ast
+from pypy.objspace.std import objspace
def arglist_equal(left,right):
"""needs special case because we handle the argumentlist differently"""
@@ -81,6 +82,20 @@
return False
return True
+constants = [
+ "0",
+ "7",
+ "-3",
+ "053",
+ "0x18",
+ "14L",
+ "1.0",
+ "3.9",
+ "-3.6",
+ "1.8e19",
+ "3j"
+ ]
+
expressions = [
"x = a + 1",
"x = 1 - a",
@@ -565,9 +580,9 @@
def call_method(self, obj, meth, *args):
return getattr(obj, meth)(*args)
-def ast_parse_expr(expr, target='single'):
+def ast_parse_expr(expr, target='single', space=FakeSpace):
target = TARGET_DICT[target]
- builder = AstBuilder(space=FakeSpace())
+ builder = AstBuilder(space=space())
PYTHON_PARSER.parse_source(expr, target, builder)
return builder
@@ -585,7 +600,6 @@
print "-" * 30
assert nodes_equal( ast, r1.rule_stack[-1]), 'failed on %r' % (expr)
-
def test_basic_astgen():
for family in TESTS:
for expr in family:
@@ -596,6 +610,14 @@
for expr in family:
yield check_expression, expr, 'exec'
+def check_constant(expr):
+ ast_parse_expr(expr, 'single', objspace.StdObjSpace)
+
+def test_constants():
+ for expr in constants:
+ yield check_constant, expr
+
+
SNIPPETS = [
'snippet_1.py',
'snippet_several_statements.py',
More information about the Pypy-commit
mailing list