projects
/
yorgey.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
2e594c0
)
exercise 3: parse SExpr
author
Ramakrishnan Muthukrishnan
<ram@rkrishnan.org>
Sun, 28 Dec 2014 10:54:58 +0000
(16:24 +0530)
committer
Ramakrishnan Muthukrishnan
<ram@rkrishnan.org>
Sun, 28 Dec 2014 10:54:58 +0000
(16:24 +0530)
hw11/SExpr.hs
patch
|
blob
|
history
diff --git
a/hw11/SExpr.hs
b/hw11/SExpr.hs
index b70683a583a4275278ab6d416eee9b78f7d12795..15d6f6f9e53d8927650d6b2e92483c5250d9942e 100644
(file)
--- a/
hw11/SExpr.hs
+++ b/
hw11/SExpr.hs
@@
-52,3
+52,13
@@
data Atom = N Integer | I Ident
data SExpr = A Atom
| Comb [SExpr]
deriving Show
+
+parseAtom :: Parser Atom
+parseAtom = spaces *> (N <$> posInt <|>
+ I <$> ident) <* spaces
+
+parseSExpr :: Parser SExpr
+parseSExpr = A <$> parseAtom <|>
+ Comb <$> parseComb
+ where
+ parseComb = spaces *> char '(' *> oneOrMore parseSExpr <* spaces <* char ')' <* spaces