toml-parser-2.0.1.0: TOML 1.0.0 parser

Copyright | (c) Eric Mertens 2024
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | None
Language | Haskell2010

Toml.Schema

Contents

- FromValue
  - Matcher
  - Tables
- ToValue
- Types
- Generics

Description

Synopsis

- class FromValue a where
  - fromValue :: Value' l -> Matcher l a
  - listFromValue :: Value' l -> Matcher l [a]
- mapOf :: Ord k => (l -> Text -> Matcher l k) -> (Text -> Value' l -> Matcher l v) -> Value' l -> Matcher l (Map k v)
- listOf :: (Int -> Value' l -> Matcher l a) -> Value' l -> Matcher l [a]
- data Matcher l a
- runMatcher :: Matcher l a -> Result (MatchMessage l) a
- runMatcherFatalWarn :: Matcher l a -> Either [MatchMessage l] a
- runMatcherIgnoreWarn :: Matcher l a -> Either [MatchMessage l] a
- data Result e a
  - = Failure [e]
  - | Success [e] a
- data MatchMessage a = MatchMessage {
  - matchAnn :: Maybe a
  - matchPath :: [Scope]
  - matchMessage :: String
  }
- data Scope
  - = ScopeIndex Int
  - | ScopeKey Text
- parseTableFromValue :: ParseTable l a -> Value' l -> Matcher l a
- parseTable :: ParseTable l a -> l -> Table' l -> Matcher l a
- getScope :: Matcher a [Scope]
- warn :: String -> Matcher a ()
- warnAt :: l -> String -> Matcher l ()
- failAt :: l -> String -> Matcher l a
- getTable :: ParseTable l (Table' l)
- setTable :: Table' l -> ParseTable l ()
- data ParseTable l a
- reqKey :: FromValue a => Text -> ParseTable l a
- optKey :: FromValue a => Text -> ParseTable l (Maybe a)
- reqKeyOf :: Text -> (Value' l -> Matcher l a) -> ParseTable l a
- optKeyOf :: Text -> (Value' l -> Matcher l a) -> ParseTable l (Maybe a)
- pickKey :: [KeyAlt l a] -> ParseTable l a
- data KeyAlt l a
  - = Key Text (Value' l -> Matcher l a)
  - | Else (Matcher l a)
- warnTable :: String -> ParseTable l ()
- warnTableAt :: l -> String -> ParseTable l ()
- failTableAt :: l -> String -> ParseTable l a
- liftMatcher :: Matcher l a -> ParseTable l a
- class ToValue a where
  - toValue :: a -> Value
  - toValueList :: [a] -> Value
- class ToValue a => ToTable a where
  - toTable :: a -> Table
- table :: [(Text, Value)] -> Table
- (.=) :: ToValue a => Text -> a -> (Text, Value)
- defaultTableToValue :: ToTable a => a -> Value
- type Value = Value' ()
- data Value' a where
  - Integer' a Integer
  - Double' a Double
  - List' a [Value' a]
  - Table' a (Table' a)
  - Bool' a Bool
  - Text' a Text
  - TimeOfDay' a TimeOfDay
  - ZonedTime' a ZonedTime
  - LocalTime' a LocalTime
  - Day' a Day
  - pattern Bool :: Bool -> Value
  - pattern Double :: Double -> Value
  - pattern List :: [Value] -> Value
  - pattern Integer :: Integer -> Value
  - pattern Text :: Text -> Value
  - pattern Table :: Table -> Value
  - pattern Day :: Day -> Value
  - pattern TimeOfDay :: TimeOfDay -> Value
  - pattern LocalTime :: LocalTime -> Value
  - pattern ZonedTime :: ZonedTime -> Value
- type Table = Table' ()
- newtype Table' a = MkTable (Map Text (a, Value' a))
- newtype GenericTomlArray a = GenericTomlArray a
- newtype GenericTomlTable a = GenericTomlTable a
- genericFromTable :: (Generic a, GParseTable (Rep a)) => Value' l -> Matcher l a
- genericFromArray :: (Generic a, GFromArray (Rep a)) => Value' l -> Matcher l a
- genericToArray :: (Generic a, GToArray (Rep a)) => a -> Value
- genericToTable :: (Generic a, GToTable (Rep a)) => a -> Table

# FromValue

class FromValue a where #

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

Minimal complete definition

fromValue

Methods

fromValue :: Value' l -> Matcher l a #

Convert a `Value` or report an error message

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

Used to implement instance for `[]`. Most implementations rely on the default implementation.

#### Instances

Instances details

FromValue Int16 # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Int16 # listFromValue :: Value' l -> Matcher l [Int16] #
FromValue Int32 # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Int32 # listFromValue :: Value' l -> Matcher l [Int32] #
FromValue Int64 # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Int64 # listFromValue :: Value' l -> Matcher l [Int64] #
FromValue Int8 # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Int8 # listFromValue :: Value' l -> Matcher l [Int8] #
FromValue Word16 # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Word16 # listFromValue :: Value' l -> Matcher l [Word16] #
FromValue Word32 # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Word32 # listFromValue :: Value' l -> Matcher l [Word32] #
FromValue Word64 # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Word64 # listFromValue :: Value' l -> Matcher l [Word64] #
FromValue Word8 # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Word8 # listFromValue :: Value' l -> Matcher l [Word8] #
FromValue Text # | Matches string literals
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Text # listFromValue :: Value' l -> Matcher l [Text] #
FromValue Text # | Matches string literals
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Text # listFromValue :: Value' l -> Matcher l [Text] #
FromValue Day # | Matches local date literals
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Day # listFromValue :: Value' l -> Matcher l [Day] #
FromValue UTCTime # | Matches offset date-time literals and converts to UTC
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l UTCTime # listFromValue :: Value' l -> Matcher l [UTCTime] #
FromValue LocalTime # | Matches local date-time literals
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l LocalTime # listFromValue :: Value' l -> Matcher l [LocalTime] #
FromValue TimeOfDay # | Matches local time literals
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l TimeOfDay # listFromValue :: Value' l -> Matcher l [TimeOfDay] #
FromValue ZonedTime # | Matches offset date-time literals
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l ZonedTime # listFromValue :: Value' l -> Matcher l [ZonedTime] #
FromValue Table # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Table # listFromValue :: Value' l -> Matcher l [Table] #
FromValue Value # | Matches all values, used for pass-through
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Value # listFromValue :: Value' l -> Matcher l [Value] #
FromValue Integer # | Matches integer values
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Integer # listFromValue :: Value' l -> Matcher l [Integer] #
FromValue Natural # | Matches non-negative integer values
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Natural # listFromValue :: Value' l -> Matcher l [Natural] #
FromValue Bool # | Matches `true` and `false`
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Bool # listFromValue :: Value' l -> Matcher l [Bool] #
FromValue Char # | Matches single-character strings with `fromValue` and arbitrary strings with `listFromValue` to support `String`
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Char # listFromValue :: Value' l -> Matcher l [Char] #
FromValue Double # | Matches floating-point and integer values
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Double # listFromValue :: Value' l -> Matcher l [Double] #
FromValue Float # | Matches floating-point and integer values
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Float # listFromValue :: Value' l -> Matcher l [Float] #
FromValue Int # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Int # listFromValue :: Value' l -> Matcher l [Int] #
FromValue Word # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Word # listFromValue :: Value' l -> Matcher l [Word] #
FromValue a => FromValue (Seq a) # | Matches arrays
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l (Seq a) # listFromValue :: Value' l -> Matcher l [Seq a] #
FromValue a => FromValue (NonEmpty a) # | Matches non-empty arrays or reports an error.
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l (NonEmpty a) # listFromValue :: Value' l -> Matcher l [NonEmpty a] #
Integral a => FromValue (Ratio a) # | 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 Methods fromValue :: Value' l -> Matcher l (Ratio a) # listFromValue :: Value' l -> Matcher l [Ratio a] #
(Generic a, GFromArray (Rep a)) => FromValue (GenericTomlArray a) # | Instance derived using `genericFromArray`
Instance details Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlArray a) # listFromValue :: Value' l -> Matcher l [GenericTomlArray a] #
(Generic a, GParseTable (Rep a)) => FromValue (GenericTomlTable a) # | Instance derived using `genericParseTable`
Instance details Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlTable a) # listFromValue :: Value' l -> Matcher l [GenericTomlTable a] #
FromValue a => FromValue [a] # | Implemented in terms of `listFromValue`
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l [a] # listFromValue :: Value' l -> Matcher l [[a]] #
(Ord k, FromKey k, FromValue v) => FromValue (Map k v) # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l (Map k v) # listFromValue :: Value' l -> Matcher l [Map k v] #

