comparison interps/rhotor/Main.hs @ 996:859f9b4339e6

<Gregor> tar xf egobot.tar.xz
author HackBot
date Sun, 09 Dec 2012 19:30:08 +0000
parents
children
comparison
equal deleted inserted replaced
995:6883f5911eb7 996:859f9b4339e6
1 module Main ()
2 where
3
4 import System.IO
5 import System.Environment
6 import System.Exit
7
8 import Misc
9 import Parser
10 import Evaluator
11
12
13
14 main :: IO ()
15 main = (hSetBuffering stdout NoBuffering) >> getArgs >>= \args ->
16 if length args /= 1 then usage
17 else readFile (head args) `catch` (\ _ -> putStr "Error: Couldn't open source file.\n" >> exitWith (ExitFailure 1))
18 >>= \source ->
19 interact (run source)
20
21 run :: String -> String -> String
22 run source input = nodeTreeToString (evaluate (apply (parse source) (stringToNodeTree input)))
23
24
25
26 usage :: IO ()
27 usage = putStr "Usage: rhotorhi sourcecode.rho\n"