descriptive-0.7.0: Self-describing consumers/parsers; forms, cmd-line args, JSON, etc.

Safe HaskellSafe-Inferred
LanguageHaskell98

Descriptive

Contents

Description

Descriptive parsers.

Synopsis

Consuming and describing

consume

Arguments

:: Consumer s d Identity a

The consumer to run.

-> s

Initial state.

-> Result (Description d) a 

Run a consumer.

describe

Arguments

:: Consumer s d Identity a

The consumer to run.

-> s

Initial state. Can be "empty" if you don't use it for generating descriptions.

-> Description d

A description and resultant state.

Describe a consumer.

Lower-level runners

runConsumer

Arguments

:: Monad m 
=> Consumer s d m a

The consumer to run.

-> StateT s m (Result (Description d) a) 

Run a consumer.

runDescription

Arguments

:: Monad m 
=> Consumer s d m a

The consumer to run.

-> StateT s m (Description d)

A description and resultant state.

Describe a consumer.

Types

data Description a

Description of a consumable thing.

Instances

data Bound

The bounds of a many-consumable thing.

Instances

data Consumer s d m a

A consumer.

Constructors

Consumer 

Instances

Monad m => Alternative (Consumer s d m) 
Monad m => Functor (Consumer s d m) 
Monad m => Applicative (Consumer s d m) 
(Monoid a, Monad m) => Monoid (Consumer s d m a) 

data Result e a

Some result.

Constructors

Failed e

The whole process failed.

Succeeded a

The whole process succeeded.

Continued e

There were errors but we continued to collect all the errors.

Instances

Bifunctor Result 
(Eq e, Eq a) => Eq (Result e a) 
(Ord e, Ord a) => Ord (Result e a) 
(Show e, Show a) => Show (Result e a) 
Monoid a => Monoid (Result (Description d) a) 

Combinators

consumer

Arguments

:: StateT s m (Description d)

Produce description based on the state.

-> StateT s m (Result (Description d) a)

Parse the state and maybe transform it if desired.

-> Consumer s d m a 

Make a self-describing consumer.

wrap

Arguments

:: (StateT t m (Description d) -> StateT s m (Description d))

Transform the description.

-> (StateT t m (Description d) -> StateT t m (Result (Description d) a) -> StateT s m (Result (Description d) b))

Transform the parser. Can re-run the parser as many times as desired.

-> Consumer t d m a 
-> Consumer s d m b 

Wrap a consumer with another consumer. The type looks more intimidating than it actually is. The source code is trivial. It simply allows for a way to transform the type of the state.

validate

Arguments

:: Monad m 
=> d

Description of what it expects.

-> (a -> StateT s m (Maybe b))

Attempt to parse the value.

-> Consumer s d m a

Consumer to add validation to.

-> Consumer s d m b

A new validating consumer.

Add validation to a consumer.