Descriptive

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

Safe Haskell | Safe
Language | Haskell98

Descriptive

Contents

- Consuming and describing
- Lower-level runners
- Types
- Combinators

Description

Descriptive parsers.

Synopsis

- consume :: Consumer s d Identity a -> s -> Result (Description d) a
- describe :: Consumer s d Identity a -> s -> Description d
- runConsumer :: Monad m => Consumer s d m a -> StateT s m (Result (Description d) a)
- runDescription :: Monad m => Consumer s d m a -> StateT s m (Description d)
- data Description a
  - = Unit !a
  - | Bounded !Integer !Bound !(Description a)
  - | And !(Description a) !(Description a)
  - | Or !(Description a) !(Description a)
  - | Sequence ![Description a]
  - | Wrap a !(Description a)
  - | None
- data Bound
  - = NaturalBound !Integer
  - | UnlimitedBound
- data Consumer s d m a = Consumer {
  - consumerDesc :: StateT s m (Description d)
  - consumerParse :: StateT s m (Result (Description d) a)
  }
- data Result e a
  - = Failed e
  - | Succeeded a
  - | Continued e
- consumer :: StateT s m (Description d) -> StateT s m (Result (Description d) a) -> Consumer s d m a
- wrap :: (StateT t m (Description d) -> StateT s m (Description d)) -> (StateT t m (Description d) -> StateT t m (Result (Description d) a) -> StateT s m (Result (Description d) b)) -> Consumer t d m a -> Consumer s d m b

# 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.

Constructors

Unit !a |
Bounded !Integer !Bound !(Description a) |
And !(Description a) !(Description a) |
Or !(Description a) !(Description a) |
Sequence ![Description a] |
Wrap a !(Description a) |
None |

Instances

Functor Description |
Eq a => Eq (Description a) |
Show a => Show (Description a) |
Monoid (Description d) |
Monoid a => Monoid (Result (Description d) a) |

data Bound

The bounds of a many-consumable thing.

Constructors

NaturalBound !Integer |
UnlimitedBound |

Instances

Eq Bound |
Show Bound |

data Consumer s d m a

A consumer.

Constructors

Consumer |
Fields consumerDesc :: StateT s m (Description d) consumerParse :: StateT s m (Result (Description d) a)

Instances

Monad m => Functor (Consumer s d m) |
Monad m => Applicative (Consumer s d m) |
Monad m => Alternative (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.