9 import System.CommandLine
11 import parse, ast, check, int, gen
13 chars :: *File -> ([Char], *File)
20 :: Mode = MHelp | MLex | MParse | MType | MInterpret | MGen
22 opts :: [OptDescr (Mode -> Mode)]
24 [ Option ['?'] ["help"] (NoArg (const MHelp)) "Display this message"
25 , Option ['l'] ["lex"] (NoArg (const MLex)) "Up to and including lexing"
26 , Option ['p'] ["parse"] (NoArg (const MParse)) "Up to and including parse"
27 , Option ['t'] ["type"] (NoArg (const MType)) "Up to and including typing"
28 , Option ['i'] ["interpret"] (NoArg (const MInterpret)) "Up to and including interpretation"
29 , Option ['g'] ["gen"] (NoArg (const MGen)) "Up to and including generation"
32 exit :: Int [String] *File *World -> *World
33 exit i e f w = snd (fclose (foldr fwrites f e) (setReturnCode i w))
35 Start :: *World -> *World
38 # ([argv0:args], w) = getCommandLine w
39 # (mode, positionals, errs) = getOpt Permute opts args
40 # mode = foldl (o) id mode MInterpret
41 | not (errs =: []) = exit 1 [e +++ "\n"\\e<-errs] io w
42 | not (positionals =: []) = exit 1 ["Positional arguments not allowed"] io w
45 MHelp = Left [usageInfo ("Usage: " +++ argv0 +++ " [opts]\n") opts]
46 MLex = map (nl o toString) <$> lex cs
47 MParse = map (nl o either toString toString) <$> (lex cs >>= parse)
48 MType = map (\(t, s)->nl (toString t +++ " :: " +++ toString s)) o snd <$> (lex cs >>= parse >>= check)
49 MInterpret = pure o nl o toString <$> (lex cs >>= parse >>= check >>= int o fst)
50 MGen = lex cs >>= parse >>= check >>= gen o fst
51 = exit (either (\_->1) (\_->0) mstr) (either id id mstr) io w