HORIZON HASKELLDocslts/ghc-9.14.x7a6c33e2026-10-12Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 7a6c33e · 2026-10-12

Moduletoml-parser-2.0.2.0Haskell2010

Toml.Pretty

This module provides human-readable renderers for types used in this package to assist error message production.

The generated Doc values are annotated with DocClass values to assist in producing syntax-highlighted outputs.

To extract a plain String representation, use show.

Contents
  1. Types
  2. Printing semantic values
  3. Printing syntactic components
  4. Printing keys
  5. Locations
Synopsis

Types

datadata DocClass

Annotation used to enable styling pretty-printed TOML

Constructors

Instances4Eq, Ord, Read, Show
  • Eq DocClassDefined in toml-parser-2.0.2.0 · Toml.Pretty
  • Ord DocClassDefined in toml-parser-2.0.2.0 · Toml.Pretty
  • Read DocClassDefined in toml-parser-2.0.2.0 · Toml.Pretty
  • Show DocClassDefined in toml-parser-2.0.2.0 · Toml.Pretty

Printing semantic values

valueprettyToml
  1. :: Table' a

    table to print

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

valueprettyTomlOrdered
  1. :: Ord a
  2. => ([Text] -> Text -> a)

    table path -> key -> projection

  3. -> Table' l

    table to print

  4. -> 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 ancillary 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

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

Printing keys

Locations