configurator-ng-0.0.0.1: The next generation of configuration management

Copyright | (c) 2016 Leon P Smith
License | BSD3
Maintainer | Leon P Smith <leon@melding-monads.com>
Safe Haskell | None
Language | Haskell98

Data.Configurator.FromValue

Contents

- Assorted primitive value parsers

Description

Synopsis

- 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
- data ListParser a
- class FromListValue a where
- 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 {
  - conversionErrorLoc :: Text
  - conversionErrorWhy :: ConversionErrorWhy
  - conversionErrorVal :: !(Maybe Value)
  - conversionErrorType :: !(Maybe TypeRep)
  - conversionErrorMsg :: !(Maybe Text)
  }
- 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 #

An action to turn a `Maybe` `Value` into zero or one values of type `a`, and possibly report errors/warnings.

Instances

Monad MaybeParser # |
Methods (>>=) :: MaybeParser a -> (a -> MaybeParser b) -> MaybeParser b # (>>) :: MaybeParser a -> MaybeParser b -> MaybeParser b # return :: a -> MaybeParser a # fail :: String -> MaybeParser a #
Functor MaybeParser # |
Methods fmap :: (a -> b) -> MaybeParser a -> MaybeParser b # (<$) :: a -> MaybeParser b -> MaybeParser a #
MonadFail MaybeParser # |
Methods fail :: String -> MaybeParser a #
Applicative MaybeParser # |
Methods pure :: a -> MaybeParser a # (<*>) :: MaybeParser (a -> b) -> MaybeParser a -> MaybeParser b # (*>) :: MaybeParser a -> MaybeParser b -> MaybeParser b # (<*) :: MaybeParser a -> MaybeParser b -> MaybeParser a #
Alternative MaybeParser # |
Methods empty :: MaybeParser a # (<|>) :: MaybeParser a -> MaybeParser a -> MaybeParser a # some :: MaybeParser a -> MaybeParser [a] # many :: MaybeParser a -> MaybeParser [a] #

runMaybeParser :: MaybeParser a -> Maybe Value -> (Maybe a, [ConversionError]) #

class FromMaybeValue a where #

Methods

fromMaybeValue :: MaybeParser a #

fromMaybeValue :: (Typeable a, FromValue a) => MaybeParser a #

Instances

FromMaybeValue Bool # |
Methods fromMaybeValue :: MaybeParser Bool #
FromMaybeValue Char # |
Methods fromMaybeValue :: MaybeParser Char #
FromMaybeValue Double # |
Methods fromMaybeValue :: MaybeParser Double #
FromMaybeValue Float # |
Methods fromMaybeValue :: MaybeParser Float #
FromMaybeValue Int # |
Methods fromMaybeValue :: MaybeParser Int #
FromMaybeValue Int8 # |
Methods fromMaybeValue :: MaybeParser Int8 #
FromMaybeValue Int16 # |
Methods fromMaybeValue :: MaybeParser Int16 #
FromMaybeValue Int32 # |
Methods fromMaybeValue :: MaybeParser Int32 #
FromMaybeValue Int64 # |
Methods fromMaybeValue :: MaybeParser Int64 #
FromMaybeValue Integer # |
Methods fromMaybeValue :: MaybeParser Integer #
FromMaybeValue Word # |
Methods fromMaybeValue :: MaybeParser Word #
FromMaybeValue Word8 # |
Methods fromMaybeValue :: MaybeParser Word8 #
FromMaybeValue Word16 # |
Methods fromMaybeValue :: MaybeParser Word16 #
FromMaybeValue Word32 # |
Methods fromMaybeValue :: MaybeParser Word32 #
FromMaybeValue Word64 # |
Methods fromMaybeValue :: MaybeParser Word64 #
FromMaybeValue ByteString # |
Methods fromMaybeValue :: MaybeParser ByteString #
FromMaybeValue ByteString # |
Methods fromMaybeValue :: MaybeParser ByteString #
FromMaybeValue Text # |
Methods fromMaybeValue :: MaybeParser Text #
FromMaybeValue Text # |
Methods fromMaybeValue :: MaybeParser Text #
FromMaybeValue String # |
Methods fromMaybeValue :: MaybeParser String #
FromMaybeValue CFloat # |
Methods fromMaybeValue :: MaybeParser CFloat #
FromMaybeValue CDouble # |
Methods fromMaybeValue :: MaybeParser CDouble #
FromMaybeValue Scientific # |
Methods fromMaybeValue :: MaybeParser Scientific #
FromMaybeValue Value # |
Methods fromMaybeValue :: MaybeParser Value #
(Typeable * a, FromValue a) => FromMaybeValue [a] # |
Methods fromMaybeValue :: MaybeParser [a] #
FromValue a => FromMaybeValue (Maybe a) # |
Methods fromMaybeValue :: MaybeParser (Maybe a) #
(Typeable * a, Integral a) => FromMaybeValue (Ratio a) # |
Methods fromMaybeValue :: MaybeParser (Ratio a) #
(Typeable * a, HasResolution a) => FromMaybeValue (Fixed a) # |
Methods fromMaybeValue :: MaybeParser (Fixed a) #
(Typeable * a, RealFloat a) => FromMaybeValue (Complex a) # |
Methods fromMaybeValue :: MaybeParser (Complex a) #
(Typeable * a, FromValue a, Typeable * b, FromValue b) => FromMaybeValue (a, b) # |
Methods fromMaybeValue :: MaybeParser (a, b) #
(Typeable * a, FromValue a, Typeable * b, FromValue b, Typeable * c, FromValue c) => FromMaybeValue (a, b, c) # |
Methods fromMaybeValue :: MaybeParser (a, b, c) #
(Typeable * a, FromValue a, Typeable * b, FromValue b, Typeable * c, FromValue c, Typeable * d, FromValue d) => FromMaybeValue (a, b, c, d) # |
Methods fromMaybeValue :: MaybeParser (a, b, c, d) #

