Character ex. 5

This commit is contained in:
Yann Esposito (Yogsototh) 2013-07-17 22:45:03 +02:00
parent 4ce9162f98
commit a5285e5ddb
3 changed files with 10 additions and 0 deletions

1
tests/char.in Normal file
View file

@ -0,0 +1 @@
#\a

1
tests/char.out Normal file
View file

@ -0,0 +1 @@
Character 'a'

8
y.hs
View file

@ -8,6 +8,7 @@ data LispVal = Atom String
| List [LispVal]
| DottedList [LispVal] LispVal
| Number Integer
| Character Char
| String String
| Bool Bool
deriving (Show)
@ -18,6 +19,12 @@ symbol = oneOf "!#$%&|*+-/:<=>?@^_~"
spaces :: Parser ()
spaces = skipMany1 space
parseChar :: Parser LispVal
parseChar = do
string "#\\"
c <- anyChar
return $ Character c
parseString :: Parser LispVal
parseString = do
char '"'
@ -102,6 +109,7 @@ parseNumber = do
parseExpr :: Parser LispVal
parseExpr = parseString
<|> try parseChar
<|> parseNumber
<|> parseAtom