X-Git-Url: https://git.lukelau.me/?p=kaleidoscope-hs-old.git;a=blobdiff_plain;f=AST.hs;h=1965ae6ba8378bc8277b2b46fe031ea04a64a5d5;hp=2bea0028cf47bb61f94c982f011ca24b72a612ac;hb=808a6ae35fb1f2ff61a84991af1e7722298a4d62;hpb=98897ccc44795260735bafc5124e0e14052247f2 diff --git a/AST.hs b/AST.hs index 2bea002..1965ae6 100644 --- a/AST.hs +++ b/AST.hs @@ -4,6 +4,15 @@ import Data.Char import Text.Read import Text.ParserCombinators.ReadP hiding ((+++), choice) +newtype Program = Program [AST] + deriving Show + +instance Read Program where + readPrec = fmap Program $ lift $ sepBy1 (readPrec_to_P readPrec 0) $ do + skipSpaces + char ';' + skipSpaces + data AST = Function String [String] Expr | Eval Expr deriving Show @@ -25,9 +34,7 @@ instance Read AST where params <- between (char '(') (char ')') $ sepBy (munch1 isAlpha) skipSpaces skipSpaces - body <- between (char '{') (char '}') $ - readS_to_P reads - skipSpaces + body <- readS_to_P reads return (Function name params body) instance Read Expr where