Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Descriptive
Description
Descriptive parsers.
- 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
- 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
- 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
Arguments
:: Consumer s d Identity a | The consumer to run. |
-> s | Initial state. |
-> Result (Description d) a |
Run a consumer.
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
Arguments
:: Monad m | |
=> Consumer s d m a | The consumer to run. |
-> StateT s m (Result (Description d) a) |
Run a consumer.
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 Source
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) |
The bounds of a many-consumable thing.
Constructors
NaturalBound !Integer | |
UnlimitedBound |
A consumer.
Constructors
Consumer | |
Fields
|
Some result.
Combinators
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.
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.