toml-parser-1.1.0.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 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

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 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 [a] Source #

Implemented in terms of listFromValue

Instance details

Defined in Toml.FromValue

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

Defined in Toml.FromValue

class FromValue a => FromTable a where Source #

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

Methods

fromTable :: Table -> Matcher a Source #

Convert a Table or report an error message

Instances

Instances details
(Ord k, IsString k, FromValue v) => FromTable (Map k v) Source # 
Instance details

Defined in Toml.FromValue

Methods

fromTable :: Table -> Matcher (Map k v) Source #

defaultTableFromValue :: FromTable a => Value -> Matcher a Source #

Derive fromValue implementation from fromTable

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 Result 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.

Constructors

Failure [String] 
Success [String] a 

Instances

Instances details
Read a => Read (Result a) Source # 
Instance details

Defined in Toml.FromValue.Matcher

Show a => Show (Result a) Source # 
Instance details

Defined in Toml.FromValue.Matcher

Methods

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

show :: Result a -> String #

showList :: [Result a] -> ShowS #

Eq a => Eq (Result a) Source # 
Instance details

Defined in Toml.FromValue.Matcher

Methods

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

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

Ord a => Ord (Result a) Source # 
Instance details

Defined in Toml.FromValue.Matcher

Methods

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

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

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

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

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

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

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

runMatcher :: Matcher a -> Result a Source #

Run a Matcher with an empty scope.

withScope :: String -> Matcher a -> Matcher a Source #

Run a Matcher with a locally extended scope.

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, reqKey, 'rej

Instances

Instances details
MonadFail ParseTable Source # 
Instance details

Defined in Toml.FromValue

Methods

fail :: String -> ParseTable a #

Alternative ParseTable Source # 
Instance details

Defined in Toml.FromValue

Applicative ParseTable Source # 
Instance details

Defined in Toml.FromValue

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

Methods

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

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

Monad ParseTable Source # 
Instance details

Defined in Toml.FromValue

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

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.