Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Grover is a simple example program that shows how to write a parser for commands with multiple modes. You build such parsers using Multiarg.Mode. It provides an example for the documentation, and it also provides fodder for the QuickCheck tests. You will want to look at the source code.
Grover has three modes: int
, string
, and maybe
. Each of
these modes has three options: -z
or --zero
, which takes no
arguments; -s
or --single
, which takes one argument; -d
or
--double
, which takes two arguments; and -t
or --triple
,
which takes three arguments. The type of the argument depends on
the mode. For int
, the argument or arguments must be an integer;
for string
the arguments can be any string; and for maybe
the
arguments must be a Maybe Int, such as Nothing
or Just 5
.
Each mode also accepts any number of positional arguments, which can be any string.
Grover handles simple errors right inside the parser by using the
Either
type as a return value.
- data Global
- data GroverOpt a
- globalOptSpecs :: [OptSpec (Either String Global)]
- modeOptSpecs :: Read a => [OptSpec (Either String (GroverOpt a))]
- data Result
- modes :: [Mode Result]
- readErr :: Read a => String -> Either String a
- parseGrover :: [String] -> Either (String, [String]) (ModeResult (Either String Global) Result)
Documentation
Grover's global options.
Handles all options and positional arguments for any Grover mode.
Holds the results of parsing Grover's modes.
readErr :: Read a => String -> Either String a Source
Reads a value. If it cannot be read, returns an error message.
:: [String] | Command line arguments, presumably from |
-> Either (String, [String]) (ModeResult (Either String Global) Result) | Returns a |
Parses all of Grover's options and modes.