melody-0.2: src/Language/Melody.hs
module Language.Melody where
import Language.Melody.Parser
import Language.Melody.Interpret
import Control.Monad
import Control.Monad.Error
import System.Environment
import System.IO
repl :: Melody
repl = forever . flip catchError (liftIO . print) $ do
liftIO $ putStr ">>> " >> hFlush stdout
l <- parseMelody `fmap` liftIO getLine
case l of
Left err -> liftIO $ print err
Right m -> eval m
evalFile :: String -> Melody
evalFile f = do
res <- liftIO $ parseSrcFile f
case res of
Left err -> liftIO $ print err
Right toplevels -> mapM_ eval toplevels
main :: IO ()
main = do
args <- getArgs
void . runMelody $ mapM_ evalFile args >> repl