toml-parser-1.3.0.0: TOML 1.0.0 parser

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

Toml.FromValue.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.

This module provides the `ParseTable` implementation, but most of the basic functionality is exported directly from Toml.FromValue.

Synopsis

- data ParseTable a
- data KeyAlt a
  - = Key String (Value -> Matcher a)
  - | Else (Matcher a)
- pickKey :: [KeyAlt a] -> ParseTable a
- runParseTable :: ParseTable a -> Table -> Matcher a
- liftMatcher :: Matcher a -> ParseTable a
- warnTable :: String -> ParseTable ()
- setTable :: Table -> ParseTable ()
- getTable :: ParseTable Table

# Base interface

data ParseTable a #

A `Matcher` 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

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

data KeyAlt a #

Key and value matching function

Since: 1.2.0.0

Constructors

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

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

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 `(`<|>`)` because that will generate one error message for each unmatched alternative as well as the error associate with the matched alternative.

Since: 1.2.0.0

runParseTable :: ParseTable a -> Table -> Matcher a #

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 a -> ParseTable a #

Lift a matcher into the current table parsing context.

warnTable :: String -> ParseTable () #

Emit a warning at the current location.

setTable :: Table -> ParseTable () #

Replace the remaining portion of the table being matched.

getTable :: ParseTable Table #

Return the remaining portion of the table being matched.