| Copyright | (c) Eric Mertens 2023 |
|---|---|
| License | ISC |
| Maintainer | emertens@gmail.com |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Toml.FromValue
Description
Use FromValue to define a transformation from some Value to an application
domain type.
Use FromTable to define transformations specifically from Table. These
instances are interesting because all top-level TOML values are tables,
so these are the types that work for top-level deserialization.
Use ParseTable to help build FromTable instances. 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 FromTable
automatically for record types.
Synopsis
- class FromValue a where
- class FromValue a => FromTable a where
- defaultTableFromValue :: FromTable a => Value -> Matcher a
- data Matcher a
- data Result a
- runMatcher :: Matcher a -> Result a
- withScope :: String -> Matcher a -> Matcher a
- warning :: String -> Matcher ()
- data ParseTable a
- runParseTable :: ParseTable a -> Table -> Matcher a
- optKey :: FromValue a => String -> ParseTable (Maybe a)
- reqKey :: FromValue a => String -> ParseTable a
- warnTable :: String -> ParseTable ()
- getTable :: ParseTable Table
- setTable :: Table -> ParseTable ()
Deserialization classes
class FromValue a where Source #
Class for types that can be decoded from a TOML value.
Minimal complete definition
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
class FromValue a => FromTable a where Source #
Class for types that can be decoded from a TOML table.
Matcher
Computations that result in a Result and which track a list
of nested contexts to assist in generating warnings and error
messages.
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.
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
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.
optKey :: FromValue a => String -> ParseTable (Maybe a) Source #
Match a table entry by key if it exists or return Nothing if not.
reqKey :: FromValue a => String -> ParseTable a Source #
Match a table entry by key or report an error if missing.
warnTable :: String -> ParseTable () Source #
Emit a warning at the current location.
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.