toml-parser-2.0.2.0: TOML 1.1.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 Source #

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

extractTableOrder :: [Expr a] -> TableOrder Source #

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

projectKey Source #

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 Source #

Opaque type used by `projectKey`

#### Instances

Instances details

Eq ProjectedKey Source # |
Instance details Defined in Toml.Semantics.Ordered Methods (==) :: ProjectedKey -> ProjectedKey -> Bool Source # (/=) :: ProjectedKey -> ProjectedKey -> Bool Source #
Ord ProjectedKey Source # |

Instance details

Defined in Toml.Semantics.Ordered

Methods

compare :: ProjectedKey -> ProjectedKey -> Ordering Source #

(<) :: ProjectedKey -> ProjectedKey -> Bool Source #

(<=) :: ProjectedKey -> ProjectedKey -> Bool Source #

(>) :: ProjectedKey -> ProjectedKey -> Bool Source #

(>=) :: ProjectedKey -> ProjectedKey -> Bool Source #

max :: ProjectedKey -> ProjectedKey -> ProjectedKey Source #

min :: ProjectedKey -> ProjectedKey -> ProjectedKey Source #

debugTableOrder :: TableOrder -> String Source #

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