toml-parser-1.3.2.0: TOML 1.0.0 parser
Copyright(c) Eric Mertens 2023
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Toml.FromValue

Description

Use FromValue to define a transformation from some Value to an application domain type.

Use ParseTable to help build FromValue instances that match tables. It will make it easy to track which table keys have been used and which are left over.

Warnings can be emitted using warning and warnTable (depending on what) context you're in. These warnings can provide useful feedback about problematic decodings or keys that might be unused now but were perhaps meaningful in an old version of a configuration file.

Toml.FromValue.Generic can be used to derive instances of FromValue automatically for record types.

Synopsis

Deserialization classes

class FromValue a where Source #

Class for types that can be decoded from a TOML value.

Minimal complete definition

fromValue

Methods

fromValue :: Value -> Matcher a Source #

Convert a Value or report an error message

listFromValue :: Value -> Matcher [a] Source #

Used to implement instance for '[]'. Most implementations rely on the default implementation.

Instances

Instances details
FromValue Int16 Source # 
Instance details

Defined in Toml.FromValue

FromValue Int32 Source # 
Instance details

Defined in Toml.FromValue

FromValue Int64 Source # 
Instance details

Defined in Toml.FromValue

FromValue Int8 Source # 
Instance details

Defined in Toml.FromValue

FromValue Word16 Source # 
Instance details

Defined in Toml.FromValue

FromValue Word32 Source # 
Instance details

Defined in Toml.FromValue

FromValue Word64 Source # 
Instance details

Defined in Toml.FromValue

FromValue Word8 Source # 
Instance details

Defined in Toml.FromValue

FromValue Text Source #

Matches string literals

Since: 1.2.1.0

Instance details

Defined in Toml.FromValue

FromValue Text Source #

Matches string literals

Since: 1.2.1.0

Instance details

Defined in Toml.FromValue

FromValue Day Source #

Matches local date literals

Instance details

Defined in Toml.FromValue

FromValue LocalTime Source #

Matches local date-time literals

Instance details

Defined in Toml.FromValue

FromValue TimeOfDay Source #

Matches local time literals

Instance details

Defined in Toml.FromValue

FromValue ZonedTime Source #

Matches offset date-time literals

Instance details

Defined in Toml.FromValue

FromValue Value Source #

Matches all values, used for pass-through

Instance details

Defined in Toml.FromValue

FromValue Integer Source #

Matches integer values

Instance details

Defined in Toml.FromValue

FromValue Natural Source #

Matches non-negative integer values

Instance details

Defined in Toml.FromValue

FromValue Bool Source #

Matches true and false

Instance details

Defined in Toml.FromValue

FromValue Char Source #

Matches single-character strings with fromValue and arbitrary strings with listFromValue to support String

Instance details

Defined in Toml.FromValue

FromValue Double Source #

Matches floating-point and integer values

Instance details

Defined in Toml.FromValue

FromValue Float Source #

Matches floating-point and integer values

Instance details

Defined in Toml.FromValue

FromValue Int Source # 
Instance details

Defined in Toml.FromValue

FromValue Word Source # 
Instance details

Defined in Toml.FromValue

FromValue a => FromValue (NonEmpty a) Source #

Matches non-empty arrays or reports an error.

Since: 1.3.0.0

Instance details

Defined in Toml.FromValue

Integral a => FromValue (Ratio a) Source #

Matches floating-point and integer values.

TOML specifies Floats should be implemented as IEEE 754 binary64 values. so note that the given Rational will be converted from a double representation and will often be an approximation rather than the exact value.

Since: 1.3.0.0

Instance details

Defined in Toml.FromValue

FromValue a => FromValue (Seq a) Source #

Matches arrays

Since: 1.3.0.0

Instance details

Defined in Toml.FromValue

(Generic a, GFromArray (Rep a)) => FromValue (GenericTomlArray a) Source #

Instance derived using genericFromArray

Instance details

Defined in Toml.Generic

(Generic a, GParseTable (Rep a)) => FromValue (GenericTomlTable a) Source #

Instance derived using genericParseTable

Instance details

Defined in Toml.Generic

FromValue a => FromValue [a] Source #