mapOf #

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] #

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.

## Matcher

data Matcher l a #

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

Alternative (Matcher a) # |
Instance details Defined in Toml.Schema.Matcher Methods empty :: Matcher a a0 # (<|>) :: Matcher a a0 -> Matcher a a0 -> Matcher a a0 # some :: Matcher a a0 -> Matcher a [a0] # many :: Matcher a a0 -> Matcher a [a0] #
Applicative (Matcher a) # |
Instance details Defined in Toml.Schema.Matcher Methods pure :: a0 -> Matcher a a0 # (<*>) :: Matcher a (a0 -> b) -> Matcher a a0 -> Matcher a b # liftA2 :: (a0 -> b -> c) -> Matcher a a0 -> Matcher a b -> Matcher a c # (*>) :: Matcher a a0 -> Matcher a b -> Matcher a b # (<*) :: Matcher a a0 -> Matcher a b -> Matcher a a0 #
Functor (Matcher a) # |
Instance details Defined in Toml.Schema.Matcher Methods fmap :: (a0 -> b) -> Matcher a a0 -> Matcher a b # (<$) :: a0 -> Matcher a b -> Matcher a a0 #
Monad (Matcher a) # |
Instance details Defined in Toml.Schema.Matcher Methods (>>=) :: Matcher a a0 -> (a0 -> Matcher a b) -> Matcher a b # (>>) :: Matcher a a0 -> Matcher a b -> Matcher a b # return :: a0 -> Matcher a a0 #
MonadPlus (Matcher a) # |
Instance details Defined in Toml.Schema.Matcher Methods mzero :: Matcher a a0 # mplus :: Matcher a a0 -> Matcher a a0 -> Matcher a a0 #
MonadFail (Matcher a) # | Fail with an error message without an annotation.
Instance details Defined in Toml.Schema.Matcher Methods fail :: String -> Matcher a a0 #

