6 import Control.Monad => qualified join
8 import System.CommandLine
16 chars :: *File -> ([Char], *File)
23 :: Mode = MHelp | MLex | MParse | MType | MInterpret | MGen
25 opts :: [OptDescr (Mode -> Mode)]
27 [ Option ['?'] ["help"] (NoArg (const MHelp)) "Display this message"
28 , Option ['l'] ["lex"] (NoArg (const MLex)) "Up to and including lexing"
29 , Option ['p'] ["parse"] (NoArg (const MParse)) "Up to and including parse"
30 , Option ['t'] ["type"] (NoArg (const MType)) "Up to and including typing"
31 , Option ['i'] ["interpret"] (NoArg (const MInterpret)) "Up to and including interpretation"
32 , Option ['g'] ["gen"] (NoArg (const MGen)) "Up to and including generation"
35 Start :: *World -> Either [String] [String]
37 # ([argv0:args], w) = getCommandLine w
38 # (mode, positionals, errs) = getOpt Permute opts args
39 # mode = foldl (o) id mode MInterpret
40 | not (errs =: []) = Left [e +++ "\n"\\e<-errs]
41 | not (positionals =: []) = Left ["Positional arguments not allowed"]
44 # (_, w) = fclose io w
46 MHelp = Left [usageInfo ("Usage: " +++ argv0 +++ " [opts]\n") opts]
47 MLex = map (\x->toString x +++ "\n") <$> lex cs
48 MParse = map (\x->toString x +++ "\n") <$> (lex cs >>= parse)
49 MType = (\(e, x)->[toString x, "\n", toString e]) <$> (lex cs >>= parse >>= check)
50 MInterpret = (\x->[toString x]) <$> (lex cs >>= parse >>= check >>= int o fst)
51 MGen = lex cs >>= parse >>= check >>= gen o fst