toml-parser-0.1.0.0: Parser for the TOML configuration language

Copyright(c) Eric Mertens 2017
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellSafe
LanguageHaskell2010

TOML.Components

Description

This module provides an intermediate representation for TOML files. The parser produces a list of top-level table components, and this module gathers those together in the form of tables and lists of tables.

Synopsis

Documentation

data Component Source #

Various top-level elements that can be returned by the TOML parser.

Constructors

InitialEntry [(Text, Value)]

key value pairs before any [header]

TableEntry Path [(Text, Value)]

key value pairs after any [header]

ArrayEntry Path [(Text, Value)]

key value pairs after any [[header]]

type Path = [Text] Source #

Non-empty list of table keys

componentsToTable :: [Component] -> Either Path [(Text, Value)] Source #

Merge a list of top-level components into a single table, or throw an error with an ambiguous path.

collapseComponents :: [Component] -> [(Path, Value)] Source #

Collapse the various components generated by the parser into a single list of path-value pairs. This operations is particularly responsible for gathering top-level array entries together.

splitArrays :: Path -> [Component] -> ([[(Text, Value)]], [Component]) Source #

Extract all of the leading ArrayEntry components that match the given path.

factorHeads :: Eq k => [([k], v)] -> [(k, [([k], v)])] Source #

Given a list of key-value pairs ordered by key, group the list by equality on the head of the key-path list.

flattenTableList :: [(Path, Value)] -> Either Path [(Text, Value)] Source #

Flatten a list of path-value pairs into a single table. If in the course of flattening the pairs if the value at a particular path is assigned twice, that path will be returned instead.

mergeInlineTable :: [(Text, value)] -> [(Path, value)] -> [(Path, value)] Source #

Merge a table into the current list of path-value pairs. The resulting list is sorted to make it appropriate for subsequent grouping operations.

order :: [(Path, value)] -> [(Path, value)] Source #

Order a list of path-value pairs lexicographically by path.

validateInlineTables :: Path -> Value -> Either Path () Source #

Throw an error with the problematic path if a duplicate is found.

findDuplicate :: Ord a => [a] -> Maybe a Source #

Find an entry that appears in the given list more than once.