runMatcher :: Matcher l a -> Result (MatchMessage l) a #

Run a `Matcher` with an empty scope.

runMatcherFatalWarn :: Matcher l a -> Either [MatchMessage l] a #

Run `Matcher` and treat warnings as errors.

runMatcherIgnoreWarn :: Matcher l a -> Either [MatchMessage l] a #

Run `Matcher` and ignore warnings.

data Result e a #

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 [e] | error messages
Success [e] a | warning messages and result

#### Instances

Instances details

(Read e, Read a) => Read (Result e a) # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods readsPrec :: Int -> ReadS (Result e a) # readList :: ReadS [Result e a] # readPrec :: ReadPrec (Result e a) # readListPrec :: ReadPrec [Result e a] #
(Show e, Show a) => Show (Result e a) # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods showsPrec :: Int -> Result e a -> ShowS # show :: Result e a -> String # showList :: [Result e a] -> ShowS #
(Eq e, Eq a) => Eq (Result e a) # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods (==) :: Result e a -> Result e a -> Bool # (/=) :: Result e a -> Result e a -> Bool #
(Ord e, Ord a) => Ord (Result e a) # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods compare :: Result e a -> Result e a -> Ordering # (<) :: Result e a -> Result e a -> Bool # (<=) :: Result e a -> Result e a -> Bool # (>) :: Result e a -> Result e a -> Bool # (>=) :: Result e a -> Result e a -> Bool # max :: Result e a -> Result e a -> Result e a # min :: Result e a -> Result e a -> Result e a #

data MatchMessage a #

A message emitted while matching a TOML value. The message is paired with the path to the value that was in focus when the message was generated. These message get used for both warnings and errors.

For a convenient way to render these to a string, see `prettyMatchMessage`.

Constructors

MatchMessage |

Fields

- matchAnn :: Maybe a
- matchPath :: [Scope]

  path to message location

- matchMessage :: String

  error and warning message body

#### Instances

Instances details

Functor MatchMessage # |
Instance details Defined in Toml.Schema.Matcher Methods fmap :: (a -> b) -> MatchMessage a -> MatchMessage b # (<$) :: a -> MatchMessage b -> MatchMessage a #
Foldable MatchMessage # |

Instance details

Defined in Toml.Schema.Matcher

