Copyright | (c) Eric Mertens 2023 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- type TomlDoc = Doc DocClass
- data DocClass
- prettyToml :: Table -> TomlDoc
- prettyTomlOrdered :: Ord a => ([String] -> String -> a) -> Table -> TomlDoc
- prettyValue :: Value -> TomlDoc
- prettyToken :: Token -> String
- prettySectionKind :: SectionKind -> NonEmpty String -> TomlDoc
- prettySimpleKey :: String -> Doc a
- prettyKey :: NonEmpty String -> TomlDoc
- prettySemanticError :: SemanticError -> String
- prettyMatchMessage :: MatchMessage -> String
- prettyLocated :: Located String -> String
Types
type TomlDoc = Doc DocClass Source #
Pretty-printer document with TOML class attributes to aid in syntax-highlighting.
Annotation used to enable styling pretty-printed TOML
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 |
Printing semantic values
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
.
:: Ord a | |
=> ([String] -> String -> a) | table path -> key -> projection |
-> Table | table to print |
-> TomlDoc | TOML syntax |
Render a complete TOML document like prettyToml
but use a
custom key ordering. The comparison function has access to the
complete key path. Note that only keys in the same table will
every be compared.
This operation allows you to render your TOML files with the
most important sections first. A TOML file describing a package
might desire to have the [package]
section first before any
of the ancilliary configuration sections.
The table path is the name of the table being sorted. This allows the projection to be aware of which table is being sorted.
The key is the key in the table being sorted. These are the keys that will be compared to each other.
Here's a projection that puts the package
section first, the
secondary
section second, and then all remaining cases are
sorted alphabetically afterward.
example :: [String] -> String -> Either Int String example [] "package" = Left 1 example [] "second" = Left 2 example _ other = Right other
We could also put the tables in reverse-alphabetical order by leveraging an existing newtype.
reverseOrderProj :: [String] -> String -> Down String reverseOrderProj _ = Down
Since: 1.2.1.0
prettyValue :: Value -> TomlDoc Source #
Render a value suitable for assignment on the right-hand side of an equals sign. This value will always use inline table and list syntax.
Printing syntactic components
prettyToken :: Token -> String Source #
Render token for human-readable error messages.
prettySectionKind :: SectionKind -> NonEmpty String -> TomlDoc Source #
Pretty-print a section heading. The result is annotated as a TableClass
.
Printing keys
prettySimpleKey :: String -> Doc a Source #
Renders a simple-key using quotes where necessary.
prettyKey :: NonEmpty String -> TomlDoc Source #
Renders a dotted-key using quotes where necessary and annotated
as a KeyClass
.
Pretty errors
prettySemanticError :: SemanticError -> String Source #
Render a semantic TOML error in a human-readable string.
Since: 1.3.0.0
prettyMatchMessage :: MatchMessage -> String Source #
Render a TOML decoding error as a human-readable string.
Since: 1.3.0.0