-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathki.hs
37 lines (36 loc) · 1.06 KB
/
ki.hs
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
import System.Environment
import System.IO
import UModuleLoader
import UParse
import UEnvironment
import URunTime
import ULambdaExpression
import UInterpret
import qualified Data.Set as Set
main = do
args <- getArgs
case args of
"-i":ifname:[] -> do
writeEvalResult ifname stdout args
"-i":ifname:"-o":ofname:[] -> do
fout <- openFile ofname WriteMode
writeEvalResult ifname fout args
hClose fout
"-t":ifname:[] -> do
fin <- openFile ifname ReadMode
writeParseResult fin stdout
"-t":ifname:"-o":ofname:[] -> do
fin <- openFile ifname ReadMode
fout <- openFile ofname WriteMode
writeParseResult fin fout
hClose fout
"-repl":[] -> runInteractive [] False
_ -> putStrLn "ki -i <file> [-o <file>]\nki -t <file> [-o <file>]\nki -repl"
where
writeEvalResult ifname fout args = do
runFileF fout ifname args
writeParseResult fin fout = do
content <- hGetContents fin
case parseSTokenTreeStr content of
SFail msg position -> putStrLn ("parser error: "++msg++" at "++(show position))
SSucc (st,_) -> hPutStr fout (show st)