{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE UndecidableInstances #-}

-- |
-- Module      :  Text.Megaparsec.Class
-- Copyright   :  © 2015–present Megaparsec contributors
--                © 2007 Paolo Martini
--                © 1999–2001 Daan Leijen
-- License     :  FreeBSD
--
-- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>
-- Stability   :  experimental
-- Portability :  portable
--
-- Definition of 'MonadParsec'—type class describing monads that implement
-- the full set of primitive parsers.
--
-- @since 6.5.0
module Text.Megaparsec.Class
  ( MonadParsec (..),
  )
where

import Control.Monad
import Control.Monad.Identity
import qualified Control.Monad.RWS.Lazy as L
import qualified Control.Monad.RWS.Strict as S
import Control.Monad.Trans
import qualified Control.Monad.Trans.Reader as L
import qualified Control.Monad.Trans.State.Lazy as L
import qualified Control.Monad.Trans.State.Strict as S
import qualified Control.Monad.Trans.Writer.Lazy as L
import qualified Control.Monad.Trans.Writer.Strict as S
import Data.Set (Set)
import Text.Megaparsec.Error
import Text.Megaparsec.State
import Text.Megaparsec.Stream

-- | Type class describing monads that implement the full set of primitive
-- parsers.
--
-- __Note__ that the following primitives are “fast” and should be taken
-- advantage of as much as possible if your aim is a fast parser: 'tokens',
-- 'takeWhileP', 'takeWhile1P', and 'takeP'.
class (Stream s, MonadPlus m) => MonadParsec e s m | m -> e s where
  -- | Stop parsing and report the 'ParseError'. This is the only way to
  -- control position of the error without manipulating the parser state
  -- manually.
  --
  -- @since 8.0.0
  parseError :: ParseError s e -> m a

  -- | The parser @'label' name p@ behaves as parser @p@, but whenever the
  -- parser @p@ fails /without consuming any input/, it replaces names of
  -- “expected” tokens with the name @name@.
  label :: String -> m a -> m a

  -- | @'hidden' p@ behaves just like parser @p@, but it doesn't show any
  -- “expected” tokens in error message when @p@ fails.
  --
  -- Please use 'hidden' instead of the old @'label' ""@ idiom.
  hidden :: m a -> m a
  hidden = forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
""

  -- | The parser @'try' p@ behaves like the parser @p@, except that it
  -- backtracks the parser state when @p@ fails (either consuming input or
  -- not).
  --
  -- This combinator is used whenever arbitrary look ahead is needed. Since
  -- it pretends that it hasn't consumed any input when @p@ fails, the
  -- ('A.<|>') combinator will try its second alternative even if the first
  -- parser failed while consuming input.
  --
  -- For example, here is a parser that is supposed to parse the word “let”
  -- or the word “lexical”:
  --
  -- >>> parseTest (string "let" <|> string "lexical") "lexical"
  -- 1:1:
  -- unexpected "lex"
  -- expecting "let"
  --
  -- What happens here? The first parser consumes “le” and fails (because it
  -- doesn't see a “t”). The second parser, however, isn't tried, since the
  -- first parser has already consumed some input! 'try' fixes this behavior
  -- and allows backtracking to work:
  --
  -- >>> parseTest (try (string "let") <|> string "lexical") "lexical"
  -- "lexical"
  --
  -- 'try' also improves error messages in case of overlapping alternatives,
  -- because Megaparsec's hint system can be used:
  --
  -- >>> parseTest (try (string "let") <|> string "lexical") "le"
  -- 1:1:
  -- unexpected "le"
  -- expecting "let" or "lexical"
  --
  -- __Note__ that as of Megaparsec 4.4.0, 'Text.Megaparsec.Char.string'
  -- backtracks automatically (see 'tokens'), so it does not need 'try'.
  -- However, the examples above demonstrate the idea behind 'try' so well
  -- that it was decided to keep them. You still need to use 'try' when your
  -- alternatives are complex, composite parsers.
  try :: m a -> m a

  -- | If @p@ in @'lookAhead' p@ succeeds (either consuming input or not)
  -- the whole parser behaves like @p@ succeeded without consuming anything
  -- (parser state is not updated as well). If @p@ fails, 'lookAhead' has no
  -- effect, i.e. it will fail consuming input if @p@ fails consuming input.
  -- Combine with 'try' if this is undesirable.
  lookAhead :: m a -> m a

  -- | @'notFollowedBy' p@ only succeeds when the parser @p@ fails. This
  -- parser /never consumes/ any input and /never modifies/ parser state. It
  -- can be used to implement the “longest match” rule.
  notFollowedBy :: m a -> m ()

  -- | @'withRecovery' r p@ allows us to continue parsing even if the parser
  -- @p@ fails. In this case @r@ is called with the actual 'ParseError' as
  -- its argument. Typical usage is to return a value signifying failure to
  -- parse this particular object and to consume some part of the input up
  -- to the point where the next object starts.
  --
  -- Note that if @r@ fails, the original error message is reported as if
  -- without 'withRecovery'. In no way recovering parser @r@ can influence
  -- error messages.
  --
  -- @since 4.4.0
  withRecovery ::
    -- | How to recover from failure
    (ParseError s e -> m a) ->
    -- | Original parser
    m a ->
    -- | Parser that can recover from failures
    m a

  -- | @'observing' p@ allows us to “observe” failure of the @p@ parser,
  -- should it happen, without actually ending parsing but instead getting
  -- the 'ParseError' in 'Left'. On success parsed value is returned in
  -- 'Right' as usual. Note that this primitive just allows you to observe
  -- parse errors as they happen, it does not backtrack or change how the
  -- @p@ parser works in any way.
  --
  -- @since 5.1.0
  observing ::
    -- | The parser to run
    m a ->
    m (Either (ParseError s e) a)

  -- | This parser only succeeds at the end of input.
  eof :: m ()

  -- | The parser @'token' test expected@ accepts tokens for which the
  -- matching function @test@ returns 'Just' results. If 'Nothing' is
  -- returned the @expected@ set is used to report the items that were
  -- expected.
  --
  -- For example, the 'Text.Megaparsec.satisfy' parser is implemented as:
  --
  -- > satisfy f = token testToken Set.empty
  -- >   where
  -- >     testToken x = if f x then Just x else Nothing
  --
  -- __Note__: type signature of this primitive was changed in the version
  -- /7.0.0/.
  token ::
    -- | Matching function for the token to parse
    (Token s -> Maybe a) ->
    -- | Used in the error message to mention the items that were expected
    Set (ErrorItem (Token s)) ->
    m a

  -- | The parser @'tokens' test chk@ parses a chunk of input @chk@ and
  -- returns it. The supplied predicate @test@ is used to check equality of
  -- given and parsed chunks after a candidate chunk of correct length is
  -- fetched from the stream.
  --
  -- This can be used for example to write 'Text.Megaparsec.chunk':
  --
  -- > chunk = tokens (==)
  --
  -- Note that beginning from Megaparsec 4.4.0, this is an auto-backtracking
  -- primitive, which means that if it fails, it never consumes any input.
  -- This is done to make its consumption model match how error messages for
  -- this primitive are reported (which becomes an important thing as user
  -- gets more control with primitives like 'withRecovery'):
  --
  -- >>> parseTest (string "abc") "abd"
  -- 1:1:
  -- unexpected "abd"
  -- expecting "abc"
  --
  -- This means, in particular, that it's no longer necessary to use 'try'
  -- with 'tokens'-based parsers, such as 'Text.Megaparsec.Char.string' and
  -- 'Text.Megaparsec.Char.string''. This feature /does not/ affect
  -- performance in any way.
  tokens ::
    -- | Predicate to check equality of chunks
    (Tokens s -> Tokens s -> Bool) ->
    -- | Chunk of input to match against
    Tokens s ->
    m (Tokens s)

  -- | Parse /zero/ or more tokens for which the supplied predicate holds.
  -- Try to use this as much as possible because for many streams this
  -- combinator is much faster than parsers built with
  -- 'Control.Monad.Combinators.many' and 'Text.Megaparsec.satisfy'.
  --
  -- > takeWhileP (Just "foo") f = many (satisfy f <?> "foo")
  -- > takeWhileP Nothing      f = many (satisfy f)
  --
  -- The combinator never fails, although it may parse the empty chunk.
  --
  -- @since 6.0.0
  takeWhileP ::
    -- | Name for a single token in the row
    Maybe String ->
    -- | Predicate to use to test tokens
    (Token s -> Bool) ->
    -- | A chunk of matching tokens
    m (Tokens s)

  -- | Similar to 'takeWhileP', but fails if it can't parse at least one
  -- token. Try to use this as much as possible because for many streams
  -- this combinator is much faster than parsers built with
  -- 'Control.Monad.Combinators.some' and 'Text.Megaparsec.satisfy'.
  --
  -- > takeWhile1P (Just "foo") f = some (satisfy f <?> "foo")
  -- > takeWhile1P Nothing      f = some (satisfy f)
  --
  -- Note that the combinator either succeeds or fails without consuming any
  -- input, so 'try' is not necessary with it.
  --
  -- @since 6.0.0
  takeWhile1P ::
    -- | Name for a single token in the row
    Maybe String ->
    -- | Predicate to use to test tokens
    (Token s -> Bool) ->
    -- | A chunk of matching tokens
    m (Tokens s)

  -- | Extract the specified number of tokens from the input stream and
  -- return them packed as a chunk of stream. If there is not enough tokens
  -- in the stream, a parse error will be signaled. It's guaranteed that if
  -- the parser succeeds, the requested number of tokens will be returned.
  --
  -- The parser is roughly equivalent to:
  --
  -- > takeP (Just "foo") n = count n (anySingle <?> "foo")
  -- > takeP Nothing      n = count n anySingle
  --
  -- Note that if the combinator fails due to insufficient number of tokens
  -- in the input stream, it backtracks automatically. No 'try' is necessary
  -- with 'takeP'.
  --
  -- @since 6.0.0
  takeP ::
    -- | Name for a single token in the row
    Maybe String ->
    -- | How many tokens to extract
    Int ->
    -- | A chunk of matching tokens
    m (Tokens s)

  -- | Return the full parser state as a 'State' record.
  getParserState :: m (State s e)

  -- | @'updateParserState' f@ applies the function @f@ to the parser state.
  updateParserState :: (State s e -> State s e) -> m ()

----------------------------------------------------------------------------
-- Lifting through MTL

instance MonadParsec e s m => MonadParsec e s (L.StateT st m) where
  parseError :: forall a. ParseError s e -> StateT st m a
parseError ParseError s e
e = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
ParseError s e -> m a
parseError ParseError s e
e)
  label :: forall a. String -> StateT st m a -> StateT st m a
label String
n (L.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. st -> m (a, st)
m
  try :: forall a. StateT st m a -> StateT st m a
try (L.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try forall b c a. (b -> c) -> (a -> b) -> a -> c
. st -> m (a, st)
m
  lookAhead :: forall a. StateT st m a -> StateT st m a
lookAhead (L.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT forall a b. (a -> b) -> a -> b
$ \st
s ->
    (,st
s) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead (st -> m (a, st)
m st
s)
  notFollowedBy :: forall a. StateT st m a -> StateT st m ()
notFollowedBy (L.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT forall a b. (a -> b) -> a -> b
$ \st
s ->
    forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> st -> m (a, st)
m st
s) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return ((), st
s)
  withRecovery :: forall a.
(ParseError s e -> StateT st m a) -> StateT st m a -> StateT st m a
withRecovery ParseError s e -> StateT st m a
r (L.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT forall a b. (a -> b) -> a -> b
$ \st
s ->
    forall e s (m :: * -> *) a.
MonadParsec e s m =>
(ParseError s e -> m a) -> m a -> m a
withRecovery (\ParseError s e
e -> forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
L.runStateT (ParseError s e -> StateT st m a
r ParseError s e
e) st
s) (st -> m (a, st)
m st
s)
  observing :: forall a. StateT st m a -> StateT st m (Either (ParseError s e) a)
observing (L.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
L.StateT forall a b. (a -> b) -> a -> b
$ \st
s ->
    forall s a b. s -> Either a (b, s) -> (Either a b, s)
fixs st
s forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> m (Either (ParseError s e) a)
observing (st -> m (a, st)
m st
s)
  eof :: StateT st m ()
eof = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m ()
eof
  token :: forall a.
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> StateT st m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt)
  tokens :: (Tokens s -> Tokens s -> Bool)
-> Tokens s -> StateT st m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts)
  takeWhileP :: Maybe String -> (Token s -> Bool) -> StateT st m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f)
  takeWhile1P :: Maybe String -> (Token s -> Bool) -> StateT st m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f)
  takeP :: Maybe String -> Int -> StateT st m (Tokens s)
takeP Maybe String
l Int
n = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> Int -> m (Tokens s)
takeP Maybe String
l Int
n)
  getParserState :: StateT st m (State s e)
getParserState = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m (State s e)
getParserState
  updateParserState :: (State s e -> State s e) -> StateT st m ()
updateParserState State s e -> State s e
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(State s e -> State s e) -> m ()
updateParserState State s e -> State s e
f)

