gll-0.2.0.3: GLL parser with simple combinator interface

Safe HaskellNone
LanguageHaskell98

GLL.Combinators.MemInterface

Synopsis

Documentation

class HasAlts a where Source

Methods

altsOf :: a b -> ([] :. IMParser) b Source

parse :: IsSymbParser s => s a -> [Token] -> IO [a] Source

The semantic results of a parser, given a string of Tokens

parseString :: IsSymbParser s => s a -> String -> IO [a] Source

Parse a string of characters

(<::=>) :: HasAlts b => String -> b a -> SymbParser a infixl 2 Source

Use this combinator on all combinators that might have an infinite number of derivations for some input string. A non-terminal has this property if and only if it is left-recursive and would be left-recursive if all the right-hand sides of the productions of the grammar are reversed.

(<:=>) :: HasAlts b => String -> b a -> SymbParser a infixl 2 Source

Use this combinator on all recursive non-terminals

(<$>) :: IsSymbParser s => (a -> b) -> s a -> IMParser b infixl 4 Source

(<$) :: IsSymbParser s => b -> s a -> IMParser b infixl 4 Source

(<*>) :: (IsIMParser i, IsSymbParser s) => i (a -> b) -> s a -> IMParser b infixl 4 Source

(<*) :: (IsIMParser i, IsSymbParser s) => i b -> s a -> IMParser b infixl 4 Source

(<|>) :: (IsIMParser i, HasAlts b) => i a -> b a -> ([] :. IMParser) a infixr 3 Source

data (g :. f) a :: (* -> *) -> (* -> *) -> * -> * infixl 9

Composition of unary type constructors

There are (at least) two useful Monoid instances, so you'll have to pick one and type-specialize it (filling in all or parts of g and/or f).

    -- standard Monoid instance for Applicative applied to Monoid
    instance (Applicative (g :. f), Monoid a) => Monoid ((g :. f) a) where
      { mempty = pure mempty; mappend = liftA2 mappend }
    -- Especially handy when g is a Monoid_f.
    instance Monoid (g (f a)) => Monoid ((g :. f) a) where
      { mempty = O mempty; mappend = inO2 mappend }

Corresponding to the first and second definitions above,

    instance (Applicative g, Monoid_f f) => Monoid_f (g :. f) where
      { mempty_f = O (pure mempty_f); mappend_f = inO2 (liftA2 mappend_f) }
    instance Monoid_f g => Monoid_f (g :. f) where
      { mempty_f = O mempty_f; mappend_f = inO2 mappend_f }

Similarly, there are two useful Functor instances and two useful ContraFunctor instances.

    instance (      Functor g,       Functor f) => Functor (g :. f) where fmap = fmapFF
    instance (ContraFunctor g, ContraFunctor f) => Functor (g :. f) where fmap = fmapCC

    instance (      Functor g, ContraFunctor f) => ContraFunctor (g :. f) where contraFmap = contraFmapFC
    instance (ContraFunctor g,       Functor f) => ContraFunctor (g :. f) where contraFmap = contraFmapCF

However, it's such a bother to define the Functor instances per composition type, I've left the fmapFF case in. If you want the fmapCC one, you're out of luck for now. I'd love to hear a good solution. Maybe someday Haskell will do Prolog-style search for instances, subgoaling the constraints, rather than just matching instance heads.

Instances

(Functor g, Functor f) => Functor ((:.) g f) 
(Applicative g, Applicative f) => Applicative ((:.) g f) 
(Foldable g, Foldable f, Functor g) => Foldable ((:.) g f) 
(Traversable g, Traversable f) => Traversable ((:.) g f) 
IsSymbParser ((:.) [] IMParser) 
IsIMParser ((:.) [] IMParser) 
HasAlts ((:.) [] IMParser) 
IsSymbParser ((:.) [] IMParser) 
IsIMParser ((:.) [] IMParser) 
HasAlts ((:.) [] IMParser) 
Eq (g (f a)) => Eq ((:.) g f a) 
Show (g (f a)) => Show ((:.) g f a) 

memo :: IsSymbParser s => MemoRef [a] -> s a -> SymbParser a Source

type MemoTable a = IntMap (IntMap a) Source

use ::= to enforce using parse context (to handle left-recursion)