tomland- Bidirectional TOML serialization
Copyright(c) 2018-2020 Kowainik
MaintainerKowainik <>
Safe HaskellNone



This module contains functions that aggregate the result of tomlP parser into TOML. This approach allows to keep parser fast and simple and delegate the process of creating tree structure to a separate function.




validateItems :: [TomlItem] -> Either ValidationError TOML Source #

Validate list of TomlItems and convert to TOML if not validation errors are found.

data ValidationError Source #

Error that happens during validating TOML which is already syntactically correct. For the list of all possible validation errors and their explanation, see the following issue on GitHub:

Internal helpers

groupItems :: [TomlItem] -> Forest TomlItem Source #

This function takes flat list of TomlItems and groups it into list of Trees by putting all corresponding items inside tables and table arrays. It doesn't perform any validation, just groups items according to prefixes of their keys. So, for example, if you have the following keys as flat list:

aaa              # ordinary key
aaa.bbb          # ordinary key
[foo]            # table nam
[xxx]            # table name
[xxx.yyy]        # table name

the following tree structure will be created:

└──── foo.baz
└──── [yyy]
      └──── zzz

groupWithParent Source #


:: Maybe Key

Parent name

-> [TomlItem]

List of items

-> (Forest TomlItem, [TomlItem])

Forest of times and remaining items

This function groups list of TOML items into Forest and returns list of items that are not children of specified parent.

Invariant: When this function is called with Nothing, second element in the result tuple should be empty list.

validateItemForest :: Forest TomlItem -> Either ValidationError TOML Source #

Construct TOML from the Forest of TomlItem and performing validation of TOML at the same time.