Maintainer | Leon P Smith <leon@melding-monads.com> |
---|---|
Safe Haskell | None |
- data MaybeParser a
- runMaybeParser :: MaybeParser a -> Maybe Value -> (Maybe a, [ConversionError])
- class FromMaybeValue a where
- optionalValue :: ValueParser a -> MaybeParser (Maybe a)
- requiredValue :: forall a. Typeable a => ValueParser a -> MaybeParser a
- data ValueParser a
- runValueParser :: ValueParser a -> Value -> (Maybe a, [ConversionError])
- class FromValue a where
- fromValue :: ValueParser a
- data ListParser a
- class FromListValue a where
- fromListValue :: ListParser a
- listValue :: forall a. Typeable a => ListParser a -> ValueParser a
- listValue' :: forall a. Typeable a => ListParser a -> ValueParser a
- listElem :: forall a. Typeable a => ValueParser a -> ListParser a
- data ConversionError = ConversionError {}
- data ConversionErrorWhy
- = MissingValue
- | ExtraValues
- | ExhaustedValues
- | TypeError
- | ValueError
- | MonadFail
- | OtherError
- defaultConversionError :: ConversionError
- boundedIntegerValue :: forall a. (Typeable a, Integral a, Bounded a) => ValueParser a
- integralValue :: forall a. (Typeable a, Integral a) => ValueParser a
- fractionalValue :: forall a. (Typeable a, Fractional a) => ValueParser a
- realFloatValue :: forall a. (Typeable a, RealFloat a) => ValueParser a
- fixedValue :: forall a. (Typeable a, HasResolution a) => ValueParser (Fixed a)
- scientificValue :: ValueParser Scientific
- textValue :: ValueParser Text
- charValue :: ValueParser Char
- typeError :: Text -> Value -> TypeRep -> ConversionError
- valueError :: Text -> Value -> TypeRep -> Text -> ConversionError
- extraValuesError :: Text -> [Value] -> TypeRep -> ConversionError
- missingValueError :: Text -> TypeRep -> ConversionError
Documentation
data MaybeParser a Source
runMaybeParser :: MaybeParser a -> Maybe Value -> (Maybe a, [ConversionError])Source
class FromMaybeValue a whereSource
optionalValue :: ValueParser a -> MaybeParser (Maybe a)Source
Turns a ValueParser
into a MaybeParser
. If the Maybe
Value
the
parser is passed is Nothing
(which normally means a key was not found),
then this returns the Nothing
value with no errors or warnings.
Otherwise, it passes the Value
to the subparser. If the
subparser returns a result value, then this returns Just
the value.
Otherwise, if the subparser does not return a value, then this does
not return a value.
Any errors/warnings returned by the subparser are returned exactly as-is.
requiredValue :: forall a. Typeable a => ValueParser a -> MaybeParser aSource
Turns a ValueParser
into a MaybeParser
. If the Maybe
Value
the
parser is passed is Nothing
(which normally means a key was not found),
then this does not return a value and also returns a missingValueError
.
Otherwise, the Value
is passed to the subparser, and the result
and any errors/warnings are returned as-is.
data ValueParser a Source
An action to turn a Value
into zero or one values of type a
,
and possibly report errors/warnings.
runValueParser :: ValueParser a -> Value -> (Maybe a, [ConversionError])Source
FromValue Bool | |
FromValue Char | |
FromValue Double | |
FromValue Float | |
FromValue Int | |
FromValue Int8 | |
FromValue Int16 | |
FromValue Int32 | |
FromValue Int64 | |
FromValue Integer | |
FromValue Word | |
FromValue Word8 | |
FromValue Word16 | |
FromValue Word32 | |
FromValue Word64 | |
FromValue String | |
FromValue ByteString | |
FromValue ByteString | |
FromValue Text | |
FromValue Text | |
FromValue CFloat | |
FromValue CDouble | |
FromValue Scientific | |
FromValue Value | |
(Typeable a, FromValue a) => FromValue [a] | |
(Typeable a, Integral a) => FromValue (Ratio a) | |
(Typeable a, HasResolution a) => FromValue (Fixed a) | |
(Typeable a, RealFloat a) => FromValue (Complex a) | |
(Typeable a, FromValue a, Typeable b, FromValue b) => FromValue (a, b) | |
(Typeable a, FromValue a, Typeable b, FromValue b, Typeable c, FromValue c) => FromValue (a, b, c) | |
(Typeable a, FromValue a, Typeable b, FromValue b, Typeable c, FromValue c, Typeable d, FromValue d) => FromValue (a, b, c, d) |
data ListParser a Source
An action to turn a [
into zero or one values of type Value
]a
,
and possibly report errors/warnings.
class FromListValue a whereSource
(Typeable a, FromValue a, Typeable b, FromValue b) => FromListValue (a, b) | |
(Typeable a, FromValue a, Typeable b, FromValue b, Typeable c, FromValue c) => FromListValue (a, b, c) | |
(Typeable a, FromValue a, Typeable b, FromValue b, Typeable c, FromValue c, Typeable d, FromValue d) => FromListValue (a, b, c, d) |
listValue :: forall a. Typeable a => ListParser a -> ValueParser aSource
Turns a ListParser
into a ValueParser
. It first checks that the
Value
the ValueParser
is passed is a List
Value. If it's not,
this returns no result as well as a typeError
. Otherwise, it passes
the list of results to the ListParser
subparser.
If the subparser consumes all of the list elements, this returns the value and errors as-is. If there are leftover list elements, this returns the value, and adds a message warning of the extra elements to the list of errors.
The difference from 'listValue\'' is that this returns values with unconsumed list elements (discarding the list elements).
listValue' :: forall a. Typeable a => ListParser a -> ValueParser aSource
Turns a ListParser
into a ValueParser
. It first checks that the
Value
the ValueParser
is passed is a List
Value. If it's not,
this returns no result as well as a typeError
. Otherwise, it passes
the list of results to the ListParser
subparser.
If the subparser consumes all of the list elements, this returns the value and errors as-is. If there are leftover list elements, this returns no value, and adds a message warning of the extra elements to the list of errors.
The difference from listValue
is that this never returns a value if
there are unconsumed list elements. (discarding both the value returned
and the list element.)
listElem :: forall a. Typeable a => ValueParser a -> ListParser aSource
Turns a ValueParser
into a ListParser
that consumes a single element.
If there are no list elements left, this returns list error value and an
ExhaustedValues
error.
If there is an element left, it is passed to the value parser. If the value parser returns a value, it is returned along with the errors as-is. If the value parser returns no value, then this returns a non-list error value and the list of errors returned by the value parser.
The difference between a list error value and a non-list error value,
is that the Alternative
instance for ListParser
recovers from list
error values but does not recover from non-list error values. This
behavior was chosen so that the optional
, some
, and many
combinators
work on ListParser
s in a way that is hopefully least surprising.
data ConversionError Source
data ConversionErrorWhy Source
Assorted primitive value parsers
boundedIntegerValue :: forall a. (Typeable a, Integral a, Bounded a) => ValueParser aSource
integralValue :: forall a. (Typeable a, Integral a) => ValueParser aSource
fractionalValue :: forall a. (Typeable a, Fractional a) => ValueParser aSource
realFloatValue :: forall a. (Typeable a, RealFloat a) => ValueParser aSource
fixedValue :: forall a. (Typeable a, HasResolution a) => ValueParser (Fixed a)Source
valueError :: Text -> Value -> TypeRep -> Text -> ConversionErrorSource
extraValuesError :: Text -> [Value] -> TypeRep -> ConversionErrorSource