{-# LANGUAGE FlexibleContexts       #-}
{-# LANGUAGE FlexibleInstances      #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses  #-}
{-# LANGUAGE ScopedTypeVariables    #-}
{-# LANGUAGE TupleSections          #-}
{-# LANGUAGE UndecidableInstances   #-}

{-|
Module      : Hectoparsec.Class
Copyright   : (c) comp 2020
License     : MIT
Maintainer  : onecomputer00@gmail.com
Stability   : stable
Portability : portable

Typeclass for a monad that implements the basic combinators for parsing.

Combinators that are derived from the basic combinators are also defined here.
-}
module Hectoparsec.Class
    ( -- * MonadParser typeclass
      MonadParser(..)
      -- * Derived combinators
      -- ** Input consumption
    , anyToken
    , char
    , string
    , satisfy
    , peek
    , peekNext
    , countTokens
    , tokenWhile
    , tokenWhile1
    , matchRest
    , atEnd
      -- ** Label combinators
    , label
    , (<?>)
    , hidden
      -- ** Error combinators
    , restore
    , unexpected
    , failure
    , customError
      -- ** State combinators
    , getsState
    , modifyState
    , getInput
    , getsInput
    , putInput
    , modifyInput
    , getPos
    , getOffset
    ) where

import           Control.Monad
import           Control.Monad.Trans
import qualified Control.Monad.Trans.Accum as M
import qualified Control.Monad.Trans.Except as M
import qualified Control.Monad.Trans.Identity as M
import qualified Control.Monad.Trans.Maybe as M
import qualified Control.Monad.Trans.RWS.CPS as C
import qualified Control.Monad.Trans.RWS.Lazy as L
import qualified Control.Monad.Trans.RWS.Strict as S
import qualified Control.Monad.Trans.Reader as M
import qualified Control.Monad.Trans.State.Lazy as L
import qualified Control.Monad.Trans.State.Strict as S
import qualified Control.Monad.Trans.Writer.CPS as C
import qualified Control.Monad.Trans.Writer.Lazy as L
import qualified Control.Monad.Trans.Writer.Strict as S
import           Data.Proxy
import           Hectoparsec.Error
import           Hectoparsec.Pos
import           Hectoparsec.State
import           Hectoparsec.Stream

{-|
Monad @m@ that implements the primitive parsers for a stream @s@, using custom errors @e@ and custom labels @l@. These
parsers should have a notion of whether the input was consumed or not. They should also track the parser state, errors,
and labels.

The 'MonadPlus' instance should be equal to the 'Control.Applicative.Alternative' instance, and it should implement the
operations for branching parsers. In particular, @p 'Control.Applicative.<|>' q@ must commit to the first branch
that consumes input.

The 'Hectoparsec.ParserT' instance is the canonical instance for this class.
-}
class (Stream s, MonadPlus m) => MonadParser s e l m | m -> s e l where
    {-|
    Match on a token, returning either the value or an error. If this succeeds, input is consumed.

    For matching by equality, use the derived 'char' combinator.
    -}
    matchToken
        :: -- | A function to match on tokens. It can return either an error item or the resulting value.
           (Maybe (Token s) -> Either (ErrorItem s e l) a)
        -> m a

    {-|
    Match on a chunk of at most /n/ length, returning either the value or an error. If it fails, the parser will
    backtrack the stream. If this succeeds and chunk is non-empty, input is consumed.

    For matching by equality, use the derived 'string' combinator.
    -}
    matchTokens
        :: -- | Length /n/ of the chunk to take. If /n/ <= 0, no tokens are taken.
           Int
        -> -- | A function to match on the chunk. If the chunk is empty, then /n/ <= 0 or we are at the end.
           (Chunk s -> Either (ErrorItem s e l) a)
        -> m a

    {-|
    Take tokens that satisfy a predicate, and match on them, returning either the value or an error. If it fails,
    the parser will backtrack the stream. If this succeeds and the chunk is non-empty, input is consumed.

    For matching just by a predicate, use the derived 'tokenWhile' and 'tokenWhile1' combinators.
    -}
    matchTokenWhile
        :: -- | The predicate to check a token.
           (Token s -> Bool)
        -> -- | A function to match on the chunk.
           (Chunk s -> Either (ErrorItem s e l) a)
        -> m a

    -- | A parser that only succeeds at the end of the stream.
    endOfInput :: m ()

    {-|
    Adds or removes a label for a parser. See 'label' and 'hidden' for more information.

    By default, no parsers defined in this library are labelled. It is entirely up to you to label parsers.
    -}
    withLabel :: Maybe l -> m a -> m a

    {-|
    Backtracks a parser if it failed. That is, if a parser @p@ fails, then @try p@ will be considered to not have
    consumed input. This can be used for arbitrary look ahead.

    In the example below, @alt1@ will not act as expected, since @red@ will consume the \'r', meaning @rad@ will not
    be tried. Adding @try@ in @alt2@ will allow it to work as expected.

@
red = 'char' \'r' >> 'char' \'e' >> 'char' \'d'
rad = 'char' \'r' >> 'char' \'a' >> 'char' \'d'
alt1 = red \<|> rad
alt2 = try red \<|> rad
@
    -}
    try :: m a -> m a

    {-|
    Backtracks a parser if it succeeds. That is, if a parser @p@ succeeds, then @lookAhead p@ will be considered to not
    have consumed input.

    This does not affect the parser if it fails, i.e. failed parsers can still consume input. Use 'try' along with this
    function if you need to backtrack on failure too.
    -}
    lookAhead :: m a -> m a

    {-|
    Creates a parser that only succeeds if the original fails.

    This parser never consumes input nor modifies parser state.
    -}
    notFollowedBy :: m a -> m ()

    {-|
    Creates a parser that can recover from parse failures.

    If the recovery parser fails, it will act as if only the original parser failed.
    -}
    recover :: (ParseError s e l -> m a) -> m a -> m a

    {-|
    Observes the result of a parser, allowing parsing to continue on failure.

    Note that this does not backtrack the parser whether it succeeds or fails.
    -}
    observing :: m a -> m (Either (ParseError s e l) a)

    -- | Fails parsing with a parse error.
    parseError :: ParseError s e l -> m a

    -- | Gets the parser state.
    getState :: m (State s)

    -- | Replaces the parser state.
    putState :: State s -> m ()

-- | Parses any token.
anyToken :: MonadParser s e l m => m (Token s)
anyToken :: forall s e l (m :: * -> *). MonadParser s e l m => m (Token s)
anyToken = (Maybe (Token s) -> Either (ErrorItem s e l) (Token s))
-> m (Token s)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken ((Maybe (Token s) -> Either (ErrorItem s e l) (Token s))
 -> m (Token s))
-> (Maybe (Token s) -> Either (ErrorItem s e l) (Token s))
-> m (Token s)
forall a b. (a -> b) -> a -> b
$ \Maybe (Token s)
m ->
    case Maybe (Token s)
m of
        Maybe (Token s)
Nothing -> ErrorItem s e l -> Either (ErrorItem s e l) (Token s)
forall a b. a -> Either a b
Left (Unexpected s -> [l] -> ErrorItem s e l
forall s e l. Unexpected s -> [l] -> ErrorItem s e l
ErrorItemLabels Unexpected s
forall s. Unexpected s
UnexpectedEnd [])
        Just Token s
x -> Token s -> Either (ErrorItem s e l) (Token s)
forall a b. b -> Either a b
Right Token s
x
{-# INLINABLE anyToken #-}

{-|
Parses a specific token. Note that this parser is not labelled by default.

@semicolon = char \';\'@
-}
char :: (MonadParser s e l m, Eq (Token s)) => Token s -> m (Token s)
char :: forall s e l (m :: * -> *).
(MonadParser s e l m, Eq (Token s)) =>
Token s -> m (Token s)
char Token s
expected = (Maybe (Token s) -> Either (ErrorItem s e l) (Token s))
-> m (Token s)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken ((Maybe (Token s) -> Either (ErrorItem s e l) (Token s))
 -> m (Token s))
-> (Maybe (Token s) -> Either (ErrorItem s e l) (Token s))
-> m (Token s)
forall a b. (a -> b) -> a -> b
$ \Maybe (Token s)
m ->
    case Maybe (Token s)
m of
        Just Token s
t | Token s
t Token s -> Token s -> Bool
forall a. Eq a => a -> a -> Bool
== Token s
expected -> Token s -> Either (ErrorItem s e l) (Token s)
forall a b. b -> Either a b
Right Token s
t
        Just Token s
t -> ErrorItem s e l -> Either (ErrorItem s e l) (Token s)
forall a b. a -> Either a b
Left (Unexpected s -> [l] -> ErrorItem s e l
forall s e l. Unexpected s -> [l] -> ErrorItem s e l
ErrorItemLabels (Token s -> Unexpected s
forall s. Token s -> Unexpected s
UnexpectedToken Token s
t) [])
        Maybe (Token s)
Nothing -> ErrorItem s e l -> Either (ErrorItem s e l) (Token s)
forall a b. a -> Either a b
Left (Unexpected s -> [l] -> ErrorItem s e l
forall s e l. Unexpected s -> [l] -> ErrorItem s e l
ErrorItemLabels Unexpected s
forall s. Unexpected s
UnexpectedEnd [])
{-# INLINABLE char #-}

{-|
Parses a specific sequence of tokens. This fully backtracks, since it uses 'matchTokens'. Note that this parser is not
labelled by default.

@color = string \"red\" \<|> string \"green\" \<|> string \"blue\"@
-}
string :: forall s e l m. (MonadParser s e l m, Eq (Chunk s)) => Chunk s -> m (Chunk s)
string :: forall s e l (m :: * -> *).
(MonadParser s e l m, Eq (Chunk s)) =>
Chunk s -> m (Chunk s)
string Chunk s
expected = Int
-> (Chunk s -> Either (ErrorItem s e l) (Chunk s)) -> m (Chunk s)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens (Proxy s -> Chunk s -> Int
forall s (proxy :: * -> *). Stream s => proxy s -> Chunk s -> Int
chunkLength Proxy s
proxy Chunk s
expected) ((Chunk s -> Either (ErrorItem s e l) (Chunk s)) -> m (Chunk s))
-> (Chunk s -> Either (ErrorItem s e l) (Chunk s)) -> m (Chunk s)
forall a b. (a -> b) -> a -> b
$ \Chunk s
ys ->
    if Chunk s
expected Chunk s -> Chunk s -> Bool
forall a. Eq a => a -> a -> Bool
== Chunk s
ys
        then Chunk s -> Either (ErrorItem s e l) (Chunk s)
forall a b. b -> Either a b
Right Chunk s
ys
        else ErrorItem s e l -> Either (ErrorItem s e l) (Chunk s)
forall a b. a -> Either a b
Left (Unexpected s -> [l] -> ErrorItem s e l
forall s e l. Unexpected s -> [l] -> ErrorItem s e l
ErrorItemLabels (Chunk s -> Unexpected s
forall s. Chunk s -> Unexpected s
UnexpectedChunk Chunk s
ys) [])
    where
        proxy :: Proxy s
proxy = Proxy s
forall {k} (t :: k). Proxy t
Proxy :: Proxy s
{-# INLINABLE string #-}

{-|
Parses a token that satisfies a predicate.

@digit = satisfy isDigit@
-}
satisfy :: MonadParser s e l m => (Token s -> Bool) -> m (Token s)
satisfy :: forall s e l (m :: * -> *).
MonadParser s e l m =>
(Token s -> Bool) -> m (Token s)
satisfy Token s -> Bool
p = (Maybe (Token s) -> Either (ErrorItem s e l) (Token s))
-> m (Token s)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken ((Maybe (Token s) -> Either (ErrorItem s e l) (Token s))
 -> m (Token s))
-> (Maybe (Token s) -> Either (ErrorItem s e l) (Token s))
-> m (Token s)
forall a b. (a -> b) -> a -> b
$ \Maybe (Token s)
m ->
    case Maybe (Token s)
m of
        Just Token s
t | Token s -> Bool
p Token s
t -> Token s -> Either (ErrorItem s e l) (Token s)
forall a b. b -> Either a b
Right Token s
t
        Just Token s
t -> ErrorItem s e l -> Either (ErrorItem s e l) (Token s)
forall a b. a -> Either a b
Left (Unexpected s -> [l] -> ErrorItem s e l
forall s e l. Unexpected s -> [l] -> ErrorItem s e l
ErrorItemLabels (Token s -> Unexpected s
forall s. Token s -> Unexpected s
UnexpectedToken Token s
t) [])
        Maybe (Token s)
Nothing -> ErrorItem s e l -> Either (ErrorItem s e l) (Token s)
forall a b. a -> Either a b
Left (Unexpected s -> [l] -> ErrorItem s e l
forall s e l. Unexpected s -> [l] -> ErrorItem s e l
ErrorItemLabels Unexpected s
forall s. Unexpected s
UnexpectedEnd [])
{-# INLINABLE satisfy #-}

-- | Peeks at the next token, without advancing the stream in any way.
peek :: MonadParser s e l m => m (Maybe (Token s))
peek :: forall s e l (m :: * -> *).
MonadParser s e l m =>
m (Maybe (Token s))
peek = ((Token s, s) -> Token s) -> Maybe (Token s, s) -> Maybe (Token s)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Token s, s) -> Token s
forall a b. (a, b) -> a
fst (Maybe (Token s, s) -> Maybe (Token s))
-> (s -> Maybe (Token s, s)) -> s -> Maybe (Token s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> Maybe (Token s, s)
forall s. Stream s => s -> Maybe (Token s, s)
streamUncons (s -> Maybe (Token s)) -> m s -> m (Maybe (Token s))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m s
forall s e l (m :: * -> *). MonadParser s e l m => m s
getInput
{-# INLINABLE peek #-}

{-|
Peeks at the next token, without advancing the stream in any way. If the stream is empty (i.e. there is no next token),
an unexpected end of input error is reported.
-}
peekNext :: MonadParser s e l m => m (Token s)
peekNext :: forall s e l (m :: * -> *). MonadParser s e l m => m (Token s)
peekNext = do
    Maybe (Token s, s)
m <- s -> Maybe (Token s, s)
forall s. Stream s => s -> Maybe (Token s, s)
streamUncons (s -> Maybe (Token s, s)) -> m s -> m (Maybe (Token s, s))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m s
forall s e l (m :: * -> *). MonadParser s e l m => m s
getInput
    case Maybe (Token s, s)
m of
        Maybe (Token s, s)
Nothing -> Unexpected s -> [l] -> m (Token s)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Unexpected s -> [l] -> m a
unexpected Unexpected s
forall s. Unexpected s
UnexpectedEnd []
        Just (Token s
x, s
_) -> Token s -> m (Token s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Token s
x
{-# INLINABLE peekNext #-}

-- | Parses a chunk of length exactly /n/, not more, not less. This fully backtracks, since it uses 'matchTokens'.
countTokens :: forall s e l m. MonadParser s e l m => Int -> m (Chunk s)
countTokens :: forall s e l (m :: * -> *).
MonadParser s e l m =>
Int -> m (Chunk s)
countTokens Int
n = Int
-> (Chunk s -> Either (ErrorItem s e l) (Chunk s)) -> m (Chunk s)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens Int
n ((Chunk s -> Either (ErrorItem s e l) (Chunk s)) -> m (Chunk s))
-> (Chunk s -> Either (ErrorItem s e l) (Chunk s)) -> m (Chunk s)
forall a b. (a -> b) -> a -> b
$ \Chunk s
ys ->
    if Proxy s -> Chunk s -> Int
forall s (proxy :: * -> *). Stream s => proxy s -> Chunk s -> Int
chunkLength Proxy s
proxy Chunk s
ys Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n
        then Chunk s -> Either (ErrorItem s e l) (Chunk s)
forall a b. b -> Either a b
Right Chunk s
ys
        else ErrorItem s e l -> Either (ErrorItem s e l) (Chunk s)
forall a b. a -> Either a b
Left (Unexpected s -> [l] -> ErrorItem s e l
forall s e l. Unexpected s -> [l] -> ErrorItem s e l
ErrorItemLabels (Chunk s -> Unexpected s
forall s. Chunk s -> Unexpected s
UnexpectedChunk Chunk s
ys) [])
    where
        proxy :: Proxy s
proxy = Proxy s
forall {k} (t :: k). Proxy t
Proxy :: Proxy s
{-# INLINABLE countTokens #-}

{-|
Takes zero or more tokens that match a predicate. The resulting parser cannot fail. This fully backtracks,
since it uses 'matchTokenWhile'. This should be more performant than using 'Control.Applicative.many' and 'satisfy'.

@digits = tokenWhile isDigit@
-}
tokenWhile :: MonadParser s e l m => (Token s -> Bool) -> m (Chunk s)
tokenWhile :: forall s e l (m :: * -> *).
MonadParser s e l m =>
(Token s -> Bool) -> m (Chunk s)
tokenWhile Token s -> Bool
p = (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) (Chunk s)) -> m (Chunk s)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile Token s -> Bool
p Chunk s -> Either (ErrorItem s e l) (Chunk s)
forall a b. b -> Either a b
Right
{-# INLINABLE tokenWhile #-}

{-|
Takes one or more tokens that match a predicate. This fully backtracks, since it uses 'matchTokenWhile'. This should
be more performant than using 'Control.Applicative.some' and 'satisfy'.

@digits1 = tokenWhile1 isDigit@
-}
tokenWhile1 :: forall s e l m. MonadParser s e l m => (Token s -> Bool) -> m (Chunk s)
tokenWhile1 :: forall s e l (m :: * -> *).
MonadParser s e l m =>
(Token s -> Bool) -> m (Chunk s)
tokenWhile1 Token s -> Bool
p = (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) (Chunk s)) -> m (Chunk s)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile Token s -> Bool
p ((Chunk s -> Either (ErrorItem s e l) (Chunk s)) -> m (Chunk s))
-> (Chunk s -> Either (ErrorItem s e l) (Chunk s)) -> m (Chunk s)
forall a b. (a -> b) -> a -> b
$ \Chunk s
xs ->
    if Proxy s -> Chunk s -> Bool
forall s (proxy :: * -> *). Stream s => proxy s -> Chunk s -> Bool
chunkNull Proxy s
proxy Chunk s
xs
        then ErrorItem s e l -> Either (ErrorItem s e l) (Chunk s)
forall a b. a -> Either a b
Left (Unexpected s -> [l] -> ErrorItem s e l
forall s e l. Unexpected s -> [l] -> ErrorItem s e l
ErrorItemLabels Unexpected s
forall s. Unexpected s
UnexpectedEnd [])
        else Chunk s -> Either (ErrorItem s e l) (Chunk s)
forall a b. b -> Either a b
Right Chunk s
xs
    where
        proxy :: Proxy s
proxy = Proxy s
forall {k} (t :: k). Proxy t
Proxy :: Proxy s
{-# INLINABLE tokenWhile1 #-}

-- | Consumes the rest of the input. This parser cannot fail, though the chunk may be empty.
matchRest :: MonadParser s e l m => m (Chunk s)
matchRest :: forall s e l (m :: * -> *). MonadParser s e l m => m (Chunk s)
matchRest = (Token s -> Bool) -> m (Chunk s)
forall s e l (m :: * -> *).
MonadParser s e l m =>
(Token s -> Bool) -> m (Chunk s)
tokenWhile (Bool -> Token s -> Bool
forall a b. a -> b -> a
const Bool
True)
{-# INLINABLE matchRest #-}

-- | A parser that checks whether we are at the end of the stream.
atEnd :: MonadParser s e l m => m Bool
atEnd :: forall s e l (m :: * -> *). MonadParser s e l m => m Bool
atEnd = do
    Maybe (Token s, s)
m <- s -> Maybe (Token s, s)
forall s. Stream s => s -> Maybe (Token s, s)
streamUncons (s -> Maybe (Token s, s)) -> m s -> m (Maybe (Token s, s))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m s
forall s e l (m :: * -> *). MonadParser s e l m => m s
getInput
    case Maybe (Token s, s)
m of
        Maybe (Token s, s)
Nothing -> Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
        Just (Token s, s)
_ -> Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
{-# INLINABLE atEnd #-}

{-|
Adds a label to a parser. This is used for labelling parsers that do not have one for better error messages, or for
labelling a complex combination of parsers where you want to give it a more general label instead of merging the labels
of each constituent parser.

@label lbl p = 'withLabel' (Just lbl) p@
-}
label :: MonadParser s e l m => l -> m a -> m a
label :: forall s e l (m :: * -> *) a.
MonadParser s e l m =>
l -> m a -> m a
label l
lbl m a
p = Maybe l -> m a -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel (l -> Maybe l
forall a. a -> Maybe a
Just l
lbl) m a
p
{-# INLINABLE label #-}

-- | Adds a label to a parser. Simply a synonym for @flip 'label'@.
infix 0 <?>
(<?>) :: MonadParser s e l m => m a -> l -> m a
m a
p <?> :: forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> l -> m a
<?> l
lbl = l -> m a -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
l -> m a -> m a
label l
lbl m a
p
{-# INLINABLE (<?>) #-}

{-|
Removes the label from a parser. This can be used to hide labels from errors.

@hidden p = 'withLabel' Nothing p@
-}
hidden :: MonadParser s e l m => m a -> m a
hidden :: forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
hidden m a
p = Maybe l -> m a -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
forall a. Maybe a
Nothing m a
p
{-# INLINABLE hidden #-}

{-|
Restores the state to before using the parser if the error passes a predicate.

The result parser still fails if the given parser fails.
-}
restore :: MonadParser s e l m => (ParseError s e l -> Bool) -> m a -> m a
restore :: forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> Bool) -> m a -> m a
restore ParseError s e l -> Bool
f m a
p = do
    State s
st <- m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    Either (ParseError s e l) a
r <- m a -> m (Either (ParseError s e l) a)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing m a
p
    case Either (ParseError s e l) a
r of
        Right a
x -> a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
        Left ParseError s e l
e -> do
            Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (ParseError s e l -> Bool
f ParseError s e l
e) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState State s
st
            ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError ParseError s e l
e
{-# INLINABLE restore #-}

-- | Fails parsing with an unexpected item and a list of expected items.
unexpected :: MonadParser s e l m => Unexpected s -> [l] -> m a
unexpected :: forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Unexpected s -> [l] -> m a
unexpected Unexpected s
unex [l]
ls = do
    State s
st <- m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError (State s -> ErrorItem s e l -> ParseError s e l
forall s e l. State s -> ErrorItem s e l -> ParseError s e l
makeErrorAt State s
st (Unexpected s -> [l] -> ErrorItem s e l
forall s e l. Unexpected s -> [l] -> ErrorItem s e l
ErrorItemLabels Unexpected s
unex [l]
ls))
{-# INLINABLE unexpected #-}

-- | Fails parsing with a failure message. These errors are generally for broken invariants.
failure :: MonadParser s e l m => String -> m a
failure :: forall s e l (m :: * -> *) a. MonadParser s e l m => String -> m a
failure String
msg = do
    State s
st <- m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError (State s -> ErrorItem s e l -> ParseError s e l
forall s e l. State s -> ErrorItem s e l -> ParseError s e l
makeErrorAt State s
st ([Message e] -> ErrorItem s e l
forall s e l. [Message e] -> ErrorItem s e l
ErrorItemMessages [String -> Message e
forall e. String -> Message e
MessageFail String
msg]))
{-# INLINABLE failure #-}

-- | Fails parsing with a custom error.
customError :: MonadParser s e l m => e -> m a
customError :: forall s e l (m :: * -> *) a. MonadParser s e l m => e -> m a
customError e
e = do
    State s
st <- m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError (State s -> ErrorItem s e l -> ParseError s e l
forall s e l. State s -> ErrorItem s e l -> ParseError s e l
makeErrorAt State s
st ([Message e] -> ErrorItem s e l
forall s e l. [Message e] -> ErrorItem s e l
ErrorItemMessages [e -> Message e
forall e. e -> Message e
MessageCustom e
e]))
{-# INLINABLE customError #-}

{-|
Gets the parser state applied to a function.

@getsState f = f \<$> 'getState'@
-}
getsState :: MonadParser s e l m => (State s -> a) -> m a
getsState :: forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(State s -> a) -> m a
getsState State s -> a
f = State s -> a
f (State s -> a) -> m (State s) -> m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
{-# INLINABLE getsState #-}

{-|
Modifies the parser state by a function.

@modifyState f = 'getState' >>= 'putState' . f@
-}
modifyState :: MonadParser s e l m => (State s -> State s) -> m ()
modifyState :: forall s e l (m :: * -> *).
MonadParser s e l m =>
(State s -> State s) -> m ()
modifyState State s -> State s
f = m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState m (State s) -> (State s -> m ()) -> m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState (State s -> m ()) -> (State s -> State s) -> State s -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> State s
f
{-# INLINABLE modifyState #-}

-- | Gets the input.
getInput :: MonadParser s e l m => m s
getInput :: forall s e l (m :: * -> *). MonadParser s e l m => m s
getInput = (State s -> s) -> m s
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(State s -> a) -> m a
getsState State s -> s
forall s. State s -> s
stateInput
{-# INLINABLE getInput #-}

{-|
Gets the input applied to a function.

@getsInput f = f \<$> 'getInput'@
-}
getsInput :: MonadParser s e l m => (s -> a) -> m a
getsInput :: forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(s -> a) -> m a
getsInput s -> a
f = (State s -> a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(State s -> a) -> m a
getsState (s -> a
f (s -> a) -> (State s -> s) -> State s -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> s
forall s. State s -> s
stateInput)
{-# INLINABLE getsInput #-}

-- | Replaces the input.
putInput :: MonadParser s e l m => s -> m ()
putInput :: forall s e l (m :: * -> *). MonadParser s e l m => s -> m ()
putInput s
s = (State s -> State s) -> m ()
forall s e l (m :: * -> *).
MonadParser s e l m =>
(State s -> State s) -> m ()
modifyState ((State s -> State s) -> m ()) -> (State s -> State s) -> m ()
forall a b. (a -> b) -> a -> b
$ \State s
st -> State s
st { stateInput :: s
stateInput = s
s }
{-# INLINABLE putInput #-}

{-|
Modifies the input by a function.

@modifyInput f = 'getInput' >>= 'putInput' . f@
-}
modifyInput :: MonadParser s e l m => (s -> s) -> m ()
modifyInput :: forall s e l (m :: * -> *). MonadParser s e l m => (s -> s) -> m ()
modifyInput s -> s
f = m s
forall s e l (m :: * -> *). MonadParser s e l m => m s
getInput m s -> (s -> m ()) -> m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => s -> m ()
putInput (s -> m ()) -> (s -> s) -> s -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> s
f
{-# INLINABLE modifyInput #-}

-- | Gets the position in the source text.
getPos :: MonadParser s e l m => m Pos
getPos :: forall s e l (m :: * -> *). MonadParser s e l m => m Pos
getPos = (State s -> Pos) -> m Pos
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(State s -> a) -> m a
getsState State s -> Pos
forall s. State s -> Pos
statePos
{-# INLINABLE getPos #-}

-- | Gets the offset in the input stream.
getOffset :: MonadParser s e l m => m Int
getOffset :: forall s e l (m :: * -> *). MonadParser s e l m => m Int
getOffset = (State s -> Int) -> m Int
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(State s -> a) -> m a
getsState State s -> Int
forall s. State s -> Int
stateOffset
{-# INLINABLE getOffset #-}

infixr 9 .:
(.:) :: (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: :: forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
(.:) = ((a2 -> b) -> a2 -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) (((a2 -> b) -> a2 -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c)
-> ((b -> c) -> (a2 -> b) -> a2 -> c)
-> (b -> c)
-> (a1 -> a2 -> b)
-> a1
-> a2
-> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> c) -> (a2 -> b) -> a2 -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.)
{-# INLINE (.:) #-}

infixr 9 .::
(.::) :: (b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
.:: :: forall b c a1 a2 a3.
(b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
(.::) = ((a2 -> a3 -> b) -> a2 -> a3 -> c)
-> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) (((a2 -> a3 -> b) -> a2 -> a3 -> c)
 -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c)
-> ((b -> c) -> (a2 -> a3 -> b) -> a2 -> a3 -> c)
-> (b -> c)
-> (a1 -> a2 -> a3 -> b)
-> a1
-> a2
-> a3
-> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a3 -> b) -> a3 -> c) -> (a2 -> a3 -> b) -> a2 -> a3 -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) (((a3 -> b) -> a3 -> c) -> (a2 -> a3 -> b) -> a2 -> a3 -> c)
-> ((b -> c) -> (a3 -> b) -> a3 -> c)
-> (b -> c)
-> (a2 -> a3 -> b)
-> a2
-> a3
-> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> c) -> (a3 -> b) -> a3 -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.)
{-# INLINE (.::) #-}

instance (Monoid w, MonadParser s e l m) => MonadParser s e l (M.AccumT w m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> AccumT w m a
matchToken = m a -> AccumT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> AccumT w m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> AccumT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> AccumT w m a
matchTokens = m a -> AccumT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> AccumT w m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> AccumT w m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> AccumT w m a
matchTokenWhile = m a -> AccumT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> AccumT w m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> AccumT w m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: AccumT w m ()
endOfInput = m () -> AccumT w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> AccumT w m a -> AccumT w m a
withLabel Maybe l
l = (w -> m (a, w)) -> AccumT w m a
forall w (m :: * -> *) a. (w -> m (a, w)) -> AccumT w m a
M.AccumT ((w -> m (a, w)) -> AccumT w m a)
-> (AccumT w m a -> w -> m (a, w)) -> AccumT w m a -> AccumT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (a, w) -> m (a, w))
-> (AccumT w m a -> w -> m (a, w)) -> AccumT w m a -> w -> m (a, w)
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: AccumT w m a -> w -> m (a, w)
forall w (m :: * -> *) a. AccumT w m a -> w -> m (a, w)
M.runAccumT
    try :: forall a. AccumT w m a -> AccumT w m a
try = (w -> m (a, w)) -> AccumT w m a
forall w (m :: * -> *) a. (w -> m (a, w)) -> AccumT w m a
M.AccumT ((w -> m (a, w)) -> AccumT w m a)
-> (AccumT w m a -> w -> m (a, w)) -> AccumT w m a -> AccumT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (a, w) -> m (a, w))
-> (AccumT w m a -> w -> m (a, w)) -> AccumT w m a -> w -> m (a, w)
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: AccumT w m a -> w -> m (a, w)
forall w (m :: * -> *) a. AccumT w m a -> w -> m (a, w)
M.runAccumT
    lookAhead :: forall a. AccumT w m a -> AccumT w m a
lookAhead = (w -> m (a, w)) -> AccumT w m a
forall w (m :: * -> *) a. (w -> m (a, w)) -> AccumT w m a
M.AccumT ((w -> m (a, w)) -> AccumT w m a)
-> (AccumT w m a -> w -> m (a, w)) -> AccumT w m a -> AccumT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (a, w) -> m (a, w))
-> (AccumT w m a -> w -> m (a, w)) -> AccumT w m a -> w -> m (a, w)
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: AccumT w m a -> w -> m (a, w)
forall w (m :: * -> *) a. AccumT w m a -> w -> m (a, w)
M.runAccumT
    notFollowedBy :: forall a. AccumT w m a -> AccumT w m ()
notFollowedBy AccumT w m a
m = (w -> m ((), w)) -> AccumT w m ()
forall w (m :: * -> *) a. (w -> m (a, w)) -> AccumT w m a
M.AccumT ((w -> m ((), w)) -> AccumT w m ())
-> (w -> m ((), w)) -> AccumT w m ()
forall a b. (a -> b) -> a -> b
$ \w
w -> (() -> ((), w)) -> m () -> m ((), w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, w
forall a. Monoid a => a
mempty) (m () -> m ((), w)) -> (m (a, w) -> m ()) -> m (a, w) -> m ((), w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (a, w) -> m ((), w)) -> m (a, w) -> m ((), w)
forall a b. (a -> b) -> a -> b
$ AccumT w m a -> w -> m (a, w)
forall w (m :: * -> *) a. AccumT w m a -> w -> m (a, w)
M.runAccumT AccumT w m a
m w
w
    recover :: forall a.
(ParseError s e l -> AccumT w m a) -> AccumT w m a -> AccumT w m a
recover ParseError s e l -> AccumT w m a
f AccumT w m a
m = (w -> m (a, w)) -> AccumT w m a
forall w (m :: * -> *) a. (w -> m (a, w)) -> AccumT w m a
M.AccumT ((w -> m (a, w)) -> AccumT w m a)
-> (w -> m (a, w)) -> AccumT w m a
forall a b. (a -> b) -> a -> b
$ \w
w -> (ParseError s e l -> m (a, w)) -> m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover ((AccumT w m a -> w -> m (a, w)) -> w -> AccumT w m a -> m (a, w)
forall a b c. (a -> b -> c) -> b -> a -> c
flip AccumT w m a -> w -> m (a, w)
forall w (m :: * -> *) a. AccumT w m a -> w -> m (a, w)
M.runAccumT w
w (AccumT w m a -> m (a, w))
-> (ParseError s e l -> AccumT w m a)
-> ParseError s e l
-> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> AccumT w m a
f) (AccumT w m a -> w -> m (a, w)
forall w (m :: * -> *) a. AccumT w m a -> w -> m (a, w)
M.runAccumT AccumT w m a
m w
w)
    observing :: forall a. AccumT w m a -> AccumT w m (Either (ParseError s e l) a)
observing AccumT w m a
m = (w -> m (Either (ParseError s e l) a, w))
-> AccumT w m (Either (ParseError s e l) a)
forall w (m :: * -> *) a. (w -> m (a, w)) -> AccumT w m a
M.AccumT ((w -> m (Either (ParseError s e l) a, w))
 -> AccumT w m (Either (ParseError s e l) a))
-> (w -> m (Either (ParseError s e l) a, w))
-> AccumT w m (Either (ParseError s e l) a)
forall a b. (a -> b) -> a -> b
$ \w
w -> (Either (ParseError s e l) (a, w)
 -> (Either (ParseError s e l) a, w))
-> m (Either (ParseError s e l) (a, w))
-> m (Either (ParseError s e l) a, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Either (ParseError s e l) (a, w)
-> (Either (ParseError s e l) a, w)
forall w b a. Monoid w => Either b (a, w) -> (Either b a, w)
adjustWriterT (m (Either (ParseError s e l) (a, w))
 -> m (Either (ParseError s e l) a, w))
-> (m (a, w) -> m (Either (ParseError s e l) (a, w)))
-> m (a, w)
-> m (Either (ParseError s e l) a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (Either (ParseError s e l) (a, w))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (a, w) -> m (Either (ParseError s e l) a, w))
-> m (a, w) -> m (Either (ParseError s e l) a, w)
forall a b. (a -> b) -> a -> b
$ AccumT w m a -> w -> m (a, w)
forall w (m :: * -> *) a. AccumT w m a -> w -> m (a, w)
M.runAccumT AccumT w m a
m w
w
    parseError :: forall a. ParseError s e l -> AccumT w m a
parseError = m a -> AccumT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> AccumT w m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> AccumT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: AccumT w m (State s)
getState = m (State s) -> AccumT w m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> AccumT w m ()
putState = m () -> AccumT w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> AccumT w m ())
-> (State s -> m ()) -> State s -> AccumT w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance (Monoid err, MonadParser s e l m) => MonadParser s e l (M.ExceptT err m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> ExceptT err m a
matchToken = m a -> ExceptT err m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ExceptT err m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> ExceptT err m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> ExceptT err m a
matchTokens = m a -> ExceptT err m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ExceptT err m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> ExceptT err m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> ExceptT err m a
matchTokenWhile = m a -> ExceptT err m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ExceptT err m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> ExceptT err m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: ExceptT err m ()
endOfInput = m () -> ExceptT err m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> ExceptT err m a -> ExceptT err m a
withLabel Maybe l
l = m (Either err a) -> ExceptT err m a
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
M.ExceptT (m (Either err a) -> ExceptT err m a)
-> (ExceptT err m a -> m (Either err a))
-> ExceptT err m a
-> ExceptT err m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (Either err a) -> m (Either err a)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (Either err a) -> m (Either err a))
-> (ExceptT err m a -> m (Either err a))
-> ExceptT err m a
-> m (Either err a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT err m a -> m (Either err a)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
M.runExceptT
    try :: forall a. ExceptT err m a -> ExceptT err m a
try = m (Either err a) -> ExceptT err m a
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
M.ExceptT (m (Either err a) -> ExceptT err m a)
-> (ExceptT err m a -> m (Either err a))
-> ExceptT err m a
-> ExceptT err m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Either err a) -> m (Either err a)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (Either err a) -> m (Either err a))
-> (ExceptT err m a -> m (Either err a))
-> ExceptT err m a
-> m (Either err a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT err m a -> m (Either err a)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
M.runExceptT
    lookAhead :: forall a. ExceptT err m a -> ExceptT err m a
lookAhead = m (Either err a) -> ExceptT err m a
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
M.ExceptT (m (Either err a) -> ExceptT err m a)
-> (ExceptT err m a -> m (Either err a))
-> ExceptT err m a
-> ExceptT err m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Either err a) -> m (Either err a)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (Either err a) -> m (Either err a))
-> (ExceptT err m a -> m (Either err a))
-> ExceptT err m a
-> m (Either err a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT err m a -> m (Either err a)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
M.runExceptT
    notFollowedBy :: forall a. ExceptT err m a -> ExceptT err m ()
notFollowedBy = m (Either err ()) -> ExceptT err m ()
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
M.ExceptT (m (Either err ()) -> ExceptT err m ())
-> (ExceptT err m a -> m (Either err ()))
-> ExceptT err m a
-> ExceptT err m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (() -> Either err ()) -> m () -> m (Either err ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap () -> Either err ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (m () -> m (Either err ()))
-> (ExceptT err m a -> m ())
-> ExceptT err m a
-> m (Either err ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Either err a) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (Either err a) -> m ())
-> (ExceptT err m a -> m (Either err a)) -> ExceptT err m a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT err m a -> m (Either err a)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
M.runExceptT
    recover :: forall a.
(ParseError s e l -> ExceptT err m a)
-> ExceptT err m a -> ExceptT err m a
recover ParseError s e l -> ExceptT err m a
f ExceptT err m a
m = m (Either err a) -> ExceptT err m a
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
M.ExceptT (m (Either err a) -> ExceptT err m a)
-> m (Either err a) -> ExceptT err m a
forall a b. (a -> b) -> a -> b
$ (ParseError s e l -> m (Either err a))
-> m (Either err a) -> m (Either err a)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover (ExceptT err m a -> m (Either err a)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
M.runExceptT (ExceptT err m a -> m (Either err a))
-> (ParseError s e l -> ExceptT err m a)
-> ParseError s e l
-> m (Either err a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> ExceptT err m a
f) (ExceptT err m a -> m (Either err a)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
M.runExceptT ExceptT err m a
m)
    observing :: forall a.
ExceptT err m a -> ExceptT err m (Either (ParseError s e l) a)
observing = m (Either err (Either (ParseError s e l) a))
-> ExceptT err m (Either (ParseError s e l) a)
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
M.ExceptT (m (Either err (Either (ParseError s e l) a))
 -> ExceptT err m (Either (ParseError s e l) a))
-> (ExceptT err m a
    -> m (Either err (Either (ParseError s e l) a)))
-> ExceptT err m a
-> ExceptT err m (Either (ParseError s e l) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either (ParseError s e l) (Either err a)
 -> Either err (Either (ParseError s e l) a))
-> m (Either (ParseError s e l) (Either err a))
-> m (Either err (Either (ParseError s e l) a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Either (ParseError s e l) (Either err a)
-> Either err (Either (ParseError s e l) a)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence (m (Either (ParseError s e l) (Either err a))
 -> m (Either err (Either (ParseError s e l) a)))
-> (ExceptT err m a
    -> m (Either (ParseError s e l) (Either err a)))
-> ExceptT err m a
-> m (Either err (Either (ParseError s e l) a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Either err a) -> m (Either (ParseError s e l) (Either err a))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (Either err a) -> m (Either (ParseError s e l) (Either err a)))
-> (ExceptT err m a -> m (Either err a))
-> ExceptT err m a
-> m (Either (ParseError s e l) (Either err a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT err m a -> m (Either err a)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
M.runExceptT
    parseError :: forall a. ParseError s e l -> ExceptT err m a
parseError = m a -> ExceptT err m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ExceptT err m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> ExceptT err m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: ExceptT err m (State s)
getState = m (State s) -> ExceptT err m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> ExceptT err m ()
putState = m () -> ExceptT err m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ExceptT err m ())
-> (State s -> m ()) -> State s -> ExceptT err m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance MonadParser s e l m => MonadParser s e l (M.IdentityT m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> IdentityT m a
matchToken = m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> IdentityT m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> IdentityT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> IdentityT m a
matchTokens = m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> IdentityT m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> IdentityT m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> IdentityT m a
matchTokenWhile = m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> IdentityT m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> IdentityT m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: IdentityT m ()
endOfInput = m () -> IdentityT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> IdentityT m a -> IdentityT m a
withLabel Maybe l
l = m a -> IdentityT m a
forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
M.IdentityT (m a -> IdentityT m a)
-> (IdentityT m a -> m a) -> IdentityT m a -> IdentityT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m a -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m a -> m a) -> (IdentityT m a -> m a) -> IdentityT m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentityT m a -> m a
forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
M.runIdentityT
    try :: forall a. IdentityT m a -> IdentityT m a
try = m a -> IdentityT m a
forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
M.IdentityT (m a -> IdentityT m a)
-> (IdentityT m a -> m a) -> IdentityT m a -> IdentityT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m a
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m a -> m a) -> (IdentityT m a -> m a) -> IdentityT m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentityT m a -> m a
forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
M.runIdentityT
    lookAhead :: forall a. IdentityT m a -> IdentityT m a
lookAhead = m a -> IdentityT m a
forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
M.IdentityT (m a -> IdentityT m a)
-> (IdentityT m a -> m a) -> IdentityT m a -> IdentityT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m a
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m a -> m a) -> (IdentityT m a -> m a) -> IdentityT m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentityT m a -> m a
forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
M.runIdentityT
    notFollowedBy :: forall a. IdentityT m a -> IdentityT m ()
notFollowedBy = m () -> IdentityT m ()
forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
M.IdentityT (m () -> IdentityT m ())
-> (IdentityT m a -> m ()) -> IdentityT m a -> IdentityT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m a -> m ()) -> (IdentityT m a -> m a) -> IdentityT m a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentityT m a -> m a
forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
M.runIdentityT
    recover :: forall a.
(ParseError s e l -> IdentityT m a)
-> IdentityT m a -> IdentityT m a
recover ParseError s e l -> IdentityT m a
f IdentityT m a
m = m a -> IdentityT m a
forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
M.IdentityT (m a -> IdentityT m a) -> m a -> IdentityT m a
forall a b. (a -> b) -> a -> b
$ (ParseError s e l -> m a) -> m a -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover (IdentityT m a -> m a
forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
M.runIdentityT (IdentityT m a -> m a)
-> (ParseError s e l -> IdentityT m a) -> ParseError s e l -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> IdentityT m a
f) (IdentityT m a -> m a
forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
M.runIdentityT IdentityT m a
m)
    observing :: forall a.
IdentityT m a -> IdentityT m (Either (ParseError s e l) a)
observing = m (Either (ParseError s e l) a)
-> IdentityT m (Either (ParseError s e l) a)
forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
M.IdentityT (m (Either (ParseError s e l) a)
 -> IdentityT m (Either (ParseError s e l) a))
-> (IdentityT m a -> m (Either (ParseError s e l) a))
-> IdentityT m a
-> IdentityT m (Either (ParseError s e l) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m (Either (ParseError s e l) a)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m a -> m (Either (ParseError s e l) a))
-> (IdentityT m a -> m a)
-> IdentityT m a
-> m (Either (ParseError s e l) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentityT m a -> m a
forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
M.runIdentityT
    parseError :: forall a. ParseError s e l -> IdentityT m a
parseError = m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> IdentityT m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> IdentityT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: IdentityT m (State s)
getState = m (State s) -> IdentityT m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> IdentityT m ()
putState = m () -> IdentityT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> IdentityT m ())
-> (State s -> m ()) -> State s -> IdentityT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance MonadParser s e l m => MonadParser s e l (M.MaybeT m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> MaybeT m a
matchToken = m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> MaybeT m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> MaybeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> MaybeT m a
matchTokens = m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> MaybeT m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> MaybeT m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> MaybeT m a
matchTokenWhile = m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> MaybeT m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> MaybeT m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: MaybeT m ()
endOfInput = m () -> MaybeT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> MaybeT m a -> MaybeT m a
withLabel Maybe l
l = m (Maybe a) -> MaybeT m a
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
M.MaybeT (m (Maybe a) -> MaybeT m a)
-> (MaybeT m a -> m (Maybe a)) -> MaybeT m a -> MaybeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (Maybe a) -> m (Maybe a)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (Maybe a) -> m (Maybe a))
-> (MaybeT m a -> m (Maybe a)) -> MaybeT m a -> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeT m a -> m (Maybe a)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
M.runMaybeT
    try :: forall a. MaybeT m a -> MaybeT m a
try = m (Maybe a) -> MaybeT m a
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
M.MaybeT (m (Maybe a) -> MaybeT m a)
-> (MaybeT m a -> m (Maybe a)) -> MaybeT m a -> MaybeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Maybe a) -> m (Maybe a)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (Maybe a) -> m (Maybe a))
-> (MaybeT m a -> m (Maybe a)) -> MaybeT m a -> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeT m a -> m (Maybe a)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
M.runMaybeT
    lookAhead :: forall a. MaybeT m a -> MaybeT m a
lookAhead = m (Maybe a) -> MaybeT m a
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
M.MaybeT (m (Maybe a) -> MaybeT m a)
-> (MaybeT m a -> m (Maybe a)) -> MaybeT m a -> MaybeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Maybe a) -> m (Maybe a)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (Maybe a) -> m (Maybe a))
-> (MaybeT m a -> m (Maybe a)) -> MaybeT m a -> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeT m a -> m (Maybe a)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
M.runMaybeT
    notFollowedBy :: forall a. MaybeT m a -> MaybeT m ()
notFollowedBy = m (Maybe ()) -> MaybeT m ()
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
M.MaybeT (m (Maybe ()) -> MaybeT m ())
-> (MaybeT m a -> m (Maybe ())) -> MaybeT m a -> MaybeT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (() -> Maybe ()) -> m () -> m (Maybe ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap () -> Maybe ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure (m () -> m (Maybe ()))
-> (MaybeT m a -> m ()) -> MaybeT m a -> m (Maybe ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Maybe a) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (Maybe a) -> m ())
-> (MaybeT m a -> m (Maybe a)) -> MaybeT m a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeT m a -> m (Maybe a)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
M.runMaybeT
    recover :: forall a.
(ParseError s e l -> MaybeT m a) -> MaybeT m a -> MaybeT m a
recover ParseError s e l -> MaybeT m a
f MaybeT m a
m = m (Maybe a) -> MaybeT m a
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
M.MaybeT (m (Maybe a) -> MaybeT m a) -> m (Maybe a) -> MaybeT m a
forall a b. (a -> b) -> a -> b
$ (ParseError s e l -> m (Maybe a)) -> m (Maybe a) -> m (Maybe a)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover (MaybeT m a -> m (Maybe a)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
M.runMaybeT (MaybeT m a -> m (Maybe a))
-> (ParseError s e l -> MaybeT m a)
-> ParseError s e l
-> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> MaybeT m a
f) (MaybeT m a -> m (Maybe a)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
M.runMaybeT MaybeT m a
m)
    observing :: forall a. MaybeT m a -> MaybeT m (Either (ParseError s e l) a)
observing = m (Maybe (Either (ParseError s e l) a))
-> MaybeT m (Either (ParseError s e l) a)
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
M.MaybeT (m (Maybe (Either (ParseError s e l) a))
 -> MaybeT m (Either (ParseError s e l) a))
-> (MaybeT m a -> m (Maybe (Either (ParseError s e l) a)))
-> MaybeT m a
-> MaybeT m (Either (ParseError s e l) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either (ParseError s e l) (Maybe a)
 -> Maybe (Either (ParseError s e l) a))
-> m (Either (ParseError s e l) (Maybe a))
-> m (Maybe (Either (ParseError s e l) a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Either (ParseError s e l) (Maybe a)
-> Maybe (Either (ParseError s e l) a)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence (m (Either (ParseError s e l) (Maybe a))
 -> m (Maybe (Either (ParseError s e l) a)))
-> (MaybeT m a -> m (Either (ParseError s e l) (Maybe a)))
-> MaybeT m a
-> m (Maybe (Either (ParseError s e l) a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Maybe a) -> m (Either (ParseError s e l) (Maybe a))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (Maybe a) -> m (Either (ParseError s e l) (Maybe a)))
-> (MaybeT m a -> m (Maybe a))
-> MaybeT m a
-> m (Either (ParseError s e l) (Maybe a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeT m a -> m (Maybe a)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
M.runMaybeT
    parseError :: forall a. ParseError s e l -> MaybeT m a
parseError = m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> MaybeT m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> MaybeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: MaybeT m (State s)
getState = m (State s) -> MaybeT m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> MaybeT m ()
putState = m () -> MaybeT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> MaybeT m ())
-> (State s -> m ()) -> State s -> MaybeT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance (Monoid w, MonadParser s e l m) => MonadParser s e l (C.RWST r w st m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> RWST r w st m a
matchToken = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> RWST r w st m a
matchTokens = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> RWST r w st m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> RWST r w st m a
matchTokenWhile = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> RWST r w st m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: RWST r w st m ()
endOfInput = m () -> RWST r w st m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> RWST r w st m a -> RWST r w st m a
withLabel Maybe l
l = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall (m :: * -> *) w r s a.
(Functor m, Monoid w) =>
(r -> s -> m (a, s, w)) -> RWST r w s m a
C.rwsT ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (a, st, w) -> m (a, st, w))
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> r
-> st
-> m (a, st, w)
forall b c a1 a2 a3.
(b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
.:: RWST r w st m a -> r -> st -> m (a, st, w)
forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
C.runRWST
    try :: forall a. RWST r w st m a -> RWST r w st m a
try = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall (m :: * -> *) w r s a.
(Functor m, Monoid w) =>
(r -> s -> m (a, s, w)) -> RWST r w s m a
C.rwsT ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (a, st, w) -> m (a, st, w))
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> r
-> st
-> m (a, st, w)
forall b c a1 a2 a3.
(b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
.:: RWST r w st m a -> r -> st -> m (a, st, w)
forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
C.runRWST
    lookAhead :: forall a. RWST r w st m a -> RWST r w st m a
lookAhead = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall (m :: * -> *) w r s a.
(Functor m, Monoid w) =>
(r -> s -> m (a, s, w)) -> RWST r w s m a
C.rwsT ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (a, st, w) -> m (a, st, w))
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> r
-> st
-> m (a, st, w)
forall b c a1 a2 a3.
(b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
.:: RWST r w st m a -> r -> st -> m (a, st, w)
forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
C.runRWST
    notFollowedBy :: forall a. RWST r w st m a -> RWST r w st m ()
notFollowedBy RWST r w st m a
m = (r -> st -> m ((), st, w)) -> RWST r w st m ()
forall (m :: * -> *) w r s a.
(Functor m, Monoid w) =>
(r -> s -> m (a, s, w)) -> RWST r w s m a
C.rwsT ((r -> st -> m ((), st, w)) -> RWST r w st m ())
-> (r -> st -> m ((), st, w)) -> RWST r w st m ()
forall a b. (a -> b) -> a -> b
$ \r
r st
st -> (() -> ((), st, w)) -> m () -> m ((), st, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, st
st, w
forall a. Monoid a => a
mempty) (m () -> m ((), st, w))
-> (m (a, st, w) -> m ()) -> m (a, st, w) -> m ((), st, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (a, st, w) -> m ((), st, w)) -> m (a, st, w) -> m ((), st, w)
forall a b. (a -> b) -> a -> b
$ RWST r w st m a -> r -> st -> m (a, st, w)
forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
C.runRWST RWST r w st m a
m r
r st
st
    recover :: forall a.
(ParseError s e l -> RWST r w st m a)
-> RWST r w st m a -> RWST r w st m a
recover ParseError s e l -> RWST r w st m a
f RWST r w st m a
m = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall (m :: * -> *) w r s a.
(Functor m, Monoid w) =>
(r -> s -> m (a, s, w)) -> RWST r w s m a
C.rwsT ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (r -> st -> m (a, st, w)) -> RWST r w st m a
forall a b. (a -> b) -> a -> b
$ \r
r st
st -> (ParseError s e l -> m (a, st, w)) -> m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover (\ParseError s e l
e -> RWST r w st m a -> r -> st -> m (a, st, w)
forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
C.runRWST (ParseError s e l -> RWST r w st m a
f ParseError s e l
e) r
r st
st) (RWST r w st m a -> r -> st -> m (a, st, w)
forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
C.runRWST RWST r w st m a
m r
r st
st)
    observing :: forall a.
RWST r w st m a -> RWST r w st m (Either (ParseError s e l) a)
observing RWST r w st m a
m = (r -> st -> m (Either (ParseError s e l) a, st, w))
-> RWST r w st m (Either (ParseError s e l) a)
forall (m :: * -> *) w r s a.
(Functor m, Monoid w) =>
(r -> s -> m (a, s, w)) -> RWST r w s m a
C.rwsT ((r -> st -> m (Either (ParseError s e l) a, st, w))
 -> RWST r w st m (Either (ParseError s e l) a))
-> (r -> st -> m (Either (ParseError s e l) a, st, w))
-> RWST r w st m (Either (ParseError s e l) a)
forall a b. (a -> b) -> a -> b
$ \r
r st
st -> (Either (ParseError s e l) (a, st, w)
 -> (Either (ParseError s e l) a, st, w))
-> m (Either (ParseError s e l) (a, st, w))
-> m (Either (ParseError s e l) a, st, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (st
-> Either (ParseError s e l) (a, st, w)
-> (Either (ParseError s e l) a, st, w)
forall w st b a.
Monoid w =>
st -> Either b (a, st, w) -> (Either b a, st, w)
adjustRWST st
st) (m (Either (ParseError s e l) (a, st, w))
 -> m (Either (ParseError s e l) a, st, w))
-> (m (a, st, w) -> m (Either (ParseError s e l) (a, st, w)))
-> m (a, st, w)
-> m (Either (ParseError s e l) a, st, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m (Either (ParseError s e l) (a, st, w))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (a, st, w) -> m (Either (ParseError s e l) a, st, w))
-> m (a, st, w) -> m (Either (ParseError s e l) a, st, w)
forall a b. (a -> b) -> a -> b
$ RWST r w st m a -> r -> st -> m (a, st, w)
forall w r s (m :: * -> *) a.
Monoid w =>
RWST r w s m a -> r -> s -> m (a, s, w)
C.runRWST RWST r w st m a
m r
r st
st
    parseError :: forall a. ParseError s e l -> RWST r w st m a
parseError = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: RWST r w st m (State s)
getState = m (State s) -> RWST r w st m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> RWST r w st m ()
putState = m () -> RWST r w st m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> RWST r w st m ())
-> (State s -> m ()) -> State s -> RWST r w st m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance (Monoid w, MonadParser s e l m) => MonadParser s e l (L.RWST r w st m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> RWST r w st m a
matchToken = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> RWST r w st m a
matchTokens = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> RWST r w st m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> RWST r w st m a
matchTokenWhile = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> RWST r w st m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: RWST r w st m ()
endOfInput = m () -> RWST r w st m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> RWST r w st m a -> RWST r w st m a
withLabel Maybe l
l = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (a, st, w) -> m (a, st, w))
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> r
-> st
-> m (a, st, w)
forall b c a1 a2 a3.
(b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
.:: RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
L.runRWST
    try :: forall a. RWST r w st m a -> RWST r w st m a
try = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (a, st, w) -> m (a, st, w))
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> r
-> st
-> m (a, st, w)
forall b c a1 a2 a3.
(b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
.:: RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
L.runRWST
    lookAhead :: forall a. RWST r w st m a -> RWST r w st m a
lookAhead = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (a, st, w) -> m (a, st, w))
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> r
-> st
-> m (a, st, w)
forall b c a1 a2 a3.
(b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
.:: RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
L.runRWST
    notFollowedBy :: forall a. RWST r w st m a -> RWST r w st m ()
notFollowedBy RWST r w st m a
m = (r -> st -> m ((), st, w)) -> RWST r w st m ()
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST ((r -> st -> m ((), st, w)) -> RWST r w st m ())
-> (r -> st -> m ((), st, w)) -> RWST r w st m ()
forall a b. (a -> b) -> a -> b
$ \r
r st
st -> (() -> ((), st, w)) -> m () -> m ((), st, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, st
st, w
forall a. Monoid a => a
mempty) (m () -> m ((), st, w))
-> (m (a, st, w) -> m ()) -> m (a, st, w) -> m ((), st, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (a, st, w) -> m ((), st, w)) -> m (a, st, w) -> m ((), st, w)
forall a b. (a -> b) -> a -> b
$ RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
L.runRWST RWST r w st m a
m r
r st
st
    recover :: forall a.
(ParseError s e l -> RWST r w st m a)
-> RWST r w st m a -> RWST r w st m a
recover ParseError s e l -> RWST r w st m a
f RWST r w st m a
m = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (r -> st -> m (a, st, w)) -> RWST r w st m a
forall a b. (a -> b) -> a -> b
$ \r
r st
st -> (ParseError s e l -> m (a, st, w)) -> m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover (\ParseError s e l
e -> RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
L.runRWST (ParseError s e l -> RWST r w st m a
f ParseError s e l
e) r
r st
st) (RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
L.runRWST RWST r w st m a
m r
r st
st)
    observing :: forall a.
RWST r w st m a -> RWST r w st m (Either (ParseError s e l) a)
observing RWST r w st m a
m = (r -> st -> m (Either (ParseError s e l) a, st, w))
-> RWST r w st m (Either (ParseError s e l) a)
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST ((r -> st -> m (Either (ParseError s e l) a, st, w))
 -> RWST r w st m (Either (ParseError s e l) a))
-> (r -> st -> m (Either (ParseError s e l) a, st, w))
-> RWST r w st m (Either (ParseError s e l) a)
forall a b. (a -> b) -> a -> b
$ \r
r st
st -> (Either (ParseError s e l) (a, st, w)
 -> (Either (ParseError s e l) a, st, w))
-> m (Either (ParseError s e l) (a, st, w))
-> m (Either (ParseError s e l) a, st, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (st
-> Either (ParseError s e l) (a, st, w)
-> (Either (ParseError s e l) a, st, w)
forall w st b a.
Monoid w =>
st -> Either b (a, st, w) -> (Either b a, st, w)
adjustRWST st
st) (m (Either (ParseError s e l) (a, st, w))
 -> m (Either (ParseError s e l) a, st, w))
-> (m (a, st, w) -> m (Either (ParseError s e l) (a, st, w)))
-> m (a, st, w)
-> m (Either (ParseError s e l) a, st, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m (Either (ParseError s e l) (a, st, w))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (a, st, w) -> m (Either (ParseError s e l) a, st, w))
-> m (a, st, w) -> m (Either (ParseError s e l) a, st, w)
forall a b. (a -> b) -> a -> b
$ RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
L.runRWST RWST r w st m a
m r
r st
st
    parseError :: forall a. ParseError s e l -> RWST r w st m a
parseError = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: RWST r w st m (State s)
getState = m (State s) -> RWST r w st m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> RWST r w st m ()
putState = m () -> RWST r w st m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> RWST r w st m ())
-> (State s -> m ()) -> State s -> RWST r w st m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance (Monoid w, MonadParser s e l m) => MonadParser s e l (S.RWST r w st m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> RWST r w st m a
matchToken = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> RWST r w st m a
matchTokens = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> RWST r w st m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> RWST r w st m a
matchTokenWhile = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> RWST r w st m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: RWST r w st m ()
endOfInput = m () -> RWST r w st m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> RWST r w st m a -> RWST r w st m a
withLabel Maybe l
l = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (a, st, w) -> m (a, st, w))
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> r
-> st
-> m (a, st, w)
forall b c a1 a2 a3.
(b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
.:: RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
S.runRWST
    try :: forall a. RWST r w st m a -> RWST r w st m a
try = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (a, st, w) -> m (a, st, w))
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> r
-> st
-> m (a, st, w)
forall b c a1 a2 a3.
(b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
.:: RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
S.runRWST
    lookAhead :: forall a. RWST r w st m a -> RWST r w st m a
lookAhead = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (a, st, w) -> m (a, st, w))
-> (RWST r w st m a -> r -> st -> m (a, st, w))
-> RWST r w st m a
-> r
-> st
-> m (a, st, w)
forall b c a1 a2 a3.
(b -> c) -> (a1 -> a2 -> a3 -> b) -> a1 -> a2 -> a3 -> c
.:: RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
S.runRWST
    notFollowedBy :: forall a. RWST r w st m a -> RWST r w st m ()
notFollowedBy RWST r w st m a
m = (r -> st -> m ((), st, w)) -> RWST r w st m ()
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST ((r -> st -> m ((), st, w)) -> RWST r w st m ())
-> (r -> st -> m ((), st, w)) -> RWST r w st m ()
forall a b. (a -> b) -> a -> b
$ \r
r st
st -> (() -> ((), st, w)) -> m () -> m ((), st, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, st
st, w
forall a. Monoid a => a
mempty) (m () -> m ((), st, w))
-> (m (a, st, w) -> m ()) -> m (a, st, w) -> m ((), st, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (a, st, w) -> m ((), st, w)) -> m (a, st, w) -> m ((), st, w)
forall a b. (a -> b) -> a -> b
$ RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
S.runRWST RWST r w st m a
m r
r st
st
    recover :: forall a.
(ParseError s e l -> RWST r w st m a)
-> RWST r w st m a -> RWST r w st m a
recover ParseError s e l -> RWST r w st m a
f RWST r w st m a
m = (r -> st -> m (a, st, w)) -> RWST r w st m a
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST ((r -> st -> m (a, st, w)) -> RWST r w st m a)
-> (r -> st -> m (a, st, w)) -> RWST r w st m a
forall a b. (a -> b) -> a -> b
$ \r
r st
st -> (ParseError s e l -> m (a, st, w)) -> m (a, st, w) -> m (a, st, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover (\ParseError s e l
e -> RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
S.runRWST (ParseError s e l -> RWST r w st m a
f ParseError s e l
e) r
r st
st) (RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
S.runRWST RWST r w st m a
m r
r st
st)
    observing :: forall a.
RWST r w st m a -> RWST r w st m (Either (ParseError s e l) a)
observing RWST r w st m a
m = (r -> st -> m (Either (ParseError s e l) a, st, w))
-> RWST r w st m (Either (ParseError s e l) a)
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST ((r -> st -> m (Either (ParseError s e l) a, st, w))
 -> RWST r w st m (Either (ParseError s e l) a))
-> (r -> st -> m (Either (ParseError s e l) a, st, w))
-> RWST r w st m (Either (ParseError s e l) a)
forall a b. (a -> b) -> a -> b
$ \r
r st
st -> (Either (ParseError s e l) (a, st, w)
 -> (Either (ParseError s e l) a, st, w))
-> m (Either (ParseError s e l) (a, st, w))
-> m (Either (ParseError s e l) a, st, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (st
-> Either (ParseError s e l) (a, st, w)
-> (Either (ParseError s e l) a, st, w)
forall w st b a.
Monoid w =>
st -> Either b (a, st, w) -> (Either b a, st, w)
adjustRWST st
st) (m (Either (ParseError s e l) (a, st, w))
 -> m (Either (ParseError s e l) a, st, w))
-> (m (a, st, w) -> m (Either (ParseError s e l) (a, st, w)))
-> m (a, st, w)
-> m (Either (ParseError s e l) a, st, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st, w) -> m (Either (ParseError s e l) (a, st, w))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (a, st, w) -> m (Either (ParseError s e l) a, st, w))
-> m (a, st, w) -> m (Either (ParseError s e l) a, st, w)
forall a b. (a -> b) -> a -> b
$ RWST r w st m a -> r -> st -> m (a, st, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
S.runRWST RWST r w st m a
m r
r st
st
    parseError :: forall a. ParseError s e l -> RWST r w st m a
parseError = m a -> RWST r w st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w st m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> RWST r w st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: RWST r w st m (State s)
getState = m (State s) -> RWST r w st m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> RWST r w st m ()
putState = m () -> RWST r w st m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> RWST r w st m ())
-> (State s -> m ()) -> State s -> RWST r w st m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance MonadParser s e l m => MonadParser s e l (M.ReaderT r m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> ReaderT r m a
matchToken = m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> ReaderT r m a
matchTokens = m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> ReaderT r m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> ReaderT r m a
matchTokenWhile = m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> ReaderT r m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: ReaderT r m ()
endOfInput = m () -> ReaderT r m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> ReaderT r m a -> ReaderT r m a
withLabel Maybe l
l = (r -> m a) -> ReaderT r m a
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
M.ReaderT ((r -> m a) -> ReaderT r m a)
-> (ReaderT r m a -> r -> m a) -> ReaderT r m a -> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m a -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m a -> m a)
-> (ReaderT r m a -> r -> m a) -> ReaderT r m a -> r -> m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: ReaderT r m a -> r -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
M.runReaderT
    try :: forall a. ReaderT r m a -> ReaderT r m a
try = (r -> m a) -> ReaderT r m a
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
M.ReaderT ((r -> m a) -> ReaderT r m a)
-> (ReaderT r m a -> r -> m a) -> ReaderT r m a -> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m a
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m a -> m a)
-> (ReaderT r m a -> r -> m a) -> ReaderT r m a -> r -> m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: ReaderT r m a -> r -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
M.runReaderT
    lookAhead :: forall a. ReaderT r m a -> ReaderT r m a
lookAhead = (r -> m a) -> ReaderT r m a
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
M.ReaderT ((r -> m a) -> ReaderT r m a)
-> (ReaderT r m a -> r -> m a) -> ReaderT r m a -> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m a
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m a -> m a)
-> (ReaderT r m a -> r -> m a) -> ReaderT r m a -> r -> m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: ReaderT r m a -> r -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
M.runReaderT
    notFollowedBy :: forall a. ReaderT r m a -> ReaderT r m ()
notFollowedBy = (r -> m ()) -> ReaderT r m ()
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
M.ReaderT ((r -> m ()) -> ReaderT r m ())
-> (ReaderT r m a -> r -> m ()) -> ReaderT r m a -> ReaderT r m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m a -> m ())
-> (ReaderT r m a -> r -> m a) -> ReaderT r m a -> r -> m ()
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: ReaderT r m a -> r -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
M.runReaderT
    recover :: forall a.
(ParseError s e l -> ReaderT r m a)
-> ReaderT r m a -> ReaderT r m a
recover ParseError s e l -> ReaderT r m a
f ReaderT r m a
m = (r -> m a) -> ReaderT r m a
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
M.ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \r
r -> (ParseError s e l -> m a) -> m a -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover ((ReaderT r m a -> r -> m a) -> r -> ReaderT r m a -> m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT r m a -> r -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
M.runReaderT r
r (ReaderT r m a -> m a)
-> (ParseError s e l -> ReaderT r m a) -> ParseError s e l -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> ReaderT r m a
f) (ReaderT r m a -> r -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
M.runReaderT ReaderT r m a
m r
r)
    observing :: forall a.
ReaderT r m a -> ReaderT r m (Either (ParseError s e l) a)
observing = (r -> m (Either (ParseError s e l) a))
-> ReaderT r m (Either (ParseError s e l) a)
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
M.ReaderT ((r -> m (Either (ParseError s e l) a))
 -> ReaderT r m (Either (ParseError s e l) a))
-> (ReaderT r m a -> r -> m (Either (ParseError s e l) a))
-> ReaderT r m a
-> ReaderT r m (Either (ParseError s e l) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m (Either (ParseError s e l) a)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m a -> m (Either (ParseError s e l) a))
-> (ReaderT r m a -> r -> m a)
-> ReaderT r m a
-> r
-> m (Either (ParseError s e l) a)
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: ReaderT r m a -> r -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
M.runReaderT
    parseError :: forall a. ParseError s e l -> ReaderT r m a
parseError = m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: ReaderT r m (State s)
getState = m (State s) -> ReaderT r m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> ReaderT r m ()
putState = m () -> ReaderT r m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ReaderT r m ())
-> (State s -> m ()) -> State s -> ReaderT r m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance MonadParser s e l m => MonadParser s e l (L.StateT st m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> StateT st m a
matchToken = m a -> StateT st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT st m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> StateT st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> StateT st m a
matchTokens = m a -> StateT st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT st m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> StateT st m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> StateT st m a
matchTokenWhile = m a -> StateT st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT st m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> StateT st m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: StateT st m ()
endOfInput = m () -> StateT st m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> StateT st m a -> StateT st m a
withLabel Maybe l
l = (st -> m (a, st)) -> StateT st m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT ((st -> m (a, st)) -> StateT st m a)
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> StateT st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (a, st) -> m (a, st)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (a, st) -> m (a, st))
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> st
-> m (a, st)
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
L.runStateT
    try :: forall a. StateT st m a -> StateT st m a
try = (st -> m (a, st)) -> StateT st m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT ((st -> m (a, st)) -> StateT st m a)
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> StateT st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st) -> m (a, st)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (a, st) -> m (a, st))
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> st
-> m (a, st)
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
L.runStateT
    lookAhead :: forall a. StateT st m a -> StateT st m a
lookAhead = (st -> m (a, st)) -> StateT st m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT ((st -> m (a, st)) -> StateT st m a)
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> StateT st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st) -> m (a, st)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (a, st) -> m (a, st))
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> st
-> m (a, st)
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
L.runStateT
    notFollowedBy :: forall a. StateT st m a -> StateT st m ()
notFollowedBy StateT st m a
m = (st -> m ((), st)) -> StateT st m ()
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT ((st -> m ((), st)) -> StateT st m ())
-> (st -> m ((), st)) -> StateT st m ()
forall a b. (a -> b) -> a -> b
$ \st
st -> (() -> ((), st)) -> m () -> m ((), st)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, st
st) (m () -> m ((), st))
-> (m (a, st) -> m ()) -> m (a, st) -> m ((), st)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (a, st) -> m ((), st)) -> m (a, st) -> m ((), st)
forall a b. (a -> b) -> a -> b
$ StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
L.runStateT StateT st m a
m st
st
    recover :: forall a.
(ParseError s e l -> StateT st m a)
-> StateT st m a -> StateT st m a
recover ParseError s e l -> StateT st m a
f StateT st m a
m = (st -> m (a, st)) -> StateT st m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT ((st -> m (a, st)) -> StateT st m a)
-> (st -> m (a, st)) -> StateT st m a
forall a b. (a -> b) -> a -> b
$ \st
st -> (ParseError s e l -> m (a, st)) -> m (a, st) -> m (a, st)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover ((StateT st m a -> st -> m (a, st))
-> st -> StateT st m a -> m (a, st)
forall a b c. (a -> b -> c) -> b -> a -> c
flip StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
L.runStateT st
st (StateT st m a -> m (a, st))
-> (ParseError s e l -> StateT st m a)
-> ParseError s e l
-> m (a, st)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> StateT st m a
f) (StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
L.runStateT StateT st m a
m st
st)
    observing :: forall a.
StateT st m a -> StateT st m (Either (ParseError s e l) a)
observing StateT st m a
m = (st -> m (Either (ParseError s e l) a, st))
-> StateT st m (Either (ParseError s e l) a)
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT ((st -> m (Either (ParseError s e l) a, st))
 -> StateT st m (Either (ParseError s e l) a))
-> (st -> m (Either (ParseError s e l) a, st))
-> StateT st m (Either (ParseError s e l) a)
forall a b. (a -> b) -> a -> b
$ \st
st -> (Either (ParseError s e l) (a, st)
 -> (Either (ParseError s e l) a, st))
-> m (Either (ParseError s e l) (a, st))
-> m (Either (ParseError s e l) a, st)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (st
-> Either (ParseError s e l) (a, st)
-> (Either (ParseError s e l) a, st)
forall st b a. st -> Either b (a, st) -> (Either b a, st)
adjustStateT st
st) (m (Either (ParseError s e l) (a, st))
 -> m (Either (ParseError s e l) a, st))
-> (m (a, st) -> m (Either (ParseError s e l) (a, st)))
-> m (a, st)
-> m (Either (ParseError s e l) a, st)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st) -> m (Either (ParseError s e l) (a, st))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (a, st) -> m (Either (ParseError s e l) a, st))
-> m (a, st) -> m (Either (ParseError s e l) a, st)
forall a b. (a -> b) -> a -> b
$ StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
L.runStateT StateT st m a
m st
st
    parseError :: forall a. ParseError s e l -> StateT st m a
parseError = m a -> StateT st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT st m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> StateT st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: StateT st m (State s)
getState = m (State s) -> StateT st m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> StateT st m ()
putState = m () -> StateT st m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StateT st m ())
-> (State s -> m ()) -> State s -> StateT st m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance MonadParser s e l m => MonadParser s e l (S.StateT st m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> StateT st m a
matchToken = m a -> StateT st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT st m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> StateT st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> StateT st m a
matchTokens = m a -> StateT st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT st m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> StateT st m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> StateT st m a
matchTokenWhile = m a -> StateT st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT st m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> StateT st m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: StateT st m ()
endOfInput = m () -> StateT st m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> StateT st m a -> StateT st m a
withLabel Maybe l
l = (st -> m (a, st)) -> StateT st m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT ((st -> m (a, st)) -> StateT st m a)
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> StateT st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (a, st) -> m (a, st)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (a, st) -> m (a, st))
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> st
-> m (a, st)
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
S.runStateT
    try :: forall a. StateT st m a -> StateT st m a
try = (st -> m (a, st)) -> StateT st m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT ((st -> m (a, st)) -> StateT st m a)
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> StateT st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st) -> m (a, st)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (a, st) -> m (a, st))
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> st
-> m (a, st)
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
S.runStateT
    lookAhead :: forall a. StateT st m a -> StateT st m a
lookAhead = (st -> m (a, st)) -> StateT st m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT ((st -> m (a, st)) -> StateT st m a)
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> StateT st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st) -> m (a, st)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (a, st) -> m (a, st))
-> (StateT st m a -> st -> m (a, st))
-> StateT st m a
-> st
-> m (a, st)
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
S.runStateT
    notFollowedBy :: forall a. StateT st m a -> StateT st m ()
notFollowedBy StateT st m a
m = (st -> m ((), st)) -> StateT st m ()
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT ((st -> m ((), st)) -> StateT st m ())
-> (st -> m ((), st)) -> StateT st m ()
forall a b. (a -> b) -> a -> b
$ \st
st -> (() -> ((), st)) -> m () -> m ((), st)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, st
st) (m () -> m ((), st))
-> (m (a, st) -> m ()) -> m (a, st) -> m ((), st)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (a, st) -> m ((), st)) -> m (a, st) -> m ((), st)
forall a b. (a -> b) -> a -> b
$ StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
S.runStateT StateT st m a
m st
st
    recover :: forall a.
(ParseError s e l -> StateT st m a)
-> StateT st m a -> StateT st m a
recover ParseError s e l -> StateT st m a
f StateT st m a
m = (st -> m (a, st)) -> StateT st m a
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT ((st -> m (a, st)) -> StateT st m a)
-> (st -> m (a, st)) -> StateT st m a
forall a b. (a -> b) -> a -> b
$ \st
st -> (ParseError s e l -> m (a, st)) -> m (a, st) -> m (a, st)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover ((StateT st m a -> st -> m (a, st))
-> st -> StateT st m a -> m (a, st)
forall a b c. (a -> b -> c) -> b -> a -> c
flip StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
S.runStateT st
st (StateT st m a -> m (a, st))
-> (ParseError s e l -> StateT st m a)
-> ParseError s e l
-> m (a, st)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> StateT st m a
f) (StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
S.runStateT StateT st m a
m st
st)
    observing :: forall a.
StateT st m a -> StateT st m (Either (ParseError s e l) a)
observing StateT st m a
m = (st -> m (Either (ParseError s e l) a, st))
-> StateT st m (Either (ParseError s e l) a)
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT ((st -> m (Either (ParseError s e l) a, st))
 -> StateT st m (Either (ParseError s e l) a))
-> (st -> m (Either (ParseError s e l) a, st))
-> StateT st m (Either (ParseError s e l) a)
forall a b. (a -> b) -> a -> b
$ \st
st -> (Either (ParseError s e l) (a, st)
 -> (Either (ParseError s e l) a, st))
-> m (Either (ParseError s e l) (a, st))
-> m (Either (ParseError s e l) a, st)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (st
-> Either (ParseError s e l) (a, st)
-> (Either (ParseError s e l) a, st)
forall st b a. st -> Either b (a, st) -> (Either b a, st)
adjustStateT st
st) (m (Either (ParseError s e l) (a, st))
 -> m (Either (ParseError s e l) a, st))
-> (m (a, st) -> m (Either (ParseError s e l) (a, st)))
-> m (a, st)
-> m (Either (ParseError s e l) a, st)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, st) -> m (Either (ParseError s e l) (a, st))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (a, st) -> m (Either (ParseError s e l) a, st))
-> m (a, st) -> m (Either (ParseError s e l) a, st)
forall a b. (a -> b) -> a -> b
$ StateT st m a -> st -> m (a, st)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
S.runStateT StateT st m a
m st
st
    parseError :: forall a. ParseError s e l -> StateT st m a
parseError = m a -> StateT st m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT st m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> StateT st m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: StateT st m (State s)
getState = m (State s) -> StateT st m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> StateT st m ()
putState = m () -> StateT st m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StateT st m ())
-> (State s -> m ()) -> State s -> StateT st m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance (Monoid w, MonadParser s e l m) => MonadParser s e l (C.WriterT w m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> WriterT w m a
matchToken = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> WriterT w m a
matchTokens = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> WriterT w m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> WriterT w m a
matchTokenWhile = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> WriterT w m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: WriterT w m ()
endOfInput = m () -> WriterT w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> WriterT w m a -> WriterT w m a
withLabel Maybe l
l = m (a, w) -> WriterT w m a
forall (m :: * -> *) w a.
(Functor m, Monoid w) =>
m (a, w) -> WriterT w m a
C.writerT (m (a, w) -> WriterT w m a)
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (a, w) -> m (a, w))
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. Monoid w => WriterT w m a -> m (a, w)
C.runWriterT
    try :: forall a. WriterT w m a -> WriterT w m a
try = m (a, w) -> WriterT w m a
forall (m :: * -> *) w a.
(Functor m, Monoid w) =>
m (a, w) -> WriterT w m a
C.writerT (m (a, w) -> WriterT w m a)
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (a, w) -> m (a, w))
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. Monoid w => WriterT w m a -> m (a, w)
C.runWriterT
    lookAhead :: forall a. WriterT w m a -> WriterT w m a
lookAhead = m (a, w) -> WriterT w m a
forall (m :: * -> *) w a.
(Functor m, Monoid w) =>
m (a, w) -> WriterT w m a
C.writerT (m (a, w) -> WriterT w m a)
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (a, w) -> m (a, w))
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. Monoid w => WriterT w m a -> m (a, w)
C.runWriterT
    notFollowedBy :: forall a. WriterT w m a -> WriterT w m ()
notFollowedBy = m ((), w) -> WriterT w m ()
forall (m :: * -> *) w a.
(Functor m, Monoid w) =>
m (a, w) -> WriterT w m a
C.writerT (m ((), w) -> WriterT w m ())
-> (WriterT w m a -> m ((), w)) -> WriterT w m a -> WriterT w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (() -> ((), w)) -> m () -> m ((), w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, w
forall a. Monoid a => a
mempty) (m () -> m ((), w))
-> (WriterT w m a -> m ()) -> WriterT w m a -> m ((), w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (a, w) -> m ())
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. Monoid w => WriterT w m a -> m (a, w)
C.runWriterT
    recover :: forall a.
(ParseError s e l -> WriterT w m a)
-> WriterT w m a -> WriterT w m a
recover ParseError s e l -> WriterT w m a
f WriterT w m a
m = m (a, w) -> WriterT w m a
forall (m :: * -> *) w a.
(Functor m, Monoid w) =>
m (a, w) -> WriterT w m a
C.writerT (m (a, w) -> WriterT w m a) -> m (a, w) -> WriterT w m a
forall a b. (a -> b) -> a -> b
$ (ParseError s e l -> m (a, w)) -> m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover (WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. Monoid w => WriterT w m a -> m (a, w)
C.runWriterT (WriterT w m a -> m (a, w))
-> (ParseError s e l -> WriterT w m a)
-> ParseError s e l
-> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> WriterT w m a
f) (WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. Monoid w => WriterT w m a -> m (a, w)
C.runWriterT WriterT w m a
m)
    observing :: forall a.
WriterT w m a -> WriterT w m (Either (ParseError s e l) a)
observing = m (Either (ParseError s e l) a, w)
-> WriterT w m (Either (ParseError s e l) a)
forall (m :: * -> *) w a.
(Functor m, Monoid w) =>
m (a, w) -> WriterT w m a
C.writerT (m (Either (ParseError s e l) a, w)
 -> WriterT w m (Either (ParseError s e l) a))
-> (WriterT w m a -> m (Either (ParseError s e l) a, w))
-> WriterT w m a
-> WriterT w m (Either (ParseError s e l) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either (ParseError s e l) (a, w)
 -> (Either (ParseError s e l) a, w))
-> m (Either (ParseError s e l) (a, w))
-> m (Either (ParseError s e l) a, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Either (ParseError s e l) (a, w)
-> (Either (ParseError s e l) a, w)
forall w b a. Monoid w => Either b (a, w) -> (Either b a, w)
adjustWriterT (m (Either (ParseError s e l) (a, w))
 -> m (Either (ParseError s e l) a, w))
-> (WriterT w m a -> m (Either (ParseError s e l) (a, w)))
-> WriterT w m a
-> m (Either (ParseError s e l) a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (Either (ParseError s e l) (a, w))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (a, w) -> m (Either (ParseError s e l) (a, w)))
-> (WriterT w m a -> m (a, w))
-> WriterT w m a
-> m (Either (ParseError s e l) (a, w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. Monoid w => WriterT w m a -> m (a, w)
C.runWriterT
    parseError :: forall a. ParseError s e l -> WriterT w m a
parseError = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: WriterT w m (State s)
getState = m (State s) -> WriterT w m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> WriterT w m ()
putState = m () -> WriterT w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> WriterT w m ())
-> (State s -> m ()) -> State s -> WriterT w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance (Monoid w, MonadParser s e l m) => MonadParser s e l (L.WriterT w m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> WriterT w m a
matchToken = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> WriterT w m a
matchTokens = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> WriterT w m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> WriterT w m a
matchTokenWhile = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> WriterT w m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: WriterT w m ()
endOfInput = m () -> WriterT w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> WriterT w m a -> WriterT w m a
withLabel Maybe l
l = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT (m (a, w) -> WriterT w m a)
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (a, w) -> m (a, w))
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
L.runWriterT
    try :: forall a. WriterT w m a -> WriterT w m a
try = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT (m (a, w) -> WriterT w m a)
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (a, w) -> m (a, w))
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
L.runWriterT
    lookAhead :: forall a. WriterT w m a -> WriterT w m a
lookAhead = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT (m (a, w) -> WriterT w m a)
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (a, w) -> m (a, w))
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
L.runWriterT
    notFollowedBy :: forall a. WriterT w m a -> WriterT w m ()
notFollowedBy = m ((), w) -> WriterT w m ()
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT (m ((), w) -> WriterT w m ())
-> (WriterT w m a -> m ((), w)) -> WriterT w m a -> WriterT w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (() -> ((), w)) -> m () -> m ((), w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, w
forall a. Monoid a => a
mempty) (m () -> m ((), w))
-> (WriterT w m a -> m ()) -> WriterT w m a -> m ((), w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (a, w) -> m ())
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
L.runWriterT
    recover :: forall a.
(ParseError s e l -> WriterT w m a)
-> WriterT w m a -> WriterT w m a
recover ParseError s e l -> WriterT w m a
f WriterT w m a
m = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT (m (a, w) -> WriterT w m a) -> m (a, w) -> WriterT w m a
forall a b. (a -> b) -> a -> b
$ (ParseError s e l -> m (a, w)) -> m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover (WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
L.runWriterT (WriterT w m a -> m (a, w))
-> (ParseError s e l -> WriterT w m a)
-> ParseError s e l
-> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> WriterT w m a
f) (WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
L.runWriterT WriterT w m a
m)
    observing :: forall a.
WriterT w m a -> WriterT w m (Either (ParseError s e l) a)
observing = m (Either (ParseError s e l) a, w)
-> WriterT w m (Either (ParseError s e l) a)
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT (m (Either (ParseError s e l) a, w)
 -> WriterT w m (Either (ParseError s e l) a))
-> (WriterT w m a -> m (Either (ParseError s e l) a, w))
-> WriterT w m a
-> WriterT w m (Either (ParseError s e l) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either (ParseError s e l) (a, w)
 -> (Either (ParseError s e l) a, w))
-> m (Either (ParseError s e l) (a, w))
-> m (Either (ParseError s e l) a, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Either (ParseError s e l) (a, w)
-> (Either (ParseError s e l) a, w)
forall w b a. Monoid w => Either b (a, w) -> (Either b a, w)
adjustWriterT (m (Either (ParseError s e l) (a, w))
 -> m (Either (ParseError s e l) a, w))
-> (WriterT w m a -> m (Either (ParseError s e l) (a, w)))
-> WriterT w m a
-> m (Either (ParseError s e l) a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (Either (ParseError s e l) (a, w))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (a, w) -> m (Either (ParseError s e l) (a, w)))
-> (WriterT w m a -> m (a, w))
-> WriterT w m a
-> m (Either (ParseError s e l) (a, w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
L.runWriterT
    parseError :: forall a. ParseError s e l -> WriterT w m a
parseError = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: WriterT w m (State s)
getState = m (State s) -> WriterT w m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> WriterT w m ()
putState = m () -> WriterT w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> WriterT w m ())
-> (State s -> m ()) -> State s -> WriterT w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

instance (Monoid w, MonadParser s e l m) => MonadParser s e l (S.WriterT w m) where
    matchToken :: forall a.
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> WriterT w m a
matchToken = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> ((Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a)
-> (Maybe (Token s) -> Either (ErrorItem s e l) a)
-> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Maybe (Token s) -> Either (ErrorItem s e l) a) -> m a
matchToken
    matchTokens :: forall a.
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> WriterT w m a
matchTokens = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> (Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> Int
-> (Chunk s -> Either (ErrorItem s e l) a)
-> WriterT w m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Int -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokens
    matchTokenWhile :: forall a.
(Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a) -> WriterT w m a
matchTokenWhile = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> ((Token s -> Bool)
    -> (Chunk s -> Either (ErrorItem s e l) a) -> m a)
-> (Token s -> Bool)
-> (Chunk s -> Either (ErrorItem s e l) a)
-> WriterT w m a
forall b c a1 a2. (b -> c) -> (a1 -> a2 -> b) -> a1 -> a2 -> c
.: (Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(Token s -> Bool) -> (Chunk s -> Either (ErrorItem s e l) a) -> m a
matchTokenWhile
    endOfInput :: WriterT w m ()
endOfInput = m () -> WriterT w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m ()
forall s e l (m :: * -> *). MonadParser s e l m => m ()
endOfInput
    withLabel :: forall a. Maybe l -> WriterT w m a -> WriterT w m a
withLabel Maybe l
l = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT (m (a, w) -> WriterT w m a)
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe l -> m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
Maybe l -> m a -> m a
withLabel Maybe l
l (m (a, w) -> m (a, w))
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
S.runWriterT
    try :: forall a. WriterT w m a -> WriterT w m a
try = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT (m (a, w) -> WriterT w m a)
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
try (m (a, w) -> m (a, w))
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
S.runWriterT
    lookAhead :: forall a. WriterT w m a -> WriterT w m a
lookAhead = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT (m (a, w) -> WriterT w m a)
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m a
lookAhead (m (a, w) -> m (a, w))
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
S.runWriterT
    notFollowedBy :: forall a. WriterT w m a -> WriterT w m ()
notFollowedBy = m ((), w) -> WriterT w m ()
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT (m ((), w) -> WriterT w m ())
-> (WriterT w m a -> m ((), w)) -> WriterT w m a -> WriterT w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (() -> ((), w)) -> m () -> m ((), w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, w
forall a. Monoid a => a
mempty) (m () -> m ((), w))
-> (WriterT w m a -> m ()) -> WriterT w m a -> m ((), w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m ()
forall s e l (m :: * -> *) a. MonadParser s e l m => m a -> m ()
notFollowedBy (m (a, w) -> m ())
-> (WriterT w m a -> m (a, w)) -> WriterT w m a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
S.runWriterT
    recover :: forall a.
(ParseError s e l -> WriterT w m a)
-> WriterT w m a -> WriterT w m a
recover ParseError s e l -> WriterT w m a
f WriterT w m a
m = m (a, w) -> WriterT w m a
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT (m (a, w) -> WriterT w m a) -> m (a, w) -> WriterT w m a
forall a b. (a -> b) -> a -> b
$ (ParseError s e l -> m (a, w)) -> m (a, w) -> m (a, w)
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
(ParseError s e l -> m a) -> m a -> m a
recover (WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
S.runWriterT (WriterT w m a -> m (a, w))
-> (ParseError s e l -> WriterT w m a)
-> ParseError s e l
-> m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> WriterT w m a
f) (WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
S.runWriterT WriterT w m a
m)
    observing :: forall a.
WriterT w m a -> WriterT w m (Either (ParseError s e l) a)
observing = m (Either (ParseError s e l) a, w)
-> WriterT w m (Either (ParseError s e l) a)
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT (m (Either (ParseError s e l) a, w)
 -> WriterT w m (Either (ParseError s e l) a))
-> (WriterT w m a -> m (Either (ParseError s e l) a, w))
-> WriterT w m a
-> WriterT w m (Either (ParseError s e l) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either (ParseError s e l) (a, w)
 -> (Either (ParseError s e l) a, w))
-> m (Either (ParseError s e l) (a, w))
-> m (Either (ParseError s e l) a, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Either (ParseError s e l) (a, w)
-> (Either (ParseError s e l) a, w)
forall w b a. Monoid w => Either b (a, w) -> (Either b a, w)
adjustWriterT (m (Either (ParseError s e l) (a, w))
 -> m (Either (ParseError s e l) a, w))
-> (WriterT w m a -> m (Either (ParseError s e l) (a, w)))
-> WriterT w m a
-> m (Either (ParseError s e l) a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a, w) -> m (Either (ParseError s e l) (a, w))
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
m a -> m (Either (ParseError s e l) a)
observing (m (a, w) -> m (Either (ParseError s e l) (a, w)))
-> (WriterT w m a -> m (a, w))
-> WriterT w m a
-> m (Either (ParseError s e l) (a, w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m a -> m (a, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
S.runWriterT
    parseError :: forall a. ParseError s e l -> WriterT w m a
parseError = m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a)
-> (ParseError s e l -> m a) -> ParseError s e l -> WriterT w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e l -> m a
forall s e l (m :: * -> *) a.
MonadParser s e l m =>
ParseError s e l -> m a
parseError
    getState :: WriterT w m (State s)
getState = m (State s) -> WriterT w m (State s)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (State s)
forall s e l (m :: * -> *). MonadParser s e l m => m (State s)
getState
    putState :: State s -> WriterT w m ()
putState = m () -> WriterT w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> WriterT w m ())
-> (State s -> m ()) -> State s -> WriterT w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State s -> m ()
forall s e l (m :: * -> *). MonadParser s e l m => State s -> m ()
putState

adjustRWST :: Monoid w => st -> Either b (a, st, w) -> (Either b a, st, w)
adjustRWST :: forall w st b a.
Monoid w =>
st -> Either b (a, st, w) -> (Either b a, st, w)
adjustRWST st
st (Left b
b) = (b -> Either b a
forall a b. a -> Either a b
Left b
b, st
st, w
forall a. Monoid a => a
mempty)
adjustRWST st
_ (Right (a
a, st
st, w
w)) = (a -> Either b a
forall a b. b -> Either a b
Right a
a, st
st, w
w)
{-# INLINE adjustRWST #-}

adjustStateT :: st -> Either b (a, st) -> (Either b a, st)
adjustStateT :: forall st b a. st -> Either b (a, st) -> (Either b a, st)
adjustStateT st
st (Left b
b) = (b -> Either b a
forall a b. a -> Either a b
Left b
b, st
st)
adjustStateT st
_ (Right (a
a, st
st)) = (a -> Either b a
forall a b. b -> Either a b
Right a
a, st
st)
{-# INLINE adjustStateT #-}

adjustWriterT :: Monoid w => Either b (a, w) -> (Either b a, w)
adjustWriterT :: forall w b a. Monoid w => Either b (a, w) -> (Either b a, w)
adjustWriterT (Left b
b) = (b -> Either b a
forall a b. a -> Either a b
Left b
b, w
forall a. Monoid a => a
mempty)
adjustWriterT (Right (a
a, w
w)) = (a -> Either b a
forall a b. b -> Either a b
Right a
a, w
w)
{-# INLINE adjustWriterT #-}