toml-parser-2.0.0.0: TOML 1.0.0 parser
Copyright(c) Eric Mertens 2023
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

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

debugTableOrder :: TableOrder -> String Source #

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