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

Toml.Schema.Generic

Description

This module makes it possible to easily derive the TOML classes using the DerivingVia extension.

For example:

data Physical = Physical {
    color :: String,
    shape :: String
    }
    deriving (Eq, Show, Generic)
    deriving (ToTable, ToValue, FromValue) via GenericTomlTable Physical

These derived instances would allow you to match TOML {color="red", shape="round"} to value Physical "red" "round".

data Coord = Coord Int Int
    deriving (Eq, Show, Generic)
    deriving (ToValue, FromValue) via GenericTomlArray Physical

These derived instances would allow you to match TOML [1,2] to value Coord 1 2.

Synopsis

DerivingVia

newtype GenericTomlTable a Source #

Helper type to use GHC's DerivingVia extension to derive ToValue, ToTable, FromValue for records.

Constructors

GenericTomlTable a 

Instances

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

Instance derived using genericParseTable

Instance details

Defined in Toml.Schema.Generic

(Generic a, GToTable (Rep a)) => ToTable (GenericTomlTable a) Source #

Instance derived using genericToTable

Instance details

Defined in Toml.Schema.Generic

(Generic a, GToTable (Rep a)) => ToValue (GenericTomlTable a) Source #

Instance derived from ToTable instance using defaultTableToValue

Instance details

Defined in Toml.Schema.Generic

newtype GenericTomlArray a Source #

Helper type to use GHC's DerivingVia extension to derive ToValue, ToTable, FromValue for any product type.

Constructors

GenericTomlArray a 

Instances

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

Instance derived using genericFromArray

Instance details

Defined in Toml.Schema.Generic

(Generic a, GToArray (Rep a)) => ToValue (GenericTomlArray a) Source #

Instance derived using genericToArray

Instance details

Defined in Toml.Schema.Generic

FromValue

genericFromArray :: (Generic a, GFromArray (Rep a)) => Value' l -> Matcher l a Source #

Match a Value' as an array positionally matching field fields of a constructor to the elements of the array.

genericFromTable :: (Generic a, GParseTable (Rep a)) => Value' l -> Matcher l a Source #

Implementation of fromValue using genericParseTable to derive a match from the record field names of the target type.

class GFromArray f Source #

Supports conversion of TOML arrays into product-type values.

Minimal complete definition

gFromArray

Instances

Instances details
GFromArray (U1 :: Type -> Type) Source #

Uses no array elements

Instance details

Defined in Toml.Schema.Generic.FromValue

Methods