Methods

fold :: Monoid m => MatchMessage m -> m #

foldMap :: Monoid m => (a -> m) -> MatchMessage a -> m #

foldMap' :: Monoid m => (a -> m) -> MatchMessage a -> m #

foldr :: (a -> b -> b) -> b -> MatchMessage a -> b #

foldr' :: (a -> b -> b) -> b -> MatchMessage a -> b #

foldl :: (b -> a -> b) -> b -> MatchMessage a -> b #

foldl' :: (b -> a -> b) -> b -> MatchMessage a -> b #

foldr1 :: (a -> a -> a) -> MatchMessage a -> a #

foldl1 :: (a -> a -> a) -> MatchMessage a -> a #

toList :: MatchMessage a -> [a] #

null :: MatchMessage a -> Bool #

length :: MatchMessage a -> Int #

elem :: Eq a => a -> MatchMessage a -> Bool #

maximum :: Ord a => MatchMessage a -> a #

minimum :: Ord a => MatchMessage a -> a #

sum :: Num a => MatchMessage a -> a #

product :: Num a => MatchMessage a -> a #

Traversable MatchMessage # |
Instance details Defined in Toml.Schema.Matcher Methods traverse :: Applicative f => (a -> f b) -> MatchMessage a -> f (MatchMessage b) # sequenceA :: Applicative f => MatchMessage (f a) -> f (MatchMessage a) # mapM :: Monad m => (a -> m b) -> MatchMessage a -> m (MatchMessage b) # sequence :: Monad m => MatchMessage (m a) -> m (MatchMessage a) #
Read a => Read (MatchMessage a) # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods readsPrec :: Int -> ReadS (MatchMessage a) # readList :: ReadS [MatchMessage a] # readPrec :: ReadPrec (MatchMessage a) # readListPrec :: ReadPrec [MatchMessage a] #
Show a => Show (MatchMessage a) # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods showsPrec :: Int -> MatchMessage a -> ShowS # show :: MatchMessage a -> String # showList :: [MatchMessage a] -> ShowS #
Eq a => Eq (MatchMessage a) # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods (==) :: MatchMessage a -> MatchMessage a -> Bool # (/=) :: MatchMessage a -> MatchMessage a -> Bool #
Ord a => Ord (MatchMessage a) # | Default instance

Instance details

Defined in Toml.Schema.Matcher

Methods

compare :: MatchMessage a -> MatchMessage a -> Ordering #

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

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

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

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

max :: MatchMessage a -> MatchMessage a -> MatchMessage a #

min :: MatchMessage a -> MatchMessage a -> MatchMessage a #

data Scope #

Scopes for TOML message.

Constructors

ScopeIndex Int | zero-based array index
ScopeKey Text | key in a table

#### Instances

Instances details

Read Scope # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods readsPrec :: Int -> ReadS Scope # readList :: ReadS [Scope] # readPrec :: ReadPrec Scope # readListPrec :: ReadPrec [Scope] #
Show Scope # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods showsPrec :: Int -> Scope -> ShowS # show :: Scope -> String # showList :: [Scope] -> ShowS #
Eq Scope # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods (==) :: Scope -> Scope -> Bool # (/=) :: Scope -> Scope -> Bool #
Ord Scope # | Default instance
Instance details Defined in Toml.Schema.Matcher Methods compare :: Scope -> Scope -> Ordering # (<) :: Scope -> Scope -> Bool # (<=) :: Scope -> Scope -> Bool # (>) :: Scope -> Scope -> Bool # (>=) :: Scope -> Scope -> Bool # max :: Scope -> Scope -> Scope # min :: Scope -> Scope -> Scope #

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

Used to derive a `fromValue` implementation from a `ParseTable` matcher.

parseTable :: ParseTable l a -> l -> Table' l -> Matcher l a #

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.

getScope :: Matcher a [Scope] #

Get the current list of scopes.

warn :: String -> Matcher a () #

Emit a warning without an annotation.

warnAt :: l -> String -> Matcher l () #

Emit a warning mentioning the given annotation.

failAt :: l -> String -> Matcher l a #

Terminate the match with an error mentioning the given annotation.

