Safe Haskell | Safe-Infered |
---|
Errors. Parsing a command line when a user has entered it
correctly is easy; doing something sensible when an incorrect line
has been entered is a bit more difficult. This module exports an
Error
typeclass, which you can declare instances of in order to
have your own type to represent errors. Or you can use
SimpleError
, which is already an instance of Error
.
- class Error e where
- data SimpleError = SimpleError Expecting Saw
- printError :: SimpleError -> Text
- data Expecting
- = ExpPendingShortOpt ShortOpt
- | ExpExactLong LongOpt
- | ExpApproxLong (Set LongOpt)
- | ExpLongOptArg
- | ExpPendingShortArg
- | ExpStopper
- | ExpNextArg
- | ExpNonOptionPosArg
- | ExpEnd
- | ExpNonGNUExactLong LongOpt
- | ExpMatchingApproxLong LongOpt (Set LongOpt)
- | ExpNonGNUMatchingApproxLong LongOpt (Set LongOpt)
- | ExpApproxWord (Set Text)
- | ExpOptionOrPosArg
- | ExpTextError Text
- | ExpNonPendingShortOpt ShortOpt
- | ExpNotFollowedBy
- | ExpOtherFailure
- printExpecting :: Expecting -> Text
- data Saw
- = SawNoPendingShorts
- | SawWrongPendingShort Char
- | SawNoArgsLeft
- | SawEmptyArg
- | SawSingleDashArg
- | SawStillPendingShorts TextNonEmpty
- | SawNotShortArg Text
- | SawWrongShortArg Char
- | SawNotLongArg Text
- | SawWrongLongArg Text
- | SawNoMatches Text
- | SawMultipleMatches (Set LongOpt) Text
- | SawNoPendingShortArg
- | SawAlreadyStopper
- | SawNewStopper
- | SawNotStopper
- | SawLeadingDashArg Text
- | SawMoreInput
- | SawGNULongOptArg Text
- | SawNotMatchingApproxLong Text LongOpt
- | SawMatchingApproxLongWithArg Text
- | SawMultipleApproxMatches (Set Text) Text
- | SawNoOption
- | SawNoOptionOrPosArg
- | SawTextError Text
- | SawFollowedBy
- | SawOtherFailure
- printSaw :: Saw -> Text
Documentation
Instances of this typeclass represent multiarg errors. You can
declare instances of this typeclass so that you can use your own
type for errors. This makes multiarg easy to integrate into your
own programs. Then you can also easily add other errors, which you
can report from the parsers you build by calling
throw
.
data SimpleError Source
A simple type that is already an instance of Error
.
printError :: SimpleError -> TextSource
Generates error messages.
Each error consists of two parts: what the parser was expecting
to see, and what it actually saw. This type holds what the parser
expected to see. If you just want to give some text to be used in
an error message, use ExpTextError
. To generate a generic error,
use ExpOtherFailure
.
printExpecting :: Expecting -> TextSource
Generates an error message from an Expecting.
What the parser actually saw. To give some text to be used in the
error message, use SawTextError
. To generate a generic error, use
SawOtherFailure
.