gFromArray :: StateT [Value' l] (Matcher l) (U1 a) Source #

(GFromArray f, GFromArray g) => GFromArray (f :*: g) Source # 
Instance details

Defined in Toml.Schema.Generic.FromValue

Methods

gFromArray :: StateT [Value' l] (Matcher l) ((f :*: g) a) Source #

FromValue a => GFromArray (K1 i a :: Type -> Type) Source # 
Instance details

Defined in Toml.Schema.Generic.FromValue

Methods

gFromArray :: StateT [Value' l] (Matcher l) (K1 i a a0) Source #

GFromArray f => GFromArray (M1 i c f) Source # 
Instance details

Defined in Toml.Schema.Generic.FromValue

Methods

gFromArray :: StateT [Value' l] (Matcher l) (M1 i c f a) Source #

class GParseTable f Source #

Supports conversion of TOML tables into record values using field selector names as TOML keys.

Minimal complete definition

gParseTable

Instances

Instances details
GParseTable (U1 :: Type -> Type) Source #

Emits empty table

Instance details

Defined in Toml.Schema.Generic.FromValue

Methods

gParseTable :: ParseTable l (U1 a) Source #

(GParseTable f, GParseTable g) => GParseTable (f :*: g) Source #

Matches left then right component

Instance details

Defined in Toml.Schema.Generic.FromValue

Methods

gParseTable :: ParseTable l ((f :*: g) a) Source #

GParseTable f => GParseTable (C1 ('MetaCons sym fix 'True) f) Source #

Ignores value constructor name - only supports record constructors

Instance details

Defined in Toml.Schema.Generic.FromValue

Methods

gParseTable :: ParseTable l (C1 ('MetaCons sym fix 'True) f a) Source #

GParseTable f => GParseTable (D1 c f) Source #

Ignores type constructor name

Instance details

Defined in Toml.Schema.Generic.FromValue

Methods

gParseTable :: ParseTable l (D1 c f a) Source #

(Selector s, FromValue a) => GParseTable (S1 s (K1 i (Maybe a) :: Type -> Type)) Source #

Omits the key from the table on nothing, includes it on just

Instance details

Defined in Toml.Schema.Generic.FromValue

Methods

gParseTable :: ParseTable l (S1 s (K1 i (Maybe a)) a0) Source #

(Selector s, FromValue a) => GParseTable (S1 s (K1 i a :: Type -> Type)) Source #

Uses record selector name as table key

Instance details

Defined in Toml.Schema.Generic.FromValue

Methods

gParseTable :: ParseTable l (S1 s (K1 i a) a0) Source #

ToValue

genericToArray :: (Generic a, GToArray (Rep a)) => a -> Value Source #

Use a record's field names to generate a Value'

genericToTable :: (Generic a, GToTable (Rep a)) => a -> Table Source #

Use a record's field names to generate a Value'

class GToArray f Source #

Convert product types to arrays positionally.

Minimal complete definition

gToArray

Instances

Instances details
(GToArray f, GToArray g) => GToArray (f :*: g) Source #

Convert left and then right

Instance details

Defined in Toml.Schema.Generic.ToValue

Methods

gToArray :: (f :*: g) a -> [Value] -> [Value] Source #

ToValue a => GToArray (K1 i a :: Type -> Type) Source #

Convert fields using ToValue instances

Instance details

Defined in Toml.Schema.Generic.ToValue

Methods

gToArray :: K1 i a a0 -> [Value] -> [Value] Source #

GToArray f => GToArray (M1 i c f) Source #

Ignore metadata

Instance details

Defined in Toml.Schema.Generic.ToValue

Methods

gToArray :: M1 i c f a -> [Value] -> [Value] Source #

class GToTable f Source #

Supports conversion of product types with field selector names to TOML values.

Minimal complete definition

gToTable

Instances

Instances details
GToTable (U1 :: Type -> Type) Source #

Emits empty table

Instance details

Defined in Toml.Schema.Generic.ToValue

Methods

gToTable :: U1 a -> [(Text, Value)] -> [(Text, Value)] Source #

GToTable (V1 :: Type -> Type) Source # 
Instance details

Defined in Toml.Schema.Generic.ToValue

Methods

gToTable :: V1 a -> [(Text, Value)] -> [(Text, Value)] Source #

(GToTable f, GToTable g) => GToTable (f :*: g) Source # 
Instance details

Defined in Toml.Schema.Generic.ToValue

Methods

gToTable :: (f :*: g) a -> [(Text, Value)] -> [(Text, Value)] Source #

GToTable f => GToTable (C1 c f) Source #

Ignores value constructor names

Instance details

Defined in Toml.Schema.Generic.ToValue

Methods

gToTable :: C1 c f a -> [(Text, Value)] -> [(Text, Value)] Source #

GToTable f => GToTable (D1 c f) Source #

Ignores type constructor names

Instance details

Defined in Toml.Schema.Generic.ToValue

Methods

gToTable :: D1 c f a -> [(Text, Value)] -> [(Text, Value)] Source #

(Selector s, ToValue a) => GToTable (S1 s (K1 i (Maybe a) :: Type -> Type)) Source #

Omits the key from the table on nothing, includes it on just

Instance details

Defined in Toml.Schema.Generic.ToValue

Methods

gToTable :: S1 s (K1 i (Maybe a)) a0 -> [(Text, Value)] -> [(Text, Value)] Source #

(Selector s, ToValue a) => GToTable (S1 s (K1 i a :: Type -> Type)) Source #

Uses record selector name as table key

Instance details

Defined in Toml.Schema.Generic.ToValue

Methods

gToTable :: S1 s (K1 i a) a0 -> [(Text, Value)] -> [(Text, Value)] Source #