instance MonadParsec e s m => MonadParsec e s (S.StateT st m) where
  parseError :: forall a. ParseError s e -> StateT st m a
parseError ParseError s e
e = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
ParseError s e -> m a
parseError ParseError s e
e)
  label :: forall a. String -> StateT st m a -> StateT st m a
label String
n (S.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. st -> m (a, st)
m
  try :: forall a. StateT st m a -> StateT st m a
try (S.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try forall b c a. (b -> c) -> (a -> b) -> a -> c
. st -> m (a, st)
m
  lookAhead :: forall a. StateT st m a -> StateT st m a
lookAhead (S.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT forall a b. (a -> b) -> a -> b
$ \st
s ->
    (,st
s) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead (st -> m (a, st)
m st
s)
  notFollowedBy :: forall a. StateT st m a -> StateT st m ()
notFollowedBy (S.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT forall a b. (a -> b) -> a -> b
$ \st
s ->
    forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> st -> m (a, st)
m st
s) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return ((), st
s)
  withRecovery :: forall a.
(ParseError s e -> StateT st m a) -> StateT st m a -> StateT st m a
withRecovery ParseError s e -> StateT st m a
r (S.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT forall a b. (a -> b) -> a -> b
$ \st
s ->
    forall e s (m :: * -> *) a.
MonadParsec e s m =>
(ParseError s e -> m a) -> m a -> m a
withRecovery (\ParseError s e
e -> forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
S.runStateT (ParseError s e -> StateT st m a
r ParseError s e
e) st
s) (st -> m (a, st)
m st
s)
  observing :: forall a. StateT st m a -> StateT st m (Either (ParseError s e) a)
observing (S.StateT st -> m (a, st)
m) = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
S.StateT forall a b. (a -> b) -> a -> b
$ \st
s ->
    forall s a b. s -> Either a (b, s) -> (Either a b, s)
fixs st
s forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> m (Either (ParseError s e) a)
observing (st -> m (a, st)
m st
s)
  eof :: StateT st m ()
eof = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m ()
eof
  token :: forall a.
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> StateT st m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt)
  tokens :: (Tokens s -> Tokens s -> Bool)
-> Tokens s -> StateT st m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts)
  takeWhileP :: Maybe String -> (Token s -> Bool) -> StateT st m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f)
  takeWhile1P :: Maybe String -> (Token s -> Bool) -> StateT st m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f)
  takeP :: Maybe String -> Int -> StateT st m (Tokens s)
