X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=hw11%2FSExpr.hs;fp=hw11%2FSExpr.hs;h=15d6f6f9e53d8927650d6b2e92483c5250d9942e;hb=03f5b2992dea2e5c21df8af1292d516899cf0f3b;hp=b70683a583a4275278ab6d416eee9b78f7d12795;hpb=2e594c0ef1af839a4e85139357c751f3140c1a8e;p=yorgey.git 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