blob: 72c577a0b9460f4cc61c07012b190c78b3363f90 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
-- 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
|