takeP Maybe String
l Int
n = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> Int -> m (Tokens s)
takeP Maybe String
l Int
n)
  getParserState :: StateT st m (State s e)
getParserState = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m (State s e)
getParserState
  updateParserState :: (State s e -> State s e) -> StateT st m ()
updateParserState State s e -> State s e
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(State s e -> State s e) -> m ()
updateParserState State s e -> State s e
f)

instance MonadParsec e s m => MonadParsec e s (L.ReaderT r m) where
  parseError :: forall a. ParseError s e -> ReaderT r m a
parseError ParseError s e
e = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
ParseError s e -> m a
parseError ParseError s e
e)
  label :: forall a. String -> ReaderT r m a -> ReaderT r m a
label String
n (L.ReaderT r -> m a
m) = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
L.ReaderT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> m a
m
  try :: forall a. ReaderT r m a -> ReaderT r m a
try (L.ReaderT r -> m a
m) = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
L.ReaderT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> m a
m
  lookAhead :: forall a. ReaderT r m a -> ReaderT r m a
lookAhead (L.ReaderT r -> m a
m) = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
L.ReaderT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> m a
m
  notFollowedBy :: forall a. ReaderT r m a -> ReaderT r m ()
notFollowedBy (L.ReaderT r -> m a
m) = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
L.ReaderT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> m a
m
  withRecovery :: forall a.
