From: Ramakrishnan Muthukrishnan Date: Sun, 28 Dec 2014 10:54:58 +0000 (+0530) Subject: exercise 3: parse SExpr X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/running.html?a=commitdiff_plain;h=03f5b2992dea2e5c21df8af1292d516899cf0f3b;p=yorgey.git exercise 3: parse SExpr --- diff --git a/hw11/SExpr.hs b/hw11/SExpr.hs index b70683a..15d6f6f 100644 --- 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