Toml

toml-parser-1.3.0.0: TOML 1.0.0 parser

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

Toml

Contents

- Types
- Parsing
- Printing
- Serialization

Description

This is the high-level interface to the toml-parser library. It enables parsing, printing, and coversion into and out of application-specific representations.

This parser implements TOML 1.0.0 https://toml.io/en/v1.0.0 as carefully as possible.

Synopsis

- type Table = Map String Value
- data Value
  - = Integer Integer
  - | Float Double
  - | Array [Value]
  - | Table Table
  - | Bool Bool
  - | String String
  - | TimeOfDay TimeOfDay
  - | ZonedTime ZonedTime
  - | LocalTime LocalTime
  - | Day Day
- parse :: String -> Either String Table
- prettyToml :: Table -> TomlDoc
- data DocClass
  - = TableClass
  - | KeyClass
  - | StringClass
  - | NumberClass
  - | DateClass
  - | BoolClass
- decode :: FromValue a => String -> Result String a
- encode :: ToTable a => a -> TomlDoc
- data Result e a
  - = Failure [e]
  - | Success [e] a

# Types

type Table = Map String Value #

Representation of a TOML key-value table.

data Value #

Semantic TOML value with all table assignments resolved.

Constructors

Integer Integer |
Float Double |
Array [Value] |
Table Table |
Bool Bool |
String String |
TimeOfDay TimeOfDay |
ZonedTime ZonedTime |
LocalTime LocalTime |
Day Day |

#### Instances

Instances details

Data Value # | Default instance
Instance details Defined in Toml.Value Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Value -> c Value gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Value toConstr :: Value -> Constr dataTypeOf :: Value -> DataType dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Value) dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Value) gmapT :: (forall b. Data b => b -> b) -> Value -> Value gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r gmapQ :: (forall d. Data d => d -> u) -> Value -> [u] gmapQi :: Int -> (forall d. Data d => d -> u) -> Value -> u gmapM :: Monad m => (forall d. Data d => d -> m d) -> Value -> m Value gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value
Generic Value # |
Instance details Defined in Toml.Value Associated Types type Rep Value :: Type -> Type Methods from :: Value -> Rep Value x to :: Rep Value x -> Value
Read Value # | Default instance
Instance details Defined in Toml.Value Methods readsPrec :: Int -> ReadS Value readList :: ReadS [Value] readPrec :: ReadPrec Value readListPrec :: ReadPrec [Value]
Show Value # | Default instance
Instance details Defined in Toml.Value Methods showsPrec :: Int -> Value -> ShowS show :: Value -> String showList :: [Value] -> ShowS
Eq Value # | Nearly default instance except `Value` doesn't have an `Eq` instance. `Value` values are equal if their times and timezones are both equal.
Instance details Defined in Toml.Value Methods (==) :: Value -> Value -> Bool (/=) :: Value -> Value -> Bool
FromValue Value # | Matches all values, used for pass-through
Instance details Defined in Toml.FromValue Methods fromValue :: Value -> Matcher Value # listFromValue :: Value -> Matcher [Value] #
ToValue Value # | Identity function
Instance details Defined in Toml.ToValue Methods toValue :: Value -> Value # toValueList :: [Value] -> Value #
type Rep Value # | Default instance
Instance details Defined in Toml.Value type Rep Value = D1 ('MetaData "Value" "Toml.Value" "toml-parser-1.3.0.0-CYT1F0M7m7w5Wflta0pWOu" 'False) (((C1 ('MetaCons "Integer" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer)) :+: C1 ('MetaCons "Float" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Double))) :+: (C1 ('MetaCons "Array" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Value])) :+: (C1 ('MetaCons "Table" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Table)) :+: C1 ('MetaCons "Bool" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))) :+: ((C1 ('MetaCons "String" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :+: C1 ('MetaCons "TimeOfDay" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TimeOfDay))) :+: (C1 ('MetaCons "ZonedTime" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ZonedTime)) :+: (C1 ('MetaCons "LocalTime" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LocalTime)) :+: C1 ('MetaCons "Day" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Day))))))

# Parsing

parse :: String -> Either String Table #

Parse a TOML formatted `Value` or report an error message.

# Printing

prettyToml #

Arguments

:: Table | table to print
-> TomlDoc | TOML syntax

Render a complete TOML document using top-level table and array of table sections where possible.

Keys are sorted alphabetically. To provide a custom ordering, see `prettyTomlOrdered`.

data DocClass #

Annotation used to enable styling pretty-printed TOML

Constructors

TableClass | top-level `[key]` and `[[key]]`
KeyClass | dotted keys, left-hand side of assignments
StringClass | string literals
NumberClass | number literals
DateClass | date and time literals
BoolClass | boolean literals

#### Instances

Instances details

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

# Serialization

decode :: FromValue a => String -> Result String a #

Use the `FromValue` instance to decode a value from a TOML string.

encode :: ToTable a => a -> TomlDoc #

Use the `ToTable` instance to encode a value to a TOML string.

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.

Since: 1.3.0.0

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.FromValue.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.FromValue.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.FromValue.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.FromValue.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