getTable :: ParseTable l (Table' l) #

Return the remaining portion of the table being matched.

setTable :: Table' l -> ParseTable l () #

Replace the remaining portion of the table being matched.

## Tables

data ParseTable l a #

Parser 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

Instances details

Alternative (ParseTable l) # |
Instance details Defined in Toml.Schema.ParseTable Methods empty :: ParseTable l a # (<|>) :: ParseTable l a -> ParseTable l a -> ParseTable l a # some :: ParseTable l a -> ParseTable l [a] # many :: ParseTable l a -> ParseTable l [a] #
Applicative (ParseTable l) # |
Instance details Defined in Toml.Schema.ParseTable Methods pure :: a -> ParseTable l a # (<*>) :: ParseTable l (a -> b) -> ParseTable l a -> ParseTable l b # liftA2 :: (a -> b -> c) -> ParseTable l a -> ParseTable l b -> ParseTable l c # (*>) :: ParseTable l a -> ParseTable l b -> ParseTable l b # (<*) :: ParseTable l a -> ParseTable l b -> ParseTable l a #
Functor (ParseTable l) # |
Instance details Defined in Toml.Schema.ParseTable Methods fmap :: (a -> b) -> ParseTable l a -> ParseTable l b # (<$) :: a -> ParseTable l b -> ParseTable l a #
Monad (ParseTable l) # |
Instance details Defined in Toml.Schema.ParseTable Methods (>>=) :: ParseTable l a -> (a -> ParseTable l b) -> ParseTable l b # (>>) :: ParseTable l a -> ParseTable l b -> ParseTable l b # return :: a -> ParseTable l a #
MonadPlus (ParseTable l) # |
Instance details Defined in Toml.Schema.ParseTable Methods mzero :: ParseTable l a # mplus :: ParseTable l a -> ParseTable l a -> ParseTable l a #
MonadFail (ParseTable l) # | Implemented in terms of `fail` on `Matcher`
Instance details Defined in Toml.Schema.ParseTable Methods fail :: String -> ParseTable l a #

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

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

    reqKey key = reqKeyOf key fromValue

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

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

    optKey key = optKeyOf key fromValue

reqKeyOf #

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.

optKeyOf #

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.

pickKey :: [KeyAlt l a] -> ParseTable l a #

Take the first option from a list of table keys and matcher functions. This operation will commit to the first table key that matches. If the associated matcher fails, only that error will be propagated and the other alternatives will not be matched.

If no keys match, an error message is generated explaining which keys would have been accepted.

This is provided as an alternative to chaining multiple `reqKey` cases together with `Alternative` which will fall-through as a result of any failure to the next case.

data KeyAlt l a #

Key and value matching function

Constructors

Key Text (Value' l -> Matcher l a) | pick alternative based on key match
Else (Matcher l a) | default case when no previous cases matched

warnTable :: String -> ParseTable l () #

Emit a warning without an annotation.

warnTableAt :: l -> String -> ParseTable l () #

Emit a warning with the given annotation.

failTableAt :: l -> String -> ParseTable l a #

Abort the current table matching with an error message at the given annotation.

liftMatcher :: Matcher l a -> ParseTable l a #

Lift a matcher into the current table parsing context.

# ToValue

class ToValue a where #

Class for types that can be embedded into `Value`

Minimal complete definition

toValue

Methods

toValue :: a -> Value #

Embed a single thing into a TOML value.

toValueList :: [a] -> Value #

Helper for converting a list of things into a value. This is typically left to be defined by its default implementation and exists to help define the encoding for TOML arrays.

#### Instances

Instances details

ToValue Int16 # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int16 -> Value # toValueList :: [Int16] -> Value #
ToValue Int32 # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int32 -> Value # toValueList :: [Int32] -> Value #
ToValue Int64 # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int64 -> Value # toValueList :: [Int64] -> Value #
ToValue Int8 # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int8 -> Value # toValueList :: [Int8] -> Value #
ToValue Word16 # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word16 -> Value # toValueList :: [Word16] -> Value #
ToValue Word32 # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word32 -> Value # toValueList :: [Word32] -> Value #
ToValue Word64 # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word64 -> Value # toValueList :: [Word64] -> Value #
ToValue Word8 # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word8 -> Value # toValueList :: [Word8] -> Value #
ToValue Text # | Encodes as string literal
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Text -> Value # toValueList :: [Text] -> Value #
ToValue Text # | Encodes as string literal
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Text -> Value # toValueList :: [Text] -> Value #
ToValue Day # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Day -> Value # toValueList :: [Day] -> Value #
ToValue UTCTime # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: UTCTime -> Value # toValueList :: [UTCTime] -> Value #
ToValue LocalTime # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: LocalTime -> Value # toValueList :: [LocalTime] -> Value #
ToValue TimeOfDay # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: TimeOfDay -> Value # toValueList :: [TimeOfDay] -> Value #
ToValue ZonedTime # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: ZonedTime -> Value # toValueList :: [ZonedTime] -> Value #
ToValue Value # | Identity function
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Value -> Value # toValueList :: [Value] -> Value #
ToValue Integer # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Integer -> Value # toValueList :: [Integer] -> Value #
ToValue Natural # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Natural -> Value # toValueList :: [Natural] -> Value #
ToValue Bool # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Bool -> Value # toValueList :: [Bool] -> Value #
ToValue Char # | Single characters are encoded as singleton strings. Lists of characters are encoded as a single string value.
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Char -> Value # toValueList :: [Char] -> Value #
ToValue Double # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Double -> Value # toValueList :: [Double] -> Value #
ToValue Float # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Float -> Value # toValueList :: [Float] -> Value #
ToValue Int # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int -> Value # toValueList :: [Int] -> Value #
ToValue Word # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word -> Value # toValueList :: [Word] -> Value #
ToValue a => ToValue (Seq a) # | Converts to list and encodes that to value
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Seq a -> Value # toValueList :: [Seq a] -> Value #
ToValue a => ToValue (NonEmpty a) # | Converts to list and encodes that to value
Instance details Defined in Toml.Schema.ToValue Methods toValue :: NonEmpty a -> Value # toValueList :: [NonEmpty a] -> Value #
Integral a => ToValue (Ratio a) # | TOML represents floating point numbers with `Double`. This operation lose precision and can overflow to infinity.
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Ratio a -> Value # toValueList :: [Ratio a] -> Value #
(Generic a, GToArray (Rep a)) => ToValue (GenericTomlArray a) # | Instance derived using `genericToArray`
Instance details Defined in Toml.Schema.Generic Methods toValue :: GenericTomlArray a -> Value # toValueList :: [GenericTomlArray a] -> Value #
(Generic a, GToTable (Rep a)) => ToValue (GenericTomlTable a) # | Instance derived from `ToTable` instance using `defaultTableToValue`
Instance details Defined in Toml.Schema.Generic Methods toValue :: GenericTomlTable a -> Value # toValueList :: [GenericTomlTable a] -> Value #
ToValue (Table' a) # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Table' a -> Value # toValueList :: [Table' a] -> Value #
ToValue a => ToValue [a] # | This instance defers to the list element's `toValueList` implementation.
Instance details Defined in Toml.Schema.ToValue Methods toValue :: [a] -> Value # toValueList :: [[a]] -> Value #
(ToKey k, ToValue v) => ToValue (Map k v) # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Map k v -> Value # toValueList :: [Map k v] -> Value #

class ToValue a => ToTable a where #

Class for things that can be embedded into a TOML table.

Implement this for things that always embed into a `Table` and then the `ToValue` instance can be derived with `defaultTableToValue`.

    instance ToValue Example where
        toValue = defaultTableToValue

    -- Option 1: Manual instance
    instance ToTable Example where
        toTable x = table ["field1" .= field1 x, "field2" .= field2 x]

    -- Option 2: GHC.Generics derived instance using Toml.ToValue.Generic
    instance ToTable Example where
        toTable = genericToTable

Methods

toTable :: a -> Table #

Convert a single value into a table

#### Instances

Instances details

(Generic a, GToTable (Rep a)) => ToTable (GenericTomlTable a) # | Instance derived using `genericToTable`
Instance details Defined in Toml.Schema.Generic Methods toTable :: GenericTomlTable a -> Table #
ToTable (Table' a) # |
Instance details Defined in Toml.Schema.ToValue Methods toTable :: Table' a -> Table #
(ToKey k, ToValue v) => ToTable (Map k v) # |
Instance details Defined in Toml.Schema.ToValue Methods toTable :: Map k v -> Table #

table :: [(Text, Value)] -> Table #

Build a `Table` from a list of key-value pairs.

Use `.=` for a convenient way to build the pairs.

(.=) :: ToValue a => Text -> a -> (Text, Value) #

Convenience function for building key-value pairs while constructing a `Table`.

    table [a .= b, c .= d]

defaultTableToValue :: ToTable a => a -> Value #

Convenience function for building `ToValue` instances.

# Types

type Value = Value' () #

A `Value'` with trivial annotations

data Value' a #

Semantic TOML value with all table assignments resolved.

Constructors

Integer' a Integer |
Double' a Double |
List' a [Value' a] |
Table' a (Table' a) |
Bool' a Bool |
Text' a Text |
TimeOfDay' a TimeOfDay |
ZonedTime' a ZonedTime |
LocalTime' a LocalTime |
Day' a Day |

Bundled Patterns

pattern Bool :: Bool -> Value |
pattern Double :: Double -> Value |
pattern List :: [Value] -> Value |
pattern Integer :: Integer -> Value |
pattern Text :: Text -> Value |
pattern Table :: Table -> Value |
pattern Day :: Day -> Value |
pattern TimeOfDay :: TimeOfDay -> Value |
pattern LocalTime :: LocalTime -> Value |
pattern ZonedTime :: ZonedTime -> Value |

#### Instances

Instances details

Functor Value' # | Derived
Instance details Defined in Toml.Semantics.Types Methods fmap :: (a -> b) -> Value' a -> Value' b # (<$) :: a -> Value' b -> Value' a #
Foldable Value' # | Derived

Instance details

Defined in Toml.Semantics.Types

Methods

fold :: Monoid m => Value' m -> m #

foldMap :: Monoid m => (a -> m) -> Value' a -> m #

foldMap' :: Monoid m => (a -> m) -> Value' a -> m #

foldr :: (a -> b -> b) -> b -> Value' a -> b #

foldr' :: (a -> b -> b) -> b -> Value' a -> b #

foldl :: (b -> a -> b) -> b -> Value' a -> b #

foldl' :: (b -> a -> b) -> b -> Value' a -> b #

foldr1 :: (a -> a -> a) -> Value' a -> a #

foldl1 :: (a -> a -> a) -> Value' a -> a #

toList :: Value' a -> [a] #

null :: Value' a -> Bool #

length :: Value' a -> Int #

elem :: Eq a => a -> Value' a -> Bool #

maximum :: Ord a => Value' a -> a #

minimum :: Ord a => Value' a -> a #

sum :: Num a => Value' a -> a #

product :: Num a => Value' a -> a #

Traversable Value' # | Derived
Instance details Defined in Toml.Semantics.Types Methods traverse :: Applicative f => (a -> f b) -> Value' a -> f (Value' b) # sequenceA :: Applicative f => Value' (f a) -> f (Value' a) # mapM :: Monad m => (a -> m b) -> Value' a -> m (Value' b) # sequence :: Monad m => Value' (m a) -> m (Value' a) #
FromValue Value # | Matches all values, used for pass-through
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Value # listFromValue :: Value' l -> Matcher l [Value] #
ToValue Value # | Identity function
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Value -> Value # toValueList :: [Value] -> Value #

() ~ a => IsString (Value' a) #

Constructs a TOML string literal.

    fromString = String

Instance details Defined in Toml.Semantics.Types Methods fromString :: String -> Value' a #
Read a => Read (Value' a) # | Default instance
Instance details Defined in Toml.Semantics.Types Methods readsPrec :: Int -> ReadS (Value' a) # readList :: ReadS [Value' a] # readPrec :: ReadPrec (Value' a) # readListPrec :: ReadPrec [Value' a] #
Show a => Show (Value' a) # | Default instance
Instance details Defined in Toml.Semantics.Types Methods showsPrec :: Int -> Value' a -> ShowS # show :: Value' a -> String # showList :: [Value' a] -> ShowS #
Eq a => Eq (Value' a) # | Nearly default instance except `ZonedTime` doesn't have an `Eq` instance. `ZonedTime` values are equal if their times and time-zones are both equal.
Instance details Defined in Toml.Semantics.Types Methods (==) :: Value' a -> Value' a -> Bool # (/=) :: Value' a -> Value' a -> Bool #

type Table = Table' () #

A `Table'` with trivial annotations

newtype Table' a #

A table with annotated keys and values.

Constructors

MkTable (Map Text (a, Value' a)) |

#### Instances

Instances details

Functor Table' # | Derived
Instance details Defined in Toml.Semantics.Types Methods fmap :: (a -> b) -> Table' a -> Table' b # (<$) :: a -> Table' b -> Table' a #
Foldable Table' # | Derived

Instance details

Defined in Toml.Semantics.Types

Methods

fold :: Monoid m => Table' m -> m #

foldMap :: Monoid m => (a -> m) -> Table' a -> m #

foldMap' :: Monoid m => (a -> m) -> Table' a -> m #

foldr :: (a -> b -> b) -> b -> Table' a -> b #

foldr' :: (a -> b -> b) -> b -> Table' a -> b #

foldl :: (b -> a -> b) -> b -> Table' a -> b #

foldl' :: (b -> a -> b) -> b -> Table' a -> b #

foldr1 :: (a -> a -> a) -> Table' a -> a #

foldl1 :: (a -> a -> a) -> Table' a -> a #

toList :: Table' a -> [a] #

null :: Table' a -> Bool #

length :: Table' a -> Int #

elem :: Eq a => a -> Table' a -> Bool #

maximum :: Ord a => Table' a -> a #

minimum :: Ord a => Table' a -> a #

sum :: Num a => Table' a -> a #

product :: Num a => Table' a -> a #

Traversable Table' # | Derived
Instance details Defined in Toml.Semantics.Types Methods traverse :: Applicative f => (a -> f b) -> Table' a -> f (Table' b) # sequenceA :: Applicative f => Table' (f a) -> f (Table' a) # mapM :: Monad m => (a -> m b) -> Table' a -> m (Table' b) # sequence :: Monad m => Table' (m a) -> m (Table' a) #
FromValue Table # |
Instance details Defined in Toml.Schema.FromValue Methods fromValue :: Value' l -> Matcher l Table # listFromValue :: Value' l -> Matcher l [Table] #
Read a => Read (Table' a) # | Default instance
Instance details Defined in Toml.Semantics.Types Methods readsPrec :: Int -> ReadS (Table' a) # readList :: ReadS [Table' a] # readPrec :: ReadPrec (Table' a) # readListPrec :: ReadPrec [Table' a] #
Show a => Show (Table' a) # | Default instance
Instance details Defined in Toml.Semantics.Types Methods showsPrec :: Int -> Table' a -> ShowS # show :: Table' a -> String # showList :: [Table' a] -> ShowS #
Eq a => Eq (Table' a) # | Default instance
Instance details Defined in Toml.Semantics.Types Methods (==) :: Table' a -> Table' a -> Bool # (/=) :: Table' a -> Table' a -> Bool #
ToTable (Table' a) # |
Instance details Defined in Toml.Schema.ToValue Methods toTable :: Table' a -> Table #
ToValue (Table' a) # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Table' a -> Value # toValueList :: [Table' a] -> Value #

# Generics

newtype GenericTomlArray a #

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) # | Instance derived using `genericFromArray`
Instance details Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlArray a) # listFromValue :: Value' l -> Matcher l [GenericTomlArray a] #
(Generic a, GToArray (Rep a)) => ToValue (GenericTomlArray a) # | Instance derived using `genericToArray`
Instance details Defined in Toml.Schema.Generic Methods toValue :: GenericTomlArray a -> Value # toValueList :: [GenericTomlArray a] -> Value #

newtype GenericTomlTable a #

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) # | Instance derived using `genericParseTable`
Instance details Defined in Toml.Schema.Generic Methods fromValue :: Value' l -> Matcher l (GenericTomlTable a) # listFromValue :: Value' l -> Matcher l [GenericTomlTable a] #
(Generic a, GToTable (Rep a)) => ToTable (GenericTomlTable a) # | Instance derived using `genericToTable`
Instance details Defined in Toml.Schema.Generic Methods toTable :: GenericTomlTable a -> Table #
(Generic a, GToTable (Rep a)) => ToValue (GenericTomlTable a) # | Instance derived from `ToTable` instance using `defaultTableToValue`
Instance details Defined in Toml.Schema.Generic Methods toValue :: GenericTomlTable a -> Value # toValueList :: [GenericTomlTable a] -> Value #

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

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

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

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

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

Use a record's field names to generate a `Table`

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

Use a record's field names to generate a `Table`