Safe Haskell | Safe-Infered |
---|
System.Console.MultiArg.Combinator
Description
Combinators that are useful for building command-line parsers. These build off the functions in System.Console.MultiArg.Prim. Unlike those functions, these functions have no access to the internals of the parser.
Parser combinators
notFollowedBy :: Parser a -> Parser ()Source
notFollowedBy p
succeeds only if parser p fails. If p fails,
notFollowedBy succeeds without consuming any input. If p succeeds
and consumes input, notFollowedBy fails and consumes input. If p
succeeds and does not consume any input, notFollowedBy fails and
does not consume any input.
(<?>) :: Parser a -> String -> Parser aSource
Runs the parser given. If it succeeds, then returns the result of the parser. If it fails and consumes input, returns the result of the parser. If it fails without consuming any input, then removes all previous errors, replacing them with a single error of type Replaced containing the string given.
Combined long and short option parser
Specifies options for the parseOption
function. Each OptSpec
represents one command-line option.
Constructors
OptSpec | |
Fields
|
Specifies how many arguments each option takes. As with
ArgDescr
, there are (at least) two ways to
use this type. You can simply represent each possible option using
different data constructors in an algebraic data type. Or you can
have each ArgSpec yield a function that transforms a record. For an
example that uses an algebraic data type, see
System.Console.MultiArg.SampleParser.
Constructors
NoArg a | This option takes no arguments |
OptionalArg (Maybe String -> a) | This option takes an optional argument. As noted in "The Tao
of Option Parsing", optional arguments can result in some
ambiguity. (Read it here:
http://optik.sourceforge.net/doc/1.5/tao.html) If option |
OneArg (String -> a) | This option takes one argument. Here, if option |
TwoArg (String -> String -> a) | This option takes two arguments. Parsed similarly to |
VariableArg ([String] -> a) | This option takes a variable number of arguments--zero or
more. Option arguments continue until the command line contains
a word that begins with a hyphen. For example, if option |
parseOption :: [OptSpec a] -> Parser aSource
Parses a single command line option. Examines all the options
specified using multiple OptSpec and parses one option on the
command line accordingly. Fails without consuming any input if the
next word on the command line is not a recognized option. Allows
the user to specify the shortest unambiguous match for long
options; for example, the user could type --verb
for --verbose
and --vers
for --version
.
For an example that uses this function, see System.Console.MultiArg.SimpleParser.
Other words
matchApproxWord :: Set String -> Parser (String, String)Source
Examines the possible words in Set. If there are no pendings, then get the next word and see if it matches one of the words in Set. If so, returns the word actually parsed and the matching word from Set. If there is no match, fails without consuming any input.