996
|
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" |