toml-parser-2.0.1.0: TOML 1.0.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' () #

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 #

# Validation

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

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

data SemanticError a #

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

Instance details

Defined in Toml.Semantics

Methods

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

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

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

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

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

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

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

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

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

toList :: SemanticError a -> [a] #

null :: SemanticError a -> Bool #

length :: SemanticError a -> Int #

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

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

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

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

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

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

Instance details

Defined in Toml.Semantics

Methods

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

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

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

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

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

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

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

data SemanticErrorKind #

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

Instance details

Defined in Toml.Semantics

Methods

compare :: SemanticErrorKind -> SemanticErrorKind -> Ordering #

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

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

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

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

max :: SemanticErrorKind -> SemanticErrorKind -> SemanticErrorKind #

min :: SemanticErrorKind -> SemanticErrorKind -> SemanticErrorKind #

# Annotations

forgetTableAnns :: Table' a -> Table #

Replaces annotations with a unit.

forgetValueAnns :: Value' a -> Value #

Replaces annotations with a unit.

valueAnn :: Value' a -> a #

Extract the top-level annotation from a value.

valueType :: Value' l -> String #

String representation of the kind of value using TOML vocabulary