optionalValue :: ValueParser a -> MaybeParser (Maybe a) #

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 a #

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 #

An action to turn a `Value` into zero or one values of type `a`, and possibly report errors/warnings.

Instances

Monad ValueParser # |
Methods (>>=) :: ValueParser a -> (a -> ValueParser b) -> ValueParser b # (>>) :: ValueParser a -> ValueParser b -> ValueParser b # return :: a -> ValueParser a # fail :: String -> ValueParser a #
Functor ValueParser # |
Methods fmap :: (a -> b) -> ValueParser a -> ValueParser b # (<$) :: a -> ValueParser b -> ValueParser a #
MonadFail ValueParser # |
Methods fail :: String -> ValueParser a #
Applicative ValueParser # |
Methods pure :: a -> ValueParser a # (<*>) :: ValueParser (a -> b) -> ValueParser a -> ValueParser b # (*>) :: ValueParser a -> ValueParser b -> ValueParser b # (<*) :: ValueParser a -> ValueParser b -> ValueParser a #
Alternative ValueParser # |
Methods empty :: ValueParser a # (<|>) :: ValueParser a -> ValueParser a -> ValueParser a # some :: ValueParser a -> ValueParser [a] # many :: ValueParser a -> ValueParser [a] #

runValueParser :: ValueParser a -> Value -> (Maybe a, [ConversionError]) #

class FromValue a where #

Minimal complete definition

fromValue

Methods

fromValue :: ValueParser a #

Instances

FromValue Bool # |
Methods fromValue :: ValueParser Bool #
FromValue Char # |
Methods fromValue :: ValueParser Char #
FromValue Double # |
Methods fromValue :: ValueParser Double #
FromValue Float # |
Methods fromValue :: ValueParser Float #
FromValue Int # |
Methods fromValue :: ValueParser Int #
FromValue Int8 # |
Methods fromValue :: ValueParser Int8 #
FromValue Int16 # |
Methods fromValue :: ValueParser Int16 #
FromValue Int32 # |
Methods fromValue :: ValueParser Int32 #
FromValue Int64 # |
Methods fromValue :: ValueParser Int64 #
FromValue Integer # |
Methods fromValue :: ValueParser Integer #
FromValue Word # |
Methods fromValue :: ValueParser Word #
FromValue Word8 # |
Methods fromValue :: ValueParser Word8 #
FromValue Word16 # |
Methods fromValue :: ValueParser Word16 #
FromValue Word32 # |
Methods fromValue :: ValueParser Word32 #
FromValue Word64 # |
Methods fromValue :: ValueParser Word64 #
FromValue ByteString # |
Methods fromValue :: ValueParser ByteString #
FromValue ByteString # |
Methods fromValue :: ValueParser ByteString #
FromValue Text # |
Methods fromValue :: ValueParser Text #
FromValue Text # |
Methods fromValue :: ValueParser Text #
FromValue String # |
Methods fromValue :: ValueParser String #
FromValue CFloat # |
Methods fromValue :: ValueParser CFloat #
FromValue CDouble # |
Methods fromValue :: ValueParser CDouble #
FromValue Scientific # |
Methods fromValue :: ValueParser Scientific #
FromValue Value # |
Methods fromValue :: ValueParser Value #
(Typeable * a, FromValue a) => FromValue [a] # |
Methods fromValue :: ValueParser [a] #
(Typeable * a, Integral a) => FromValue (Ratio a) # |
Methods fromValue :: ValueParser (Ratio a) #
(Typeable * a, HasResolution a) => FromValue (Fixed a) # |
Methods fromValue :: ValueParser (Fixed a) #
(Typeable * a, RealFloat a) => FromValue (Complex a) # |
Methods fromValue :: ValueParser (Complex a) #
(Typeable * a, FromValue a, Typeable * b, FromValue b) => FromValue (a, b) # |
Methods fromValue :: ValueParser (a, b) #
(Typeable * a, FromValue a, Typeable * b, FromValue b, Typeable * c, FromValue c) => FromValue (a, b, c) # |
Methods fromValue :: ValueParser (a, b, c) #
(Typeable * a, FromValue a, Typeable * b, FromValue b, Typeable * c, FromValue c, Typeable * d, FromValue d) => FromValue (a, b, c, d) # |
Methods fromValue :: ValueParser (a, b, c, d) #

