9 import System.CommandLine
17 chars :: *File -> ([Char], *File)
24 :: Mode = MHelp | MLex | MParse | MType | MInterpret | MGen
32 options :: [OptDescr (Mode->Mode)]
34 [ Option ['?'] ["help"] (NoArg (const MHelp)) "Display this message"
35 , Option ['l'] ["lex"] (NoArg (const MLex)) "Up to and including lexing"
36 , Option ['p'] ["parse"] (NoArg (const MParse)) "Up to and including parse"
37 , Option ['t'] ["type"] (NoArg (const MType)) "Up to and including typing"
38 , Option ['i'] ["interpret"] (NoArg (const MInterpret)) "Up to and including interpretation"
39 , Option ['g'] ["gen"] (NoArg (const MGen)) "Up to and including generation"
42 Start :: *World -> Either [String] Result
44 # ([argv0:args], w) = getCommandLine w
45 # (mode, positionals, errs) = getOpt Permute options args
46 # mode = foldl (o) id mode MInterpret
47 | not (errs =: []) = Left [e +++ "\n"\\e<-errs]
48 | not (positionals =: []) = Left ["Positional arguments not allowed"]
52 MHelp = Left [usageInfo ("Usage: " +++ argv0 +++ " [options]\n") options]
54 MParse = Parse <$> (lex cs >>= parse)
55 MType = Type <$> (lex cs >>= parse >>= check)
56 MInterpret = Interpret <$> (lex cs >>= parse >>= check >>= int)
57 MGen = Gen <$> (lex cs >>= parse >>= check >>= gen)