Implemented in terms of listFromValue

Instance details

Defined in Toml.FromValue

(Ord k, FromKey k, FromValue v) => FromValue (Map k v) Source # 
Instance details

Defined in Toml.FromValue

class FromKey a where Source #

Convert from a table key

Since: 1.3.0.0

Methods

fromKey :: String -> Matcher a Source #

Instances

Instances details
FromKey Text Source #

Matches all strings

Since: 1.3.0.0

Instance details

Defined in Toml.FromValue

FromKey Text Source #

Matches all strings

Since: 1.3.0.0

Instance details

Defined in Toml.FromValue

a ~ Char => FromKey [a] Source #

Matches all strings

Since: 1.3.0.0

Instance details

Defined in Toml.FromValue

Methods

fromKey :: String -> Matcher [a] Source #

Matcher

data Matcher a Source #

Computations that result in a Result and which track a list of nested contexts to assist in generating warnings and error messages.

Use withScope to run a Matcher in a new, nested scope.

Instances

Instances details
MonadFail Matcher Source #

Fail with an error message annotated to the current location.

Instance details

Defined in Toml.FromValue.Matcher

Methods

fail :: String -> Matcher a #

Alternative Matcher Source # 
Instance details

Defined in Toml.FromValue.Matcher

Methods

empty :: Matcher a #

(<|>) :: Matcher a -> Matcher a -> Matcher a #

some :: Matcher a -> Matcher [a] #

many :: Matcher a -> Matcher [a] #

Applicative Matcher Source # 
Instance details

Defined in Toml.FromValue.Matcher

Methods

pure :: a -> Matcher a #

(<*>) :: Matcher (a -> b) -> Matcher a -> Matcher b #

liftA2 :: (a -> b -> c) -> Matcher a -> Matcher b -> Matcher c #

(*>) :: Matcher a -> Matcher b -> Matcher b #

(<*) :: Matcher a -> Matcher b -> Matcher a #

Functor Matcher Source # 
Instance details

Defined in Toml.FromValue.Matcher

Methods

fmap :: (a -> b) -> Matcher a -> Matcher b #

(<$) :: a -> Matcher b -> Matcher a #

Monad Matcher Source # 
Instance details

Defined in Toml.FromValue.Matcher

Methods

(>>=) :: Matcher a -> (a -> Matcher b) -> Matcher b #

(>>) :: Matcher a -> Matcher b -> Matcher b #

return :: a -> Matcher a #

MonadPlus Matcher Source # 
Instance details

Defined in Toml.FromValue.Matcher

Methods

mzero :: Matcher a #

mplus :: Matcher a -> Matcher a -> Matcher a #

data MatchMessage Source #

A message emitted while matching a TOML value. The message is paired with the path to the value that was in focus when the message was generated. These message get used for both warnings and errors.

Since: 1.3.0.0

Constructors

MatchMessage 

Fields

data Result e a Source #

Computation outcome with error and warning messages. Multiple error messages can occur when multiple alternatives all fail. Resolving any one of the error messages could allow the computation to succeed.

Since: 1.3.0.0

Constructors

Failure [e]

error messages

Success [e] a

warning messages and result

Instances

Instances details
(Read e, Read a) => Read (Result e a) Source #

Default instance

Instance details

Defined in Toml.FromValue.Matcher

(Show e, Show a) => Show (Result e a) Source #

Default instance

Instance details

Defined in Toml.FromValue.Matcher

Methods

showsPrec :: Int -> Result e a -> ShowS #

show :: Result e a -> String #

showList :: [Result e a] -> ShowS #

(Eq e, Eq a) => Eq (Result e a) Source #

Default instance

Instance details

Defined in Toml.FromValue.Matcher

Methods

(==) :: Result e a -> Result e a -> Bool #

(/=) :: Result e a -> Result e a -> Bool #

(Ord e, Ord a) => Ord (Result e a) Source #

Default instance

Instance details

Defined in Toml.FromValue.Matcher

Methods

compare :: Result e a -> Result e a -> Ordering #

(<) :: Result e a -> Result e a -> Bool #

(<=) :: Result e a -> Result e a -> Bool #

(>) :: Result e a -> Result e a -> Bool #

