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

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.

## Matcher

data Matcher l 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

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

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

Run a `Matcher` with an empty scope.

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

Run `Matcher` and treat warnings as errors.

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

Run `Matcher` and ignore warnings.

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

#### Instances

Instances details

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

Instance details

Defined in Toml.Schema.Matcher

Methods

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

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

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

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

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

max :: Result e a -> Result e a -> Result e a Source #

min :: Result e a -> Result e a -> Result e a Source #

data MatchMessage a Source #

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 Source # |
Instance details Defined in Toml.Schema.Matcher Methods fmap :: (a -> b) -> MatchMessage a -> MatchMessage b Source # (<$) :: a -> MatchMessage b -> MatchMessage a Source #
Foldable MatchMessage Source # |

Instance details

Defined in Toml.Schema.Matcher

Methods

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

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

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

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

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

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

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

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

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

toList :: MatchMessage a -> [a] Source #

null :: MatchMessage a -> Bool Source #

length :: MatchMessage a -> Int Source #

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

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

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

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

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

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

Instance details

Defined in Toml.Schema.Matcher

Methods

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

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

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

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

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

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

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

data Scope Source #

Scopes for TOML message.

Constructors

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

#### Instances

Instances details

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

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

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

parseTable :: ParseTable l a -> l -> Table' l -> Matcher l 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.

getScope :: Matcher a [Scope] Source #

Get the current list of scopes.

warn :: String -> Matcher a () Source #

Emit a warning without an annotation.

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

Emit a warning mentioning the given annotation.

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

Terminate the match with an error mentioning the given annotation.

