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

Toml.Schema.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 warn and warnTable (depending on what) context you're in. These warnings can provide useful feedback about problematic values or keys that might be unused now but were perhaps meaningful in an old version of a configuration file.

Toml.Schema.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' l -> Matcher l a Source #

Convert a Value or report an error message

listFromValue :: Value' l -> Matcher l [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.Schema.FromValue

FromValue Int32 Source # 
Instance details

Defined in Toml.Schema.FromValue

FromValue Int64 Source # 
Instance details

Defined in Toml.Schema.FromValue

FromValue Int8 Source # 
Instance details

Defined in Toml.Schema.FromValue

FromValue Word16 Source # 
Instance details

Defined in Toml.Schema.FromValue

FromValue Word32 Source # 
Instance details

Defined in Toml.Schema.FromValue

FromValue Word64 Source # 
Instance details

Defined in Toml.Schema.FromValue

FromValue Word8 Source # 
Instance details

Defined in Toml.Schema.FromValue

FromValue Text Source #

Matches string literals

Instance details

Defined in Toml.Schema.FromValue

FromValue Text Source #

Matches string literals

Instance details

Defined in Toml.Schema.FromValue

FromValue Day Source #

Matches local date literals

Instance details

Defined in Toml.Schema.FromValue

FromValue LocalTime Source #

Matches local date-time literals

Instance details

Defined in Toml.Schema.FromValue

FromValue TimeOfDay Source #

Matches local time literals

Instance details

Defined in Toml.Schema.FromValue

FromValue ZonedTime Source #

Matches offset date-time literals

Instance details

Defined in Toml.Schema.FromValue

FromValue Table Source # 
Instance details

Defined in Toml.Schema.FromValue

FromValue Value Source #

Matches all values, used for pass-through

Instance details

Defined in Toml.Schema.FromValue

FromValue Integer Source #

Matches integer values

Instance details

Defined in Toml.Schema.FromValue

FromValue Natural Source #

Matches non-negative integer values

Instance details

Defined in Toml.Schema.FromValue

FromValue Bool Source #

Matches true and false

Instance details

Defined in Toml.Schema.FromValue

FromValue Char Source #

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

Instance details

Defined in Toml.Schema.FromValue

FromValue Double Source #

Matches floating-point and integer values

Instance details

Defined in Toml.Schema.FromValue

FromValue Float Source #

Matches floating-point and integer values

Instance details

Defined in Toml.Schema.FromValue

FromValue Int Source # 
Instance details

Defined in Toml.Schema.FromValue

FromValue Word Source # 
Instance details

Defined in Toml.Schema.FromValue

FromValue a => FromValue (NonEmpty a) Source #

Matches non-empty arrays or reports an error.

Instance details

Defined in Toml.Schema.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.

Instance details

Defined in Toml.Schema.FromValue

FromValue a => FromValue (Seq a) Source #

Matches arrays

Instance details

Defined in Toml.Schema.FromValue

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

Instance derived using genericFromArray

Instance details

Defined in Toml.Schema.Generic

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

Instance derived using genericParseTable

Instance details

Defined in Toml.Schema.Generic

FromValue a => FromValue [a] Source #

Implemented in terms of listFromValue

Instance details

Defined in Toml.Schema.FromValue

Methods

fromValue :: Value' l -> Matcher l [a] Source #

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

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

Defined in Toml.Schema.FromValue

Methods

fromValue :: Value' l -> Matcher l (Map k v) Source #

listFromValue :: Value' l -> Matcher l [Map k v] Source #

class FromKey a where Source #

Convert from a table key

Methods

fromKey :: l -> Text -> Matcher l a Source #

Instances

Instances details
FromKey Text Source #

Matches all strings

Instance details

Defined in Toml.Schema.FromValue

Methods

fromKey :: l -> Text -> Matcher l Text Source #

FromKey Text Source #

Matches all strings

Instance details

Defined in Toml.Schema.FromValue

Methods

fromKey :: l -> Text0 -> Matcher l Text Source #

a ~ Char => FromKey [a] Source #

Matches all strings

Instance details

Defined in Toml.Schema.FromValue

Methods

fromKey :: l -> Text -> Matcher l [a] Source #

Containers

mapOf Source #

Arguments

:: Ord k 
=> (l -> Text -> Matcher l k)

key matcher

-> (Text -> Value' l -> Matcher l v)

value matcher

-> Value' l 
-> Matcher l (Map k v) 

Table matching function used to help implement fromValue for tables. Key matching function is given the annotation of the key for error reporting. Value matching function is given the key in case values can depend on their keys.

listOf :: (Int -> Value' l -> Matcher l a) -> Value' l -> Matcher l [a] Source #

List matching function used to help implemented fromValue for arrays. The element matching function is given the list index in case values can depend on their index.

Tables

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

Used to derive a fromValue implementation from a ParseTable matcher.

reqKey :: FromValue a => Text -> ParseTable l a Source #

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

reqKey key = reqKeyOf key fromValue

reqKeyOf Source #

Arguments

:: Text

key

-> (Value' l -> Matcher l a)

value matcher

-> ParseTable l a 

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

See pickKey for more complex cases.

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

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

optKey key = optKeyOf key fromValue

optKeyOf Source #

Arguments

:: Text

key

-> (Value' l -> Matcher l a)

value matcher

-> ParseTable l (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.

Errors

typeError Source #

Arguments

:: String

expected type

-> Value' l

actual value

-> Matcher l a 

Report a type error