(ParseError s e -> ReaderT r m a) -> ReaderT r m a -> ReaderT r m a
withRecovery ParseError s e -> ReaderT r m a
r (L.ReaderT r -> m a
m) = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
L.ReaderT forall a b. (a -> b) -> a -> b
$ \r
s ->
    forall e s (m :: * -> *) a.
MonadParsec e s m =>
(ParseError s e -> m a) -> m a -> m a
withRecovery (\ParseError s e
e -> forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
L.runReaderT (ParseError s e -> ReaderT r m a
r ParseError s e
e) r
s) (r -> m a
m r
s)
  observing :: forall a. ReaderT r m a -> ReaderT r m (Either (ParseError s e) a)
observing (L.ReaderT r -> m a
m) = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
L.ReaderT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> m (Either (ParseError s e) a)
observing forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> m a
m
  eof :: ReaderT r m ()
eof = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m ()
eof
  token :: forall a.
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> ReaderT r m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt)
  tokens :: (Tokens s -> Tokens s -> Bool)
-> Tokens s -> ReaderT r m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts)
  takeWhileP :: Maybe String -> (Token s -> Bool) -> ReaderT r m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f)
  takeWhile1P :: Maybe String -> (Token s -> Bool) -> ReaderT r m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f)
  takeP :: Maybe String -> Int -> ReaderT r m (Tokens s)
