uu-interleaved-0.1.0.0: Providing an interleaving combinator for use with applicative/alternative style implementations.

Safe HaskellSafe-Inferred

Control.Applicative.Interleaved

Contents

Description

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.

Synopsis

Classes

class Splittable f whereSource

Methods

getNonPure :: f a -> Maybe (f a)Source

getPure :: f a -> Maybe aSource

Types

data Gram f a Source

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 Gram constructor.

Constructors

Gram [Alt f a] (Maybe a) 

Instances

Functor f => Monad (Gram f) 
Functor f => Functor (Gram f)

We define instances for the data type Gram for Functor, Applicative, Alternative and ExtAlternative

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)) 

data Alt f a Source

Constructors

forall b . Seq (f (b -> a)) (Gram f b) 
forall b . Bind (f b) (b -> Gram f a) 

Instances

Functor f => Functor (Alt f) 

Functions

mkG :: (Splittable f, Functor f) => f a -> Gram f aSource

The function 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 getOneP and getZeroP which are provided in the uu-parsinglib package, but they could easily be provided by other packages too.

mkP :: (Monad f, Applicative f, Alternative f) => Gram f a -> f aSource

mkParser converts a Grammar back into a parser, which can subsequenly be run.

(<<||>) :: Functor f => Gram f (b -> a) -> Gram f b -> Gram f aSource

The function <<||> is a special version of <||>, which only starts a new instance of its right operand when the left operand cannot proceed. This is used in the function pmMany, where we want to merge as many instances of its argument, but no more than that.

(<||>) :: Functor f => Gram f (a1 -> a) -> Gram f a1 -> Gram f aSource

The function <||> is the merging equivalent of <*>. Instead of running its two arguments consecutively, the input is split into parts which serve as input for the left operand and parts which are served to the right operand.

sepBy :: (Monad f, Applicative f, Alternative f) => Gram f a -> f b -> f aSource

sepBy is like mkP, with the additional feature that we require separators between the components. Probably only useful in the permuting case.

gmList :: Functor f => Gram f a -> Gram f [a]Source

Run a sufficient number of p's in a merged fashion, but no more than necessary!!

Modules