data ListParser a #

An action to turn a `[`Value`]` into zero or one values of type `a`, and possibly report errors/warnings.

Instances

Monad ListParser # |
Methods (>>=) :: ListParser a -> (a -> ListParser b) -> ListParser b # (>>) :: ListParser a -> ListParser b -> ListParser b # return :: a -> ListParser a # fail :: String -> ListParser a #
Functor ListParser # |
Methods fmap :: (a -> b) -> ListParser a -> ListParser b # (<$) :: a -> ListParser b -> ListParser a #
MonadFail ListParser # |
Methods fail :: String -> ListParser a #
Applicative ListParser # |
Methods pure :: a -> ListParser a # (<*>) :: ListParser (a -> b) -> ListParser a -> ListParser b # (*>) :: ListParser a -> ListParser b -> ListParser b # (<*) :: ListParser a -> ListParser b -> ListParser a #
Alternative ListParser # |
Methods empty :: ListParser a # (<|>) :: ListParser a -> ListParser a -> ListParser a # some :: ListParser a -> ListParser [a] # many :: ListParser a -> ListParser [a] #

class FromListValue a where #

Minimal complete definition

fromListValue

Methods

fromListValue :: ListParser a #

Instances

(Typeable * a, FromValue a, Typeable * b, FromValue b) => FromListValue (a, b) # |
Methods fromListValue :: ListParser (a, b) #
(Typeable * a, FromValue a, Typeable * b, FromValue b, Typeable * c, FromValue c) => FromListValue (a, b, c) # |
Methods fromListValue :: ListParser (a, b, c) #
(Typeable * a, FromValue a, Typeable * b, FromValue b, Typeable * c, FromValue c, Typeable * d, FromValue d) => FromListValue (a, b, c, d) # |
Methods fromListValue :: ListParser (a, b, c, d) #

listValue :: forall a. Typeable a => ListParser a -> ValueParser a #

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 a #

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 a #

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 #

Constructors

ConversionError |
Fields conversionErrorLoc :: Text conversionErrorWhy :: ConversionErrorWhy conversionErrorVal :: !(Maybe Value) conversionErrorType :: !(Maybe TypeRep) conversionErrorMsg :: !(Maybe Text)

Instances

Eq ConversionError # |
Methods (==) :: ConversionError -> ConversionError -> Bool # (/=) :: ConversionError -> ConversionError -> Bool #
Show ConversionError # |
Methods showsPrec :: Int -> ConversionError -> ShowS # show :: ConversionError -> String # showList :: [ConversionError] -> ShowS #
Exception ConversionError # |
Methods toException :: ConversionError -> SomeException # fromException :: SomeException -> Maybe ConversionError # displayException :: ConversionError -> String #

data ConversionErrorWhy #

Constructors

MissingValue |
ExtraValues |
ExhaustedValues |
TypeError |
ValueError |
MonadFail |
OtherError |

Instances

Eq ConversionErrorWhy # |
Methods (==) :: ConversionErrorWhy -> ConversionErrorWhy -> Bool # (/=) :: ConversionErrorWhy -> ConversionErrorWhy -> Bool #
Show ConversionErrorWhy # |
Methods showsPrec :: Int -> ConversionErrorWhy -> ShowS # show :: ConversionErrorWhy -> String # showList :: [ConversionErrorWhy] -> ShowS #

defaultConversionError :: ConversionError #

# Assorted primitive value parsers

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 #