Copyright | (c) Eric Mertens 2017 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe |
Language | Haskell2010 |
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.
- data Component
- = InitialEntry [(Text, Value)]
- | TableEntry Path [(Text, Value)]
- | ArrayEntry Path [(Text, Value)]
- type Path = [Text]
- componentsToTable :: [Component] -> Either Path [(Text, Value)]
- collapseComponents :: [Component] -> [(Path, Value)]
- splitArrays :: Path -> [Component] -> ([[(Text, Value)]], [Component])
- factorHeads :: Eq k => [([k], v)] -> [(k, [([k], v)])]
- flattenTableList :: [(Path, Value)] -> Either Path [(Text, Value)]
- mergeInlineTable :: [(Text, value)] -> [(Path, value)] -> [(Path, value)]
- order :: [(Path, value)] -> [(Path, value)]
- validateInlineTables :: Path -> Value -> Either Path ()
- findDuplicate :: Ord a => [a] -> Maybe a
Documentation
Various top-level elements that can be returned by the TOML parser.
InitialEntry [(Text, Value)] | key value pairs before any |
TableEntry Path [(Text, Value)] | key value pairs after any |
ArrayEntry Path [(Text, Value)] | key value pairs after any |
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.