-
Notifications
You must be signed in to change notification settings - Fork 1
/
MTest.hs
89 lines (83 loc) · 2.85 KB
/
MTest.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
module MTest where
import System.Environment
import qualified Lexer as Lexer
import qualified MsgTypeLexer as MsgTypeLexer
import qualified Parser as Parser
import qualified CodeGenerator as CG
main = do
putStrLn "Command is \"p\" - available commands: l, p, lp, lf, m, mf, mc, tc (f = read from file, c = compile file to file)"
loop "p"
loop cmd = do
line <- getLine
case line of
"" -> return ()
"l" -> do
putStrLn "Switched to lexer"
loop "l"
"m" -> do
putStrLn "Switched to message type lexer"
loop "m"
"lf" -> do
putStrLn "Switched to lexer (files)"
loop "lf"
"mf" -> do
putStrLn "Switched to message type file lexer"
loop "mf"
"mc" -> do
putStrLn "Switched to message type file compiler (output: M.java)"
loop "mc"
"tc" -> do
putStrLn "Switched to task compiler (output: <name>.java)"
loop "tc"
"p" -> do
putStrLn "Switched to parser"
loop "p"
"lp" -> do
putStrLn "Switched to lexer and parser"
loop "p"
_ ->
do
-- let cmd = head $ words line
-- let t = dropWhile (/=' ') line
-- putStrLn $ runCmd cmd t
case cmd of
"lf" -> do
f <- readFile line
let tokens = Lexer.scanner f
putStrLn $ show tokens
return ()
"mf" -> do
f <- readFile line
let tokens = MsgTypeLexer.scanner f
putStrLn $ show tokens
return ()
"mc" -> do
f <- readFile line
let tokens = MsgTypeLexer.scanner f
case tokens of
Left err -> putStrLn err
Right ts -> writeFile "M.java" $ CG.makeMsgTypeFile ts
return ()
"tc" -> do
f <- readFile line
let tokens = Lexer.scanner f
case tokens of
Left err -> putStrLn err
Right ts ->
let task = Parser.parse ts
(filename, content) = CG.makeTaskFile task [Parser.name task]
in writeFile filename content
return ()
_ -> putStrLn $ runCmd cmd line
loop cmd
runCmd cmd arg = case cmd of
"l" -> (either id show (Lexer.scanner arg))
-- "l" -> either id id (either Left (Right $ show $ Parser.parse) (Lexer.scanner arg)) --(either id show (Lexer.scanner arg))
"m" -> (either id show (MsgTypeLexer.scanner arg))
"p" -> case Lexer.scanner arg of
Left err -> err
Right tokens -> show $ Parser.parse tokens--case Parser.parse tokens of
"lp" -> runCmd "l" arg ++ "\n" ++ runCmd "p" arg
-- Left err -> err
-- Right p -> show p
-- "l" -> either id show (either Left (Parser.parse) (Lexer.scanner arg)) --(either id show (Lexer.scanner arg))