(>=) :: Result e a -> Result e a -> Bool #

max :: Result e a -> Result e a -> Result e a #

min :: Result e a -> Result e a -> Result e a #

warning :: String -> Matcher () Source #

Emit a warning mentioning the current scope.

Table matching

data ParseTable a Source #

A Matcher that tracks a current set of unmatched key-value pairs from a table.

Use optKey and reqKey to extract keys.

Use getTable and setTable to override the table and implement other primitives.

Instances

Instances details
MonadFail ParseTable Source #

Implemented in terms of fail on Matcher

Instance details

Defined in Toml.FromValue.ParseTable

Methods

fail :: String -> ParseTable a #

Alternative ParseTable Source # 
Instance details

Defined in Toml.FromValue.ParseTable

Applicative ParseTable Source # 
Instance details

Defined in Toml.FromValue.ParseTable

Methods

pure :: a -> ParseTable a #

(<*>) :: ParseTable (a -> b) -> ParseTable a -> ParseTable b #

liftA2 :: (a -> b -> c) -> ParseTable a -> ParseTable b -> ParseTable c #

(*>) :: ParseTable a -> ParseTable b -> ParseTable b #

(<*) :: ParseTable a -> ParseTable b -> ParseTable a #

Functor ParseTable Source # 
Instance details

Defined in Toml.FromValue.ParseTable

Methods

fmap :: (a -> b) -> ParseTable a -> ParseTable b #

(<$) :: a -> ParseTable b -> ParseTable a #

Monad ParseTable Source # 
Instance details

Defined in Toml.FromValue.ParseTable

Methods

(>>=) :: ParseTable a -> (a -> ParseTable b) -> ParseTable b #

(>>) :: ParseTable a -> ParseTable b -> ParseTable b #

return :: a -> ParseTable a #

MonadPlus ParseTable Source # 
Instance details

Defined in Toml.FromValue.ParseTable

runParseTable :: ParseTable a -> Table -> Matcher a Source #

Run a ParseTable computation with a given starting Table. Unused tables will generate a warning. To change this behavior getTable and setTable can be used to discard or generate error messages.

parseTableFromValue :: ParseTable a -> Value -> Matcher a Source #

Used to derive a fromValue implementation from a ParseTable matcher.

reqKey :: FromValue a => String -> ParseTable a Source #

Convenience function for matching a required key with a FromValue instance.

reqKey key = reqKeyOf key fromValue

optKey :: FromValue a => String -> ParseTable (Maybe a) Source #

Convenience function for matching an optional key with a FromValue instance.

optKey key = optKeyOf key fromValue

reqKeyOf Source #

Arguments

:: String

key

-> (Value -> Matcher a)

value matcher

-> ParseTable a 

Match a table entry by key or report an error if missing.

See pickKey for more complex cases.

optKeyOf Source #

Arguments

:: String

key

-> (Value -> Matcher a)

value matcher

-> ParseTable (Maybe a) 

Match a table entry by key if it exists or return Nothing if not. If the key is defined, it is matched by the given function.

See pickKey for more complex cases.

warnTable :: String -> ParseTable () Source #

Emit a warning at the current location.

data KeyAlt a Source #

Key and value matching function

Since: 1.2.0.0

Constructors

Key String (Value -> Matcher a)

pick alternative based on key match

Else (Matcher a)

default case when no previous cases matched

pickKey :: [KeyAlt a] -> ParseTable a Source #

Take the first option from a list of table keys and matcher functions. This operation will commit to the first table key that matches. If the associated matcher fails, only that error will be propagated and the other alternatives will not be matched.

If no keys match, an error message is generated explaining which keys would have been accepted.

This is provided as an alternative to chaining multiple reqKey cases together with (<|>) because that will generate one error message for each unmatched alternative as well as the error associate with the matched alternative.

Since: 1.2.0.0

Table matching primitives

getTable :: ParseTable Table Source #

Return the remaining portion of the table being matched.

setTable :: Table -> ParseTable () Source #

Replace the remaining portion of the table being matched.

liftMatcher :: Matcher a -> ParseTable a Source #

Lift a matcher into the current table parsing context.