takeP Maybe String
l Int
n = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> Int -> m (Tokens s)
takeP Maybe String
l Int
n)
  getParserState :: ReaderT r m (State s e)
getParserState = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m (State s e)
getParserState
  updateParserState :: (State s e -> State s e) -> ReaderT r m ()
updateParserState State s e -> State s e
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(State s e -> State s e) -> m ()
updateParserState State s e -> State s e
f)

instance (Monoid w, MonadParsec e s m) => MonadParsec e s (L.WriterT w m) where
  parseError :: forall a. ParseError s e -> WriterT w m a
parseError ParseError s e
e = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
ParseError s e -> m a
parseError ParseError s e
e)
  label :: forall a. String -> WriterT w m a -> WriterT w m a
label String
n (L.WriterT m (a, w)
m) = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
n m (a, w)
m
  try :: forall a. WriterT w m a -> WriterT w m a
try (L.WriterT m (a, w)
m) = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try m (a, w)
m
  lookAhead :: forall a. WriterT w m a -> WriterT w m a
lookAhead (L.WriterT m (a, w)
m) =
    forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT forall a b. (a -> b) -> a -> b
$
      (,forall a. Monoid a => a
mempty) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead m (a, w)
m
  notFollowedBy :: forall a. WriterT w m a -> WriterT w m ()
notFollowedBy (L.WriterT m (a, w)
m) =
    forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT forall a b. (a -> b) -> a -> b
$
      (,forall a. Monoid a => a
mempty) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (a, w)
m)
  withRecovery :: forall a.
(ParseError s e -> WriterT w m a) -> WriterT w m a -> WriterT w m a
withRecovery ParseError s e -> WriterT w m a
r (L.WriterT m (a, w)
m) =
    forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT forall a b. (a -> b) -> a -> b
$
      forall e s (m :: * -> *) a.
MonadParsec e s m =>
(ParseError s e -> m a) -> m a -> m a
withRecovery (forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
L.runWriterT forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e -> WriterT w m a
r) m (a, w)
m
  observing :: forall a. WriterT w m a -> WriterT w m (Either (ParseError s e) a)
observing (L.WriterT m (a, w)
m) =
    forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
L.WriterT forall a b. (a -> b) -> a -> b
$
      forall s a b. s -> Either a (b, s) -> (Either a b, s)
fixs forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> m (Either (ParseError s e) a)
observing m (a, w)
m
  eof :: WriterT w m ()
eof = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m ()
eof
  token :: forall a.
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> WriterT w m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt)
  tokens :: (Tokens s -> Tokens s -> Bool)
