module Language.Syntax.CmdArgs ( -- * Exported modules module Language.Parser, -- * Preprocessing command-line arguments OptDescr(..),ArgDescr(..),usageInfo, tokenize, -- * Example usage -- $tutorial ) where import Language.Parser import System.Console.GetOpt -- |Create a Parser that preprocesses the command-line arguments, -- splitting options and their arguments into a user-defined data -- type. tokenize :: [OptDescr a] -> (String -> a) -> ParserT [String] (WriterT String Id) [a] tokenize options wrap = p^.mapping writer.parserT where p a = (concat err,pure (a,bs)) where (bs,_,err) = getOpt (ReturnInOrder wrap) options a {- $tutorial This module is intended to provide simple parsing functionality to the handling of command-line arguments. Here is an example of how this module may be used. >data Option = Help | Version | Other String > deriving Eq > >options = [ > Option ['h'] ["help"] (NoArg Help) "Display this menu.", > Option ['v'] ["version"] (NoArg Version) "Show the version of this program" > ] > >mainAxiom = single Help >> lift (putStrLn (usageInfo options)) > <+> single Version >> lift (putStrLn "Version: 1.0") > >main = void $ do > getArgs >>= (mainAxiom <*< tokenize options Other) -}