This module contains the additional data types, instance definitions and functions to run parsers in an interleaved way. If all the interleaved parsers recognise a single connected piece of the input text this incorporates the permutation parsers. For some examples see the module Text.ParserCombinators.UU.Demo.MergeAndPermute.
- class Splittable f where
- data Gram f a = Gram [Alt f a] (Maybe a)
- data Alt f a
- mkG :: (Splittable f, Functor f) => f a -> Gram f a
- mkP :: (Monad f, Applicative f, Alternative f) => Gram f a -> f a
- (<<||>) :: Functor f => Gram f (b -> a) -> Gram f b -> Gram f a
- (<||>) :: Functor f => Gram f (a1 -> a) -> Gram f a1 -> Gram f a
- sepBy :: (Monad f, Applicative f, Alternative f) => Gram f a -> f b -> f a
- gmList :: Functor f => Gram f a -> Gram f [a]
- module Control.Applicative
- module Data.Monoid
Since we want to get access to the individual parsers which recognise a consecutive
piece of the input text we define a new data type, which lifts the underlying parsers
to the grammatical level, so they can be transformed, manipulated, and run in a piecewise way.
Gram is defined in such a way that we can always access the first parsers to be ran from such a structure.
We require that all the
Alts do not recognise the empty string.
These should be covered by the
Maybe in the
|Functor f => Monad (Gram f)|
|Functor f => Functor (Gram f)|
|Functor f => Applicative (Gram f)|
The left hand side operand is gradually transformed so we get access to its first component
|Functor f => Alternative (Gram f)|
|Show a => Show (Gram f a)|
|Functor f => Monoid (Gram f (r -> r))|
mkGram splits a simple parser into the possibly empty part and the non-empty part.
The non-empty part recognises a consecutive part of the input.
Here we use the functions
getZeroP which are provided in the uu-parsinglib package,
but they could easily be provided by other packages too.
mkParser converts a
Grammar back into a parser, which can subsequenly be run.
Run a sufficient number of
p's in a merged fashion, but no more than necessary!!