getTable :: ParseTable l (Table' l) Source #

Return the remaining portion of the table being matched.

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

Replace the remaining portion of the table being matched.

## Tables

data ParseTable l a Source #

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

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

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

    reqKey key = reqKeyOf key fromValue

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

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.

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.

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

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

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 () Source #

Emit a warning without an annotation.

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

Emit a warning with the given annotation.

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

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

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

Lift a matcher into the current table parsing context.

# ToValue

class ToValue a where Source #

Class for types that can be embedded into `Value`

Minimal complete definition

toValue

Methods

toValue :: a -> Value Source #

Embed a single thing into a TOML value.

toValueList :: [a] -> Value Source #

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 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int16 -> Value Source # toValueList :: [Int16] -> Value Source #
ToValue Int32 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int32 -> Value Source # toValueList :: [Int32] -> Value Source #
ToValue Int64 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int64 -> Value Source # toValueList :: [Int64] -> Value Source #
ToValue Int8 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int8 -> Value Source # toValueList :: [Int8] -> Value Source #
ToValue Word16 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word16 -> Value Source # toValueList :: [Word16] -> Value Source #
ToValue Word32 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word32 -> Value Source # toValueList :: [Word32] -> Value Source #
ToValue Word64 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word64 -> Value Source # toValueList :: [Word64] -> Value Source #
ToValue Word8 Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word8 -> Value Source # toValueList :: [Word8] -> Value Source #
ToValue Text Source # | Encodes as string literal
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Text -> Value Source # toValueList :: [Text] -> Value Source #
ToValue Text Source # | Encodes as string literal
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Text -> Value Source # toValueList :: [Text] -> Value Source #
ToValue Day Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Day -> Value Source # toValueList :: [Day] -> Value Source #
ToValue UTCTime Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: UTCTime -> Value Source # toValueList :: [UTCTime] -> Value Source #
ToValue LocalTime Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: LocalTime -> Value Source # toValueList :: [LocalTime] -> Value Source #
ToValue TimeOfDay Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: TimeOfDay -> Value Source # toValueList :: [TimeOfDay] -> Value Source #
ToValue ZonedTime Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: ZonedTime -> Value Source # toValueList :: [ZonedTime] -> Value Source #
ToValue Value Source # | Identity function
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Value -> Value Source # toValueList :: [Value] -> Value Source #
ToValue Integer Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Integer -> Value Source # toValueList :: [Integer] -> Value Source #
ToValue Natural Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Natural -> Value Source # toValueList :: [Natural] -> Value Source #
ToValue Bool Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Bool -> Value Source # toValueList :: [Bool] -> Value Source #
ToValue Char Source # | 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 Source # toValueList :: [Char] -> Value Source #
ToValue Double Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Double -> Value Source # toValueList :: [Double] -> Value Source #
ToValue Float Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Float -> Value Source # toValueList :: [Float] -> Value Source #
ToValue Int Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Int -> Value Source # toValueList :: [Int] -> Value Source #
ToValue Word Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Word -> Value Source # toValueList :: [Word] -> Value Source #
ToValue a => ToValue (Seq a) Source # | Converts to list and encodes that to value
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Seq a -> Value Source # toValueList :: [Seq a] -> Value Source #
ToValue a => ToValue (NonEmpty a) Source # | Converts to list and encodes that to value
Instance details Defined in Toml.Schema.ToValue Methods toValue :: NonEmpty a -> Value Source # toValueList :: [NonEmpty a] -> Value Source #
Integral a => ToValue (Ratio a) Source # | 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 Source # toValueList :: [Ratio a] -> Value Source #
(Generic a, GToArray (Rep a)) => ToValue (GenericTomlArray a) Source # | Instance derived using `genericToArray`
Instance details Defined in Toml.Schema.Generic Methods toValue :: GenericTomlArray a -> Value Source # toValueList :: [GenericTomlArray a] -> Value Source #
(Generic a, GToTable (Rep a)) => ToValue (GenericTomlTable a) Source # | Instance derived from `ToTable` instance using `defaultTableToValue`
Instance details Defined in Toml.Schema.Generic Methods toValue :: GenericTomlTable a -> Value Source # toValueList :: [GenericTomlTable a] -> Value Source #
ToValue (Table' a) Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Table' a -> Value Source # toValueList :: [Table' a] -> Value Source #
ToValue a => ToValue [a] Source # | This instance defers to the list element's `toValueList` implementation.
Instance details Defined in Toml.Schema.ToValue Methods toValue :: [a] -> Value Source # toValueList :: [[a]] -> Value Source #
(ToKey k, ToValue v) => ToValue (Map k v) Source # |
Instance details Defined in Toml.Schema.ToValue Methods toValue :: Map k v -> Value Source # toValueList :: [Map k v] -> Value Source #

class ToValue a => ToTable a where Source #

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

Convert a single value into a table

#### Instances

Instances details

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

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

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) Source #

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

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

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

Convenience function for building `ToValue` instances.

# Types

type Value = Value' () Source #

A `Value'` with trivial annotations

data Value' a Source #

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

Instance details

Defined in Toml.Semantics.Types

Methods

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

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

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

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

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

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

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

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

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

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

null :: Value' a -> Bool Source #

length :: Value' a -> Int Source #

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

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

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

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

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

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

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

Constructs a TOML string literal.

    fromString = String

Instance details Defined in Toml.Semantics.Types Methods fromString :: String -> Value' a Source #
Read a => Read (Value' a) Source # | Default instance
Instance details Defined in Toml.Semantics.Types Methods readsPrec :: Int -> ReadS (Value' a) Source # readList :: ReadS [Value' a] Source # readPrec :: ReadPrec (Value' a) Source # readListPrec :: ReadPrec [Value' a] Source #
Show a => Show (Value' a) Source # | Default instance
Instance details Defined in Toml.Semantics.Types Methods showsPrec :: Int -> Value' a -> ShowS Source # show :: Value' a -> String Source # showList :: [Value' a] -> ShowS Source #
Eq a => Eq (Value' a) Source # | 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 Source # (/=) :: Value' a -> Value' a -> Bool Source #

type Table = Table' () Source #

A `Table'` with trivial annotations

newtype Table' a Source #

A table with annotated keys and values.

Constructors

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

#### Instances

Instances details

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

Instance details

Defined in Toml.Semantics.Types

Methods

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

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

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

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

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

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

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

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

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

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

null :: Table' a -> Bool Source #

length :: Table' a -> Int Source #

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

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

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

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

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

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

# Generics

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

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

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.

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.

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

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

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

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