Copyright | (c) Eric Mertens 2023 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Toml
Description
This is the high-level interface to the toml-parser library. It enables parsing, printing, and conversion 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.
Use Toml.Schema to implement functions mapping between TOML values and your application types.
Use Toml.Syntax and Toml.Semantics for low-level TOML syntax processing and semantic validation. Most applications will not need to use these modules directly unless the application is about TOML itself.
The types and functions of this package are parameterized over an annotation type in order to allow applications to provide detailed feedback messages tracked back to specific source locations in an original TOML file. While the default annotation is a simple file position, some applications might upgrade this annotation to track multiple file names or synthetically generated sources. Other applications won't need source location and can replace annotations with a simple unit type.
Synopsis
- type Table = Table' ()
- type Value = Value' ()
- data Located a = Located {
- locPosition :: !Position
- locThing :: !a
- data Position = Position {}
- newtype Table' a = MkTable (Map Text (a, Value' a))
- 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
- valueAnn :: Value' a -> a
- valueType :: Value' l -> String
- forgetTableAnns :: Table' a -> Table
- forgetValueAnns :: Value' a -> Value
- decode' :: FromValue a => Text -> Result DecodeError a
- decode :: FromValue a => Text -> Result String a
- parse :: Text -> Either String (Table' Position)
- data DecodeError
- data Result e a
- encode :: ToTable a => a -> TomlDoc
- prettyToml :: Table' a -> TomlDoc
- data DocClass
- prettyDecodeError :: DecodeError -> String
- prettyLocated :: Located String -> String
- prettyMatchMessage :: MatchMessage Position -> String
- prettySemanticError :: SemanticError Position -> String
Types
Located types
A value annotated with its text file position
Constructors
Located | |
Fields
|
Instances
Functor Located # | Default instance |
Foldable Located # | Default instance |
Defined in Toml.Syntax.Position Methods fold :: Monoid m => Located m -> m # foldMap :: Monoid m => (a -> m) -> Located a -> m # foldMap' :: Monoid m => (a -> m) -> Located a -> m # foldr :: (a -> b -> b) -> b -> Located a -> b # foldr' :: (a -> b -> b) -> b -> Located a -> b # foldl :: (b -> a -> b) -> b -> Located a -> b # foldl' :: (b -> a -> b) -> b -> Located a -> b # foldr1 :: (a -> a -> a) -> Located a -> a # foldl1 :: (a -> a -> a) -> Located a -> a # elem :: Eq a => a -> Located a -> Bool # maximum :: Ord a => Located a -> a # minimum :: Ord a => Located a -> a # | |
Traversable Located # | Default instance |
Read a => Read (Located a) # | Default instance |
Show a => Show (Located a) # | Default instance |
A position in a text file
Constructors
Position | |
A table with annotated keys and values.
Instances
Functor Table' # | Derived |
Foldable Table' # | Derived |
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 # elem :: Eq a => a -> Table' a -> Bool # maximum :: Ord a => Table' a -> a # minimum :: Ord a => Table' a -> a # | |
Traversable Table' # | Derived |
FromValue Table # | |
Read a => Read (Table' a) # | Default instance |
Show a => Show (Table' a) # | Default instance |
Eq a => Eq (Table' a) # | Default instance |
ToTable (Table' a) # | |
Defined in Toml.Schema.ToValue | |
ToValue (Table' a) # | |
Defined in Toml.Schema.ToValue |
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
Functor Value' # | Derived |
Foldable Value' # | Derived |
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 # elem :: Eq a => a -> Value' a -> Bool # maximum :: Ord a => Value' a -> a # minimum :: Ord a => Value' a -> a # | |
Traversable Value' # | Derived |
FromValue Value # | Matches all values, used for pass-through |
ToValue Value # | Identity function |
Defined in Toml.Schema.ToValue | |
() ~ a => IsString (Value' a) # | Constructs a TOML string literal. fromString = String |
Defined in Toml.Semantics.Types Methods fromString :: String -> Value' a # | |
Read a => Read (Value' a) # | Default instance |
Show a => Show (Value' a) # | Default instance |
Eq a => Eq (Value' a) # | Nearly default instance except |
forgetTableAnns :: Table' a -> Table #
Replaces annotations with a unit.
forgetValueAnns :: Value' a -> Value #
Replaces annotations with a unit.
Parsing
decode' :: FromValue a => Text -> Result DecodeError a #
Decode TOML syntax into an application value.
decode :: FromValue a => Text -> Result String a #
Wrapper rending error and warning messages into human-readable strings.
parse :: Text -> Either String (Table' Position) #
Parse a TOML formatted String
or report a human-readable error message.
data DecodeError #
Sum of errors that can occur during TOML decoding
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.
Instances
(Read e, Read a) => Read (Result e a) # | Default instance |
(Show e, Show a) => Show (Result e a) # | Default instance |
(Eq e, Eq a) => Eq (Result e a) # | Default instance |
(Ord e, Ord a) => Ord (Result e a) # | Default instance |
Defined in Toml.Schema.Matcher |
Printing
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
.
Annotation used to enable styling pretty-printed TOML
Constructors
TableClass | top-level |
KeyClass | dotted keys, left-hand side of assignments |
StringClass | string literals |
NumberClass | number literals |
DateClass | date and time literals |
BoolClass | boolean literals |
Error rendering
prettyDecodeError :: DecodeError -> String #
Human-readable representation of a DecodeError
prettyLocated :: Located String -> String #
Pretty-print as line:col: message
prettyMatchMessage :: MatchMessage Position -> String #
Render a TOML decoding error as a human-readable string.
prettySemanticError :: SemanticError Position -> String #
Render a semantic TOML error in a human-readable string.