better tests and results

This commit is contained in:
Yann Esposito (Yogsototh) 2013-07-18 18:55:18 +02:00
parent 4326566ecd
commit 7b9efe9a3e
8 changed files with 24 additions and 15 deletions

View file

@ -1,2 +1,6 @@
32
32
#x012
18
#b001010
Number 10
10

View file

@ -1,2 +1,2 @@
#\a
Character 'a'
'a'

View file

@ -1,2 +1,2 @@
3.14
Float 3.14
3.14

View file

@ -1,4 +0,0 @@
(a list)
List [Atom "a",Atom "list"]
(a (nested) list)
List [Atom "a",List [Atom "nested"],Atom "list"]

View file

@ -1,2 +1,2 @@
32
Number 32
32

View file

@ -1,6 +1,6 @@
"This is a simple string"
String "This is a simple string"
"This is a string with a return ->\n<- Here"
String "This is a string with a return ->\n<- Here"
"More difficult string \n, \r, \t, \\, \x, \A"
String "More difficult string \n, \r, \t, \\, x, A"
"This is a simple string"
"A tab ->\t<- Here"
"A tab -> <- Here"
"\S\o\m\e\ \pr\ot\e\ct\e\d\ \w\it\h\ \\"
"Some protected with \"

11
y.hs
View file

@ -28,7 +28,16 @@ main = do
readExpr :: String -> String
readExpr input = case parse parseExpr "lisp" input of
Left err -> "No match: " ++ show err
Right val -> show val
Right val -> showVal val
showVal :: LispVal -> String
showVal (String contents) = "\"" ++ contents ++ "\""
showVal (Atom name) = name
showVal (Number contents) = show contents
showVal (Float contents) = show contents
showVal (Character c) = '\'':c:'\'':[]
showVal (Bool True) = "#t"
showVal (Bool False) = "#f"
-- parseExpr will parse the Expression
parseExpr :: Parser LispVal