Copyright | (c) Eric Mertens 2023 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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
toprettyTomlOrdered
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
.
:: 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
Eq ProjectedKey Source # | |
Defined in Toml.Semantics.Ordered (==) :: ProjectedKey -> ProjectedKey -> Bool # (/=) :: ProjectedKey -> ProjectedKey -> Bool # | |
Ord ProjectedKey Source # | |
Defined in Toml.Semantics.Ordered 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 Source #
Render a white-space nested representation of the key ordering extracted
by extractTableOrder
. This is provided for debugging and understandability.