summaryrefslogtreecommitdiff
path: root/thue.hs
blob: 6630e6da6c276a4329473ec72e63d1f7bfad47f8 (plain)
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
37
38

import System.Environment( getArgs )
import Data.Typeable
import qualified Control.Exception
import Thue.Parser
import Thue.Interpreter


data ThueException = ThueException { errString :: String }
    deriving (Show, Typeable)

instance Control.Exception.Exception ThueException



usageString :: String
usageString = "Usage: thue <program file>"



program :: IO ()
program = do
	args <- getArgs
	fileContents <- if (length args /= 1)
		            then Control.Exception.throw (ThueException usageString)
		            else readFile (head args)

	case (parseThue fileContents) of
		Left x -> putStrLn (show x)
		Right x -> (thue x) >>= (putStrLn . show)



main = Control.Exception.catch program handler
        where
        	handler :: ThueException -> IO ()
        	handler err = putStrLn (errString err)