invertible-grammar-0.1.3: Invertible parsing combinators framework

Safe HaskellTrustworthy
LanguageHaskell2010

Data.InvertibleGrammar.Combinators

Synopsis

Documentation

iso :: (a -> b) -> (b -> a) -> Grammar p (a :- t) (b :- t) Source #

Isomorphism on the stack head.

osi :: (b -> a) -> (a -> b) -> Grammar p (a :- t) (b :- t) Source #

Flipped isomorphism on the stack head.

partialIso :: (a -> b) -> (b -> Either Mismatch a) -> Grammar p (a :- t) (b :- t) Source #

Partial isomorphism (for backward run) on the stack head.

partialOsi :: (a -> Either Mismatch b) -> (b -> a) -> Grammar p (a :- t) (b :- t) Source #

Partial isomorphism (for forward run) on the stack head.

push :: a -> (a -> Bool) -> (a -> Mismatch) -> Grammar p t (a :- t) Source #

Push an element to the stack on forward run, check if the element satisfies predicate, otherwise report a mismatch.

pair :: Grammar p (b :- (a :- t)) ((a, b) :- t) Source #

2-tuple grammar. Construct on forward run, deconstruct on backward run.

swap :: Grammar p (a :- (b :- t)) (b :- (a :- t)) Source #

Swap two topmost stack elements.

cons :: Grammar p ([a] :- (a :- t)) ([a] :- t) Source #

List cons-cell grammar. Construct on forward run, deconstruct on backward run.

nil :: Grammar p t ([a] :- t) Source #

Empty list grammar. Construct empty list on forward run, check if list is empty on backward run.

insert :: Eq k => k -> Mismatch -> Grammar p (v :- ([(k, v)] :- t)) ([(k, v)] :- t) Source #

Assoc-list element grammar. Inserts an element (with static key) on forward run, look up an element on backward run.

insertMay :: Eq k => k -> Grammar p (Maybe v :- ([(k, v)] :- t)) ([(k, v)] :- t) Source #

Optional assoc-list element grammar. Like insert, but does not report a mismatch on backward run. Instead takes and produces a Maybe-value.

toDefault :: Eq a => a -> Grammar p (Maybe a :- t) (a :- t) Source #

Default value grammar. Replaces Nothing with a default value on forward run, an replaces a default value with Nothing on backward run.

coproduct :: [Grammar p a b] -> Grammar p a b Source #

Join alternative grammars in parallel.

onHead :: Grammar p a b -> Grammar p (a :- t) (b :- t) Source #

Focus a given grammar to the stack head.

onTail :: Grammar p ta tb -> Grammar p (h :- ta) (h :- tb) Source #

Focus a given grammar to the stack tail.

traversed :: Traversable f => Grammar p a b -> Grammar p (f a) (f b) Source #

Traverse a structure with a given grammar.

flipped :: Grammar p a b -> Grammar p b a Source #

Run a grammar with inputs and outputs flipped.

sealed :: Grammar p (a :- Void) (b :- Void) -> Grammar p a b Source #

Run a grammar operating on the stack head in a context where there is no stack.

coerced :: (Coercible a c, Coercible b d) => Grammar p (a :- t) (b :- t') -> Grammar p (c :- t) (d :- t') Source #

Run a grammar with the stack heads coerced to other (Coercible) types.

annotated :: Text -> Grammar p a b -> Grammar p a b Source #

Run a grammar with an annotation.