Copyright | (c) Eric Mertens 2023 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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.
Synopsis
- class FromValue a where
- class FromValue a => FromTable a where
- defaultTableFromValue :: FromTable a => Value -> Matcher a
- data Matcher a
- runMatcher :: Matcher a -> Result a
- withScope :: String -> Matcher a -> Matcher a
- warning :: String -> Matcher ()
- data Result a
- 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.
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.
results
Computation outcome with error and warning messages.
table matching
data ParseTable a Source #
A Matcher
that tracks a current set of unmatched key-value
pairs from a table.
Instances
MonadFail ParseTable Source # | |
Defined in Toml.FromValue fail :: String -> ParseTable a # | |
Applicative ParseTable Source # | |
Defined in Toml.FromValue 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 # | |
Defined in Toml.FromValue fmap :: (a -> b) -> ParseTable a -> ParseTable b # (<$) :: a -> ParseTable b -> ParseTable a # | |
Monad ParseTable Source # | |
Defined in Toml.FromValue (>>=) :: ParseTable a -> (a -> ParseTable b) -> ParseTable b # (>>) :: ParseTable a -> ParseTable b -> ParseTable b # return :: a -> ParseTable a # |
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.