[pypy-svn] r44742 - in pypy/dist/pypy/lang/scheme: . test
jlg at codespeak.net
jlg at codespeak.net
Thu Jul 5 16:56:56 CEST 2007
Author: jlg
Date: Thu Jul 5 16:56:56 2007
New Revision: 44742
Modified:
pypy/dist/pypy/lang/scheme/ssparser.py
pypy/dist/pypy/lang/scheme/test/test_parser.py
Log:
dotted list parsing take2
Modified: pypy/dist/pypy/lang/scheme/ssparser.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/ssparser.py (original)
+++ pypy/dist/pypy/lang/scheme/ssparser.py Thu Jul 5 16:56:56 2007
@@ -47,8 +47,7 @@
return {s};
sexpr:
- dotted
- | list
+ list
| FLOAT
| FIXNUM
| BOOLEAN
@@ -63,19 +62,13 @@
IGNORE*
return {p};
- dotted:
- '('
- IGNORE*
+ pair:
car = sexpr
'.'
IGNORE*
cdr = sexpr
- ')'
- IGNORE*
- return {W_Pair(car, cdr)};
-
- pair:
- car = sexpr
+ return {W_Pair(car, cdr)}
+ | car = sexpr
cdr = pair
return {W_Pair(car, cdr)}
| return {W_Nil()};
Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/test/test_parser.py (original)
+++ pypy/dist/pypy/lang/scheme/test/test_parser.py Thu Jul 5 16:56:56 2007
@@ -100,9 +100,26 @@
t = parse("#t")
assert unwrap(t) == True
-def test_dotted():
+def test_list_dotted():
t = parse("(1 . 2)")
assert isinstance(t, W_Pair)
assert unwrap(t.car) == 1
assert unwrap(t.cdr) == 2
+ t = parse("(1 . (2 . 3))")
+ assert unwrap(t.car) == 1
+ assert unwrap(t.cdr.car) == 2
+ assert unwrap(t.cdr.cdr) == 3
+
+ t = parse("(1 . (2 . (3 . ())))")
+ assert unwrap(t) == [1, 2, 3]
+
+def test_list_mixed():
+ t = parse("(1 2 . 3)")
+ assert unwrap(t.car) == 1
+ assert unwrap(t.cdr.car) == 2
+ assert unwrap(t.cdr.cdr) == 3
+
+ t = parse("(1 2 . (3 4))")
+ assert unwrap(t) == [1, 2, 3, 4]
+
More information about the Pypy-commit
mailing list