import StdEnv
import Data.Either
import Data.Functor
-import Data.Func
-import Text
import Control.Monad => qualified join
import System.GetOpt
import System.CommandLine
= ([c:cs], f)
:: Mode = MHelp | MLex | MParse | MType | MInterpret | MGen
-:: Result
- = Lex [Token]
- | Parse String
- | Type Expression
- | Interpret Value
- | Gen [String]
-options :: [OptDescr (Mode->Mode)]
-options =
+opts :: [OptDescr (Mode -> Mode)]
+opts =
[ Option ['?'] ["help"] (NoArg (const MHelp)) "Display this message"
, Option ['l'] ["lex"] (NoArg (const MLex)) "Up to and including lexing"
, Option ['p'] ["parse"] (NoArg (const MParse)) "Up to and including parse"
, Option ['g'] ["gen"] (NoArg (const MGen)) "Up to and including generation"
]
-Start :: *World -> Either [String] Result
+Start :: *World -> Either [String] [String]
Start w
# ([argv0:args], w) = getCommandLine w
- # (mode, positionals, errs) = getOpt Permute options args
+ # (mode, positionals, errs) = getOpt Permute opts args
# mode = foldl (o) id mode MInterpret
| not (errs =: []) = Left [e +++ "\n"\\e<-errs]
| not (positionals =: []) = Left ["Positional arguments not allowed"]
# (io, w) = stdio w
# (cs, io) = chars io
+ # (_, w) = fclose io w
= case mode of
- MHelp = Left [usageInfo ("Usage: " +++ argv0 +++ " [options]\n") options]
- MLex = Lex <$> lex cs
- MParse = Parse <$> join "\n" <$> map toString <$> (lex cs >>= parse)
- MType = Type <$> (lex cs >>= parse >>= check)
- MInterpret = Interpret <$> (lex cs >>= parse >>= check >>= int)
- MGen = Gen <$> (lex cs >>= parse >>= check >>= gen)
+ MHelp = Left [usageInfo ("Usage: " +++ argv0 +++ " [opts]\n") opts]
+ MLex = map (\x->toString x +++ "\n") <$> lex cs
+ MParse = map (\x->toString x +++ "\n") <$> (lex cs >>= parse)
+ MType = (\x->[toString x]) <$> (lex cs >>= parse >>= check)
+ MInterpret = (\x->[toString x]) <$> (lex cs >>= parse >>= check >>= int)
+ MGen = lex cs >>= parse >>= check >>= gen