-> Tokens s -> WriterT w m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts)
  takeWhileP :: Maybe String -> (Token s -> Bool) -> WriterT w m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f)
  takeWhile1P :: Maybe String -> (Token s -> Bool) -> WriterT w m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f)
  takeP :: Maybe String -> Int -> WriterT w m (Tokens s)
takeP Maybe String
l Int
n = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> Int -> m (Tokens s)
takeP Maybe String
l Int
n)
  getParserState :: WriterT w m (State s e)
getParserState = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m (State s e)
getParserState
  updateParserState :: (State s e -> State s e) -> WriterT w m ()
updateParserState State s e -> State s e
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(State s e -> State s e) -> m ()
updateParserState State s e -> State s e
f)

instance (Monoid w, MonadParsec e s m) => MonadParsec e s (S.WriterT w m) where
  parseError :: forall a. ParseError s e -> WriterT w m a
parseError ParseError s e
e = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
ParseError s e -> m a
parseError ParseError s e
e)
  label :: forall a. String -> WriterT w m a -> WriterT w m a
label String
n (S.WriterT m (a, w)
m) = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
n m (a, w)
m
  try :: forall a. WriterT w m a -> WriterT w m a
try (S.WriterT m (a, w)
m) = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try m (a, w)
m
  lookAhead :: forall a. WriterT w m a -> WriterT w m a
lookAhead (S.WriterT m (a, w)
m) =
    forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT forall a b. (a -> b) -> a -> b
$
      (,forall a. Monoid a => a
mempty) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead m (a, w)
m
  notFollowedBy :: forall a. WriterT w m a -> WriterT w m ()
notFollowedBy (S.WriterT m (a, w)
m) =
    forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT forall a b. (a -> b) -> a -> b
$
      (,forall a. Monoid a => a
mempty) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (a, w)
m)
  withRecovery :: forall a.
(ParseError s e -> WriterT w m a) -> WriterT w m a -> WriterT w m a
withRecovery ParseError s e -> WriterT w m a
r (S.WriterT m (a, w)
m) =
    forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT forall a b. (a -> b) -> a -> b
$
      forall e s (m :: * -> *) a.
MonadParsec e s m =>
(ParseError s e -> m a) -> m a -> m a
withRecovery (forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
S.runWriterT forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e -> WriterT w m a
r) m (a, w)
m
  observing :: forall a. WriterT w m a -> WriterT w m (Either (ParseError s e) a)
observing (S.WriterT m (a, w)
m) =
    forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
S.WriterT forall a b. (a -> b) -> a -> b
$
      forall s a b. s -> Either a (b, s) -> (Either a b, s)
fixs forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> m (Either (ParseError s e) a)
observing m (a, w)
m
  eof :: WriterT w m ()
eof = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m ()
eof
  token :: forall a.
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> WriterT w m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt)
  tokens :: (Tokens s -> Tokens s -> Bool)
-> Tokens s -> WriterT w m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts)
  takeWhileP :: Maybe String -> (Token s -> Bool) -> WriterT w m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f)
  takeWhile1P :: Maybe String -> (Token s -> Bool) -> WriterT w m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f)
  takeP :: Maybe String -> Int -> WriterT w m (Tokens s)
takeP Maybe String
l Int
n = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> Int -> m (Tokens s)
takeP Maybe String
l Int
n)
  getParserState :: WriterT w m (State s e)
getParserState = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m (State s e)
getParserState
  updateParserState :: (State s e -> State s e) -> WriterT w m ()
updateParserState State s e -> State s e
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(State s e -> State s e) -> m ()
updateParserState State s e -> State s e
f)

-- | @since 5.2.0
instance (Monoid w, MonadParsec e s m) => MonadParsec e s (L.RWST r w st m) where
  parseError :: forall a. ParseError s e -> RWST r w st m a
parseError ParseError s e
e = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
ParseError s e -> m a
parseError ParseError s e
e)
  label :: forall a. String -> RWST r w st m a -> RWST r w st m a
