toml-parser-2.0.2.0: TOML 1.1.0 parser

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

Toml.Semantics

Contents

- Types
- Validation
- Annotations

Description

This module extracts a nested Map representation of a TOML file. It detects invalid key assignments and resolves dotted key assignments.

Synopsis

- 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))
- semantics :: [Expr a] -> Either (SemanticError a) (Table' a)
- data SemanticError a = SemanticError {
  - errorAnn :: a
  - errorKey :: Text
  - errorKind :: SemanticErrorKind
  }
- data SemanticErrorKind
  - = AlreadyAssigned
  - | ClosedTable
  - | ImplicitlyTable
- forgetTableAnns :: Table' a -> Table
- forgetValueAnns :: Value' a -> Value
- valueAnn :: Value' a -> a
- valueType :: Value' l -> String

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

# Validation

semantics :: [Expr a] -> Either (SemanticError a) (Table' a) Source #

Extracts a semantic value from a sequence of raw TOML expressions, or reports a semantic error if one occurs.

data SemanticError a Source #

This type represents errors generated when resolving keys in a TOML document.

Since: 1.3.0.0

Constructors

SemanticError |

Fields

- errorAnn :: a

  Annotation associated with offending key

- errorKey :: Text
- errorKind :: SemanticErrorKind

#### Instances

Instances details

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

Instance details

Defined in Toml.Semantics

Methods

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

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

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

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

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

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

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

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

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

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

null :: SemanticError a -> Bool Source #

length :: SemanticError a -> Int Source #

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

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

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

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

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

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

Instance details

Defined in Toml.Semantics

Methods

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

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

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

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

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

max :: SemanticError a -> SemanticError a -> SemanticError a Source #

min :: SemanticError a -> SemanticError a -> SemanticError a Source #

data SemanticErrorKind Source #

Enumeration of the kinds of conflicts a key can generate.

Since: 1.3.0.0

Constructors

AlreadyAssigned | Attempted to assign to a key that was already assigned
ClosedTable | Attempted to open a table already closed
ImplicitlyTable | Attempted to open a tables as an array of tables that was implicitly defined to be a table

#### Instances

Instances details

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

Instance details

Defined in Toml.Semantics

Methods

compare :: SemanticErrorKind -> SemanticErrorKind -> Ordering Source #

(<) :: SemanticErrorKind -> SemanticErrorKind -> Bool Source #

(<=) :: SemanticErrorKind -> SemanticErrorKind -> Bool Source #

(>) :: SemanticErrorKind -> SemanticErrorKind -> Bool Source #

(>=) :: SemanticErrorKind -> SemanticErrorKind -> Bool Source #

max :: SemanticErrorKind -> SemanticErrorKind -> SemanticErrorKind Source #

min :: SemanticErrorKind -> SemanticErrorKind -> SemanticErrorKind Source #

# Annotations

forgetTableAnns :: Table' a -> Table Source #

Replaces annotations with a unit.

forgetValueAnns :: Value' a -> Value Source #

Replaces annotations with a unit.

valueAnn :: Value' a -> a Source #

Extract the top-level annotation from a value.

valueType :: Value' l -> String Source #

String representation of the kind of value using TOML vocabulary