-- vim: et ts=2 sw=2 ai: module Main where import Prelude hiding(lex) import System.Environment import System.Exit import Text.Parsec.Error (ParseError) import SPL.Syntax import SPL.Lex import SPL.Parse import SPL.PrettyPrinter main :: IO () main = do args <- getArgs contents <- getContents case lex contents of Nothing -> do putStrLn "Failed to lex" exit 1 Just tks -> if "--parse" `elem` args then doParse tks else return () where doParse :: [Token] -> IO () doParse tks = case parse tks of Left e -> do putStrLn $ "Failed to parse (" ++ show e ++ "). Tokens were:" putStrLn $ show tks exit 1 Right pgm -> putStrLn $ prettyPrint pgm exit :: Int -> IO () exit = exitWith . ExitFailure