label String
n (L.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s -> forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
n (r -> st -> m (a, st, w)
m r
r st
s)
  try :: forall a. RWST r w st m a -> RWST r w st m a
try (L.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s -> forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (r -> st -> m (a, st, w)
m r
r st
s)
  lookAhead :: forall a. RWST r w st m a -> RWST r w st m a
lookAhead (L.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s -> do
    (a
x, st
_, w
_) <- forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead (r -> st -> m (a, st, w)
m r
r st
s)
    forall (m :: * -> *) a. Monad m => a -> m a
return (a
x, st
s, forall a. Monoid a => a
mempty)
  notFollowedBy :: forall a. RWST r w st m a -> RWST r w st m ()
notFollowedBy (L.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s -> do
    forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ r -> st -> m (a, st, w)
m r
r st
s)
    forall (m :: * -> *) a. Monad m => a -> m a
return ((), st
s, forall a. Monoid a => a
mempty)
  withRecovery :: forall a.
(ParseError s e -> RWST r w st m a)
-> RWST r w st m a -> RWST r w st m a
withRecovery ParseError s e -> RWST r w st m a
n (L.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s ->
    forall e s (m :: * -> *) a.
MonadParsec e s m =>
(ParseError s e -> m a) -> m a -> m a
withRecovery (\ParseError s e
e -> forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
L.runRWST (ParseError s e -> RWST r w st m a
n ParseError s e
e) r
r st
s) (r -> st -> m (a, st, w)
m r
r st
s)
  observing :: forall a.
RWST r w st m a -> RWST r w st m (Either (ParseError s e) a)
observing (L.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
L.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s ->
    forall w s a b.
Monoid w =>
s -> Either a (b, s, w) -> (Either a b, s, w)
fixs' st
s forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> m (Either (ParseError s e) a)
observing (r -> st -> m (a, st, w)
m r
r st
s)
  eof :: RWST r w st m ()
eof = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m ()
eof
  token :: forall a.
(Token s -> Maybe a)
-> Set (ErrorItem (Token s)) -> RWST r w st m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt)
  tokens :: (Tokens s -> Tokens s -> Bool)
-> Tokens s -> RWST r w st m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts)
  takeWhileP :: Maybe String -> (Token s -> Bool) -> RWST r w st m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f)
  takeWhile1P :: Maybe String -> (Token s -> Bool) -> RWST r w st m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f)
  takeP :: Maybe String -> Int -> RWST r w st m (Tokens s)
takeP Maybe String
l Int
n = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> Int -> m (Tokens s)
takeP Maybe String
l Int
n)
  getParserState :: RWST r w st m (State s e)
getParserState = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m (State s e)
getParserState
  updateParserState :: (State s e -> State s e) -> RWST r w st m ()
updateParserState State s e -> State s e
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(State s e -> State s e) -> m ()
updateParserState State s e -> State s e
f)

-- | @since 5.2.0
instance (Monoid w, MonadParsec e s m) => MonadParsec e s (S.RWST r w st m) where
  parseError :: forall a. ParseError s e -> RWST r w st m a
parseError ParseError s e
e = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
ParseError s e -> m a
parseError ParseError s e
e)
  label :: forall a. String -> RWST r w st m a -> RWST r w st m a
label String
n (S.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s -> forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
n (r -> st -> m (a, st, w)
m r
r st
s)
  try :: forall a. RWST r w st m a -> RWST r w st m a
try (S.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s -> forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (r -> st -> m (a, st, w)
m r
r st
s)
  lookAhead :: forall a. RWST r w st m a -> RWST r w st m a
lookAhead (S.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s -> do
    (a
x, st
_, w
_) <- forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead (r -> st -> m (a, st, w)
m r
r st
s)
    forall (m :: * -> *) a. Monad m => a -> m a
return (a
x, st
s, forall a. Monoid a => a
mempty)
  notFollowedBy :: forall a. RWST r w st m a -> RWST r w st m ()
notFollowedBy (S.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s -> do
    forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ r -> st -> m (a, st, w)
m r
r st
s)
    forall (m :: * -> *) a. Monad m => a -> m a
return ((), st
s, forall a. Monoid a => a
mempty)
  withRecovery :: forall a.
(ParseError s e -> RWST r w st m a)
-> RWST r w st m a -> RWST r w st m a
withRecovery ParseError s e -> RWST r w st m a
n (S.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s ->
    forall e s (m :: * -> *) a.
MonadParsec e s m =>
(ParseError s e -> m a) -> m a -> m a
withRecovery (\ParseError s e
e -> forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
S.runRWST (ParseError s e -> RWST r w st m a
n ParseError s e
e) r
r st
s) (r -> st -> m (a, st, w)
m r
r st
s)
  observing :: forall a.
RWST r w st m a -> RWST r w st m (Either (ParseError s e) a)
observing (S.RWST r -> st -> m (a, st, w)
m) = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
S.RWST forall a b. (a -> b) -> a -> b
$ \r
r st
s ->
    forall w s a b.
Monoid w =>
s -> Either a (b, s, w) -> (Either a b, s, w)
fixs' st
s forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> m (Either (ParseError s e) a)
observing (r -> st -> m (a, st, w)
m r
r st
s)
  eof :: RWST r w st m ()
eof = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m ()
eof
  token :: forall a.
(Token s -> Maybe a)
-> Set (ErrorItem (Token s)) -> RWST r w st m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt)
  tokens :: (Tokens s -> Tokens s -> Bool)
-> Tokens s -> RWST r w st m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts)
  takeWhileP :: Maybe String -> (Token s -> Bool) -> RWST r w st m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f)
  takeWhile1P :: Maybe String -> (Token s -> Bool) -> RWST r w st m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f)
  takeP :: Maybe String -> Int -> RWST r w st m (Tokens s)
takeP Maybe String
l Int
n = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> Int -> m (Tokens s)
takeP Maybe String
l Int
n)
  getParserState :: RWST r w st m (State s e)
getParserState = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m (State s e)
getParserState
  updateParserState :: (State s e -> State s e) -> RWST r w st m ()
updateParserState State s e -> State s e
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
(State s e -> State s e) -> m ()
updateParserState State s e -> State s e
f)

instance MonadParsec e s m => MonadParsec e s (IdentityT m) where
  parseError :: forall a. ParseError s e -> IdentityT m a
parseError ParseError s e
e = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
ParseError s e -> m a
parseError ParseError s e
e)
  label :: forall a. String -> IdentityT m a -> IdentityT m a
label String
n (IdentityT m a
m) = forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
n m a
m
  try :: forall a. IdentityT m a -> IdentityT m a
try = forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT
  lookAhead :: forall a. IdentityT m a -> IdentityT m a
lookAhead (IdentityT m a
m) = forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead m a
m
  notFollowedBy :: forall a. IdentityT m a -> IdentityT m ()
notFollowedBy (IdentityT m a
m) = forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy m a
m
  withRecovery :: forall a.
(ParseError s e -> IdentityT m a) -> IdentityT m a -> IdentityT m a
withRecovery ParseError s e -> IdentityT m a
r (IdentityT m a
m) =
    forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT forall a b. (a -> b) -> a -> b
$
      forall e s (m :: * -> *) a.
MonadParsec e s m =>
(ParseError s e -> m a) -> m a -> m a
withRecovery (forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError s e -> IdentityT m a
r) m a
m
  observing :: forall a. IdentityT m a -> IdentityT m (Either (ParseError s e) a)
observing (IdentityT m a
m) = forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> m (Either (ParseError s e) a)
observing m a
m
  eof :: IdentityT m ()
eof = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m ()
eof
  token :: forall a.
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> IdentityT m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *) a.
MonadParsec e s m =>
(Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> m a
token Token s -> Maybe a
test Set (ErrorItem (Token s))
mt)
  tokens :: (Tokens s -> Tokens s -> Bool)
-> Tokens s -> IdentityT m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *).
MonadParsec e s m =>
(Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
e Tokens s
ts
  takeWhileP :: Maybe String -> (Token s -> Bool) -> IdentityT m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
l Token s -> Bool
f)
  takeWhile1P :: Maybe String -> (Token s -> Bool) -> IdentityT m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhile1P Maybe String
l Token s -> Bool
f)
  takeP :: Maybe String -> Int -> IdentityT m (Tokens s)
takeP Maybe String
l Int
n = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> Int -> m (Tokens s)
takeP Maybe String
l Int
n)
  getParserState :: IdentityT m (State s e)
getParserState = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall e s (m :: * -> *). MonadParsec e s m => m (State s e)
getParserState
  updateParserState :: (State s e -> State s e) -> IdentityT m ()
updateParserState State s e -> State s e
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall e s (m :: * -> *).
MonadParsec e s m =>
(State s e -> State s e) -> m ()
updateParserState State s e -> State s e
f

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

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