toml-parser-2.0.0.0: TOML 1.0.0 parser

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

Toml.Semantics.Ordered

Description

This module can help build a key ordering projection given an existing TOML file. This could be useful for applying a transformation to a TOML file before pretty-printing it back in something very close to the original order.

When using the computed order, table keys will be remembered in the order they appeared in the source file. Any key additional keys added to the tables will be ordered alphabetically after all the known keys.

    demo =
     do txt <- readFile "demo.toml"
        let Right exprs = parseRawToml txt
            to          = extractTableOrder exprs
            Right toml  = semantics exprs
            projection  = projectKey to
        print (prettyTomlOrdered projection toml)

Synopsis

- data TableOrder
- extractTableOrder :: [Expr a] -> TableOrder
- projectKey :: TableOrder -> [Text] -> Text -> ProjectedKey
- data ProjectedKey
- debugTableOrder :: TableOrder -> String

# Documentation

data TableOrder #

Summary of the order of the keys in a TOML document.

extractTableOrder :: [Expr a] -> TableOrder #

Extract a `TableOrder` from the output of `parseRawToml` to be later used with `projectKey`.

projectKey #

Arguments

:: TableOrder | table order
-> [Text] | table path
-> Text | key
-> ProjectedKey | type suitable for ordering table keys

Generate a projection function for use with `prettyTomlOrdered`

data ProjectedKey #

Opaque type used by `projectKey`

#### Instances

Instances details

Eq ProjectedKey # |
Instance details Defined in Toml.Semantics.Ordered Methods (==) :: ProjectedKey -> ProjectedKey -> Bool # (/=) :: ProjectedKey -> ProjectedKey -> Bool #
Ord ProjectedKey # |
Instance details Defined in Toml.Semantics.Ordered Methods compare :: ProjectedKey -> ProjectedKey -> Ordering # (<) :: ProjectedKey -> ProjectedKey -> Bool # (<=) :: ProjectedKey -> ProjectedKey -> Bool # (>) :: ProjectedKey -> ProjectedKey -> Bool # (>=) :: ProjectedKey -> ProjectedKey -> Bool # max :: ProjectedKey -> ProjectedKey -> ProjectedKey # min :: ProjectedKey -> ProjectedKey -> ProjectedKey #

debugTableOrder :: TableOrder -> String #

Render a white-space nested representation of the key ordering extracted by `extractTableOrder`. This is provided for debugging and understandability.