module Text.Grampa.ContextFree.LeftRecursive.Transformer (ParserT, SeparatedParser(..),
                                                          lift, liftPositive, tmap,
                                                          parseSeparated, separated)
where

import Text.Grampa.ContextFree.LeftRecursive (Fixed, SeparatedParser(..), FallibleWithExpectations(..),
                                              liftPositive, liftPure, mapPrimitive, parseSeparated, separated)
import qualified Text.Grampa.ContextFree.SortedMemoizing.Transformer as Transformer
import Text.Grampa.ContextFree.SortedMemoizing.Transformer (ResultListT(ResultList), FailureInfo(FailureInfo))

type ParserT m = Fixed (Transformer.ParserT m)

-- | Lift a parse-free computation into the parser.
lift :: Applicative m => m a -> ParserT m g s a
lift :: m a -> ParserT m g s a
lift = ParserT m g s a -> ParserT m g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
Alternative (p g s) =>
p g s a -> Fixed p g s a
liftPure (ParserT m g s a -> ParserT m g s a)
-> (m a -> ParserT m g s a) -> m a -> ParserT m g s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> ParserT m g s a
forall (m :: * -> *) a (g :: (* -> *) -> *) s.
m a -> ParserT m g s a
Transformer.lift

-- | Modify the computation carried by the parser.
tmap :: (m a -> m a) -> ParserT m g s a -> ParserT m g s a
tmap :: (m a -> m a) -> ParserT m g s a -> ParserT m g s a
tmap = (ParserT m g s a -> ParserT m g s a)
-> ParserT m g s a -> ParserT m g s a
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       a.
(p g s a -> p g s a) -> Fixed p g s a -> Fixed p g s a
mapPrimitive ((ParserT m g s a -> ParserT m g s a)
 -> ParserT m g s a -> ParserT m g s a)
-> ((m a -> m a) -> ParserT m g s a -> ParserT m g s a)
-> (m a -> m a)
-> ParserT m g s a
-> ParserT m g s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (m a -> m a) -> ParserT m g s a -> ParserT m g s a
forall (m :: * -> *) a b (g :: (* -> *) -> *) s.
(m a -> m b) -> ParserT m g s a -> ParserT m g s b
Transformer.tmap

instance FallibleWithExpectations (ResultListT m g) where
   hasSuccess :: ResultListT m g s a -> Bool
hasSuccess (ResultList [] _) = Bool
False
   hasSuccess _ = Bool
True
   failureOf :: ResultListT m g s a -> FailureInfo s
failureOf (ResultList _ failure :: FailureInfo s
failure) = FailureInfo s
failure
   failWith :: FailureInfo s -> ResultListT m g s a
failWith = [ResultsOfLengthT m g s a] -> FailureInfo s -> ResultListT m g s a
forall (m :: * -> *) (g :: (* -> *) -> *) s r.
[ResultsOfLengthT m g s r] -> FailureInfo s -> ResultListT m g s r
ResultList []
   expectations :: ResultListT m g s a -> [Expected s]
expectations (ResultList _ (FailureInfo _ expected :: [Expected s]
expected)) = [Expected s]
expected