From 03f5b2992dea2e5c21df8af1292d516899cf0f3b Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org> Date: Sun, 28 Dec 2014 16:24:58 +0530 Subject: [PATCH] exercise 3: parse SExpr --- hw11/SExpr.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 -- 2.45.2