Character ex. 5
This commit is contained in:
parent
4ce9162f98
commit
a5285e5ddb
3 changed files with 10 additions and 0 deletions
1
tests/char.in
Normal file
1
tests/char.in
Normal file
|
@ -0,0 +1 @@
|
|||
#\a
|
1
tests/char.out
Normal file
1
tests/char.out
Normal file
|
@ -0,0 +1 @@
|
|||
Character 'a'
|
8
y.hs
8
y.hs
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue