toml-parser-2.0.2.0: TOML 1.1.0 parser

Copyright | (c) Eric Mertens 2023
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | None
Language | Haskell2010

Toml.Schema.ParseTable

Contents

- Base interface
- Primitives

Description

This module provides utilities for matching key-value pairs out of tables while building up application-specific values.

It will help generate warnings for unused keys, help select between multiple possible keys, and emit location-specific error messages when keys are unavailable.

Synopsis

- data ParseTable l a
- data KeyAlt l a
  - = Key Text (Value' l -> Matcher l a)
  - | Else (Matcher l a)
- pickKey :: [KeyAlt l a] -> ParseTable l a
- parseTable :: ParseTable l a -> l -> Table' l -> Matcher l a
- liftMatcher :: Matcher l a -> ParseTable l a
- warnTable :: String -> ParseTable l ()
- warnTableAt :: l -> String -> ParseTable l ()
- failTableAt :: l -> String -> ParseTable l a
- setTable :: Table' l -> ParseTable l ()
- getTable :: ParseTable l (Table' l)

# Base interface

data ParseTable l a Source #

Parser that tracks a current set of unmatched key-value pairs from a table.

Use `optKey` and `reqKey` to extract keys.

Use `getTable` and `setTable` to override the table and implement other primitives.

#### Instances

Instances details

Alternative (ParseTable l) Source # |
Instance details Defined in Toml.Schema.ParseTable Methods empty :: ParseTable l a Source # (<|>) :: ParseTable l a -> ParseTable l a -> ParseTable l a Source # some :: ParseTable l a -> ParseTable l [a] Source # many :: ParseTable l a -> ParseTable l [a] Source #
Applicative (ParseTable l) Source # |
Instance details Defined in Toml.Schema.ParseTable Methods pure :: a -> ParseTable l a Source # (<*>) :: ParseTable l (a -> b) -> ParseTable l a -> ParseTable l b Source # liftA2 :: (a -> b -> c) -> ParseTable l a -> ParseTable l b -> ParseTable l c Source # (*>) :: ParseTable l a -> ParseTable l b -> ParseTable l b Source # (<*) :: ParseTable l a -> ParseTable l b -> ParseTable l a Source #
Functor (ParseTable l) Source # |
Instance details Defined in Toml.Schema.ParseTable Methods fmap :: (a -> b) -> ParseTable l a -> ParseTable l b Source # (<$) :: a -> ParseTable l b -> ParseTable l a Source #
Monad (ParseTable l) Source # |
Instance details Defined in Toml.Schema.ParseTable Methods (>>=) :: ParseTable l a -> (a -> ParseTable l b) -> ParseTable l b Source # (>>) :: ParseTable l a -> ParseTable l b -> ParseTable l b Source # return :: a -> ParseTable l a Source #
MonadPlus (ParseTable l) Source # |
Instance details Defined in Toml.Schema.ParseTable Methods mzero :: ParseTable l a Source # mplus :: ParseTable l a -> ParseTable l a -> ParseTable l a Source #
MonadFail (ParseTable l) Source # | Implemented in terms of `fail` on `Matcher`
Instance details Defined in Toml.Schema.ParseTable Methods fail :: String -> ParseTable l a Source #

data KeyAlt l a Source #

Key and value matching function

Constructors

Key Text (Value' l -> Matcher l a) | pick alternative based on key match
Else (Matcher l a) | default case when no previous cases matched

pickKey :: [KeyAlt l a] -> ParseTable l a Source #

Take the first option from a list of table keys and matcher functions. This operation will commit to the first table key that matches. If the associated matcher fails, only that error will be propagated and the other alternatives will not be matched.

If no keys match, an error message is generated explaining which keys would have been accepted.

This is provided as an alternative to chaining multiple `reqKey` cases together with `Alternative` which will fall-through as a result of any failure to the next case.

parseTable :: ParseTable l a -> l -> Table' l -> Matcher l a Source #

Run a `ParseTable` computation with a given starting `Table'`. Unused tables will generate a warning. To change this behavior `getTable` and `setTable` can be used to discard or generate error messages.

# Primitives

liftMatcher :: Matcher l a -> ParseTable l a Source #

Lift a matcher into the current table parsing context.

warnTable :: String -> ParseTable l () Source #

Emit a warning without an annotation.

warnTableAt :: l -> String -> ParseTable l () Source #

Emit a warning with the given annotation.

failTableAt :: l -> String -> ParseTable l a Source #

Abort the current table matching with an error message at the given annotation.

setTable :: Table' l -> ParseTable l () Source #

Replace the remaining portion of the table being matched.

getTable :: ParseTable l (Table' l) Source #

Return the remaining portion of the table being matched.