{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

-- |
-- Module      :  Text.Megaparsec.Internal
-- Copyright   :  © 2015–present Megaparsec contributors
--                © 2007 Paolo Martini
--                © 1999–2001 Daan Leijen
-- License     :  FreeBSD
--
-- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>
-- Stability   :  experimental
-- Portability :  portable
--
-- Internal definitions. Versioning rules do not apply here. Please do not
-- rely on these unless you really know what you're doing.
--
-- @since 6.5.0
module Text.Megaparsec.Internal
  ( -- * Data types
    Hints (..),
    Reply (..),
    Consumption (..),
    Result (..),
    ParsecT (..),

    -- * Helper functions
    toHints,
    withHints,
    accHints,
    refreshLastHint,
    runParsecT,
    withParsecT,
  )
where

import Control.Applicative
import Control.Monad
import Control.Monad.Cont.Class
import Control.Monad.Error.Class
import qualified Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Reader.Class
import Control.Monad.State.Class
import Control.Monad.Trans
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NE
import Data.Proxy
import Data.Semigroup
import Data.Set (Set)
import qualified Data.Set as E
import Data.String (IsString (..))
import Text.Megaparsec.Class
import Text.Megaparsec.Error
import Text.Megaparsec.State
import Text.Megaparsec.Stream

----------------------------------------------------------------------------
-- Data types

-- | 'Hints' represent a collection of 'ErrorItem's to be included into
-- 'ParseError' (when it's a 'TrivialError') as “expected” message items
-- when a parser fails without consuming input right after successful parser
-- that produced the hints.
--
-- For example, without hints you could get:
--
-- >>> parseTest (many (char 'r') <* eof) "ra"
-- 1:2:
-- unexpected 'a'
-- expecting end of input
--
-- We're getting better error messages with the help of hints:
--
-- >>> parseTest (many (char 'r') <* eof) "ra"
-- 1:2:
-- unexpected 'a'
-- expecting 'r' or end of input
newtype Hints t = Hints [Set (ErrorItem t)]

instance Semigroup (Hints t) where
  Hints [Set (ErrorItem t)]
xs <> :: Hints t -> Hints t -> Hints t
<> Hints [Set (ErrorItem t)]
ys = [Set (ErrorItem t)] -> Hints t
forall t. [Set (ErrorItem t)] -> Hints t
Hints ([Set (ErrorItem t)] -> Hints t) -> [Set (ErrorItem t)] -> Hints t
forall a b. (a -> b) -> a -> b
$ [Set (ErrorItem t)]
xs [Set (ErrorItem t)] -> [Set (ErrorItem t)] -> [Set (ErrorItem t)]
forall a. Semigroup a => a -> a -> a
<> [Set (ErrorItem t)]
ys

instance Monoid (Hints t) where
  mempty :: Hints t
mempty = [Set (ErrorItem t)] -> Hints t
forall t. [Set (ErrorItem t)] -> Hints t
Hints [Set (ErrorItem t)]
forall a. Monoid a => a
mempty

-- | All information available after parsing. This includes consumption of
-- input, success (with the returned value) or failure (with the parse
-- error), and parser state at the end of parsing.
--
-- See also: 'Consumption', 'Result'.
data Reply e s a = Reply (State s e) Consumption (Result s e a)

-- | Whether the input has been consumed or not.
--
-- See also: 'Result', 'Reply'.
data Consumption
  = -- | Some part of input stream was consumed
    Consumed
  | -- | No input was consumed
    Virgin

-- | Whether the parser has failed or not. On success we include the
-- resulting value, on failure we include a 'ParseError'.
--
-- See also: 'Consumption', 'Reply'.
data Result s e a
  = -- | Parser succeeded
    OK a
  | -- | Parser failed
    Error (ParseError s e)

-- | @'ParsecT' e s m a@ is a parser with custom data component of error
-- @e@, stream type @s@, underlying monad @m@ and return type @a@.
newtype ParsecT e s m a = ParsecT
  { forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ::
      forall b.
      State s e ->
      (a -> State s e -> Hints (Token s) -> m b) -> -- consumed-OK
      (ParseError s e -> State s e -> m b) -> -- consumed-error
      (a -> State s e -> Hints (Token s) -> m b) -> -- empty-OK
      (ParseError s e -> State s e -> m b) -> -- empty-error
      m b
  }

-- | @since 5.3.0
instance (Stream s, Semigroup a) => Semigroup (ParsecT e s m a) where
  <> :: ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
(<>) = (a -> a -> a)
-> ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>)
  {-# INLINE (<>) #-}
  sconcat :: NonEmpty (ParsecT e s m a) -> ParsecT e s m a
sconcat = (NonEmpty a -> a) -> ParsecT e s m (NonEmpty a) -> ParsecT e s m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NonEmpty a -> a
forall a. Semigroup a => NonEmpty a -> a
sconcat (ParsecT e s m (NonEmpty a) -> ParsecT e s m a)
-> (NonEmpty (ParsecT e s m a) -> ParsecT e s m (NonEmpty a))
-> NonEmpty (ParsecT e s m a)
-> ParsecT e s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (ParsecT e s m a) -> ParsecT e s m (NonEmpty a)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
  {-# INLINE sconcat #-}

-- | @since 5.3.0
instance (Stream s, Monoid a) => Monoid (ParsecT e s m a) where
  mempty :: ParsecT e s m a
mempty = a -> ParsecT e s m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Monoid a => a
mempty
  {-# INLINE mempty #-}
  mappend :: ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
mappend = ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
forall a. Semigroup a => a -> a -> a
(<>)
  {-# INLINE mappend #-}
  mconcat :: [ParsecT e s m a] -> ParsecT e s m a
mconcat = ([a] -> a) -> ParsecT e s m [a] -> ParsecT e s m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [a] -> a
forall a. Monoid a => [a] -> a
mconcat (ParsecT e s m [a] -> ParsecT e s m a)
-> ([ParsecT e s m a] -> ParsecT e s m [a])
-> [ParsecT e s m a]
-> ParsecT e s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ParsecT e s m a] -> ParsecT e s m [a]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
  {-# INLINE mconcat #-}

-- | @since 6.3.0
instance
  (a ~ Tokens s, IsString a, Eq a, Stream s, Ord e) =>
  IsString (ParsecT e s m a)
  where
  fromString :: String -> ParsecT e s m a
fromString String
s = (Tokens s -> Tokens s -> Bool)
-> Tokens s -> ParsecT e s m (Tokens s)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
tokens Tokens s -> Tokens s -> Bool
forall a. Eq a => a -> a -> Bool
(==) (String -> a
forall a. IsString a => String -> a
fromString String
s)

instance Functor (ParsecT e s m) where
  fmap :: forall a b. (a -> b) -> ParsecT e s m a -> ParsecT e s m b
fmap = (a -> b) -> ParsecT e s m a -> ParsecT e s m b
forall a b e s (m :: * -> *).
(a -> b) -> ParsecT e s m a -> ParsecT e s m b
pMap

pMap :: (a -> b) -> ParsecT e s m a -> ParsecT e s m b
pMap :: forall a b e s (m :: * -> *).
(a -> b) -> ParsecT e s m a -> ParsecT e s m b
pMap a -> b
f ParsecT e s m a
p = (forall b.
 State s e
 -> (b -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (b -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m b
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (b -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (b -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m b)
-> (forall b.
    State s e
    -> (b -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (b -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m b
forall a b. (a -> b) -> a -> b
$ \State s e
s b -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
cerr b -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m a
p State s e
s (b -> State s e -> Hints (Token s) -> m b
cok (b -> State s e -> Hints (Token s) -> m b)
-> (a -> b) -> a -> State s e -> Hints (Token s) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) ParseError s e -> State s e -> m b
cerr (b -> State s e -> Hints (Token s) -> m b
eok (b -> State s e -> Hints (Token s) -> m b)
-> (a -> b) -> a -> State s e -> Hints (Token s) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) ParseError s e -> State s e -> m b
eerr
{-# INLINE pMap #-}

-- | 'pure' returns a parser that __succeeds__ without consuming input.
instance Stream s => Applicative (ParsecT e s m) where
  pure :: forall a. a -> ParsecT e s m a
pure = a -> ParsecT e s m a
forall a e s (m :: * -> *). a -> ParsecT e s m a
pPure
  <*> :: forall a b.
ParsecT e s m (a -> b) -> ParsecT e s m a -> ParsecT e s m b
(<*>) = ParsecT e s m (a -> b) -> ParsecT e s m a -> ParsecT e s m b
forall s e (m :: * -> *) a b.
Stream s =>
ParsecT e s m (a -> b) -> ParsecT e s m a -> ParsecT e s m b
pAp
  ParsecT e s m a
p1 *> :: forall a b. ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m b
*> ParsecT e s m b
p2 = ParsecT e s m a
p1 ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b
forall s e (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b
`pBind` ParsecT e s m b -> a -> ParsecT e s m b
forall a b. a -> b -> a
const ParsecT e s m b
p2
  ParsecT e s m a
p1 <* :: forall a b. ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m a
<* ParsecT e s m b
p2 = do a
x1 <- ParsecT e s m a
p1; ParsecT e s m b -> ParsecT e s m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT e s m b
p2; a -> ParsecT e s m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x1

pPure :: a -> ParsecT e s m a
pPure :: forall a e s (m :: * -> *). a -> ParsecT e s m a
pPure a
x = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s a -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
_ a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
_ -> a -> State s e -> Hints (Token s) -> m b
eok a
x State s e
s Hints (Token s)
forall a. Monoid a => a
mempty
{-# INLINE pPure #-}

pAp ::
  Stream s =>
  ParsecT e s m (a -> b) ->
  ParsecT e s m a ->
  ParsecT e s m b
pAp :: forall s e (m :: * -> *) a b.
Stream s =>
ParsecT e s m (a -> b) -> ParsecT e s m a -> ParsecT e s m b
pAp ParsecT e s m (a -> b)
m ParsecT e s m a
k = (forall b.
 State s e
 -> (b -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (b -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m b
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (b -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (b -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m b)
-> (forall b.
    State s e
    -> (b -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (b -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m b
forall a b. (a -> b) -> a -> b
$ \State s e
s b -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
cerr b -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  let mcok :: (a -> b) -> State s e -> Hints (Token s) -> m b
mcok a -> b
x State s e
s' Hints (Token s)
hs =
        ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser
          ParsecT e s m a
k
          State s e
s'
          (b -> State s e -> Hints (Token s) -> m b
cok (b -> State s e -> Hints (Token s) -> m b)
-> (a -> b) -> a -> State s e -> Hints (Token s) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
x)
          ParseError s e -> State s e -> m b
cerr
          (Hints (Token s)
-> (a -> State s e -> Hints (Token s) -> m b)
-> a
-> State s e
-> Hints (Token s)
-> m b
forall t a s e (m :: * -> *) b.
Hints t
-> (a -> State s e -> Hints t -> m b)
-> a
-> State s e
-> Hints t
-> m b
accHints Hints (Token s)
hs (b -> State s e -> Hints (Token s) -> m b
cok (b -> State s e -> Hints (Token s) -> m b)
-> (a -> b) -> a -> State s e -> Hints (Token s) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
x))
          (Hints (Token s)
-> (ParseError s e -> State s e -> m b)
-> ParseError s e
-> State s e
-> m b
forall s e (m :: * -> *) b.
Stream s =>
Hints (Token s)
-> (ParseError s e -> State s e -> m b)
-> ParseError s e
-> State s e
-> m b
withHints Hints (Token s)
hs ParseError s e -> State s e -> m b
cerr)
      meok :: (a -> b) -> State s e -> Hints (Token s) -> m b
meok a -> b
x State s e
s' Hints (Token s)
hs =
        ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser
          ParsecT e s m a
k
          State s e
s'
          (b -> State s e -> Hints (Token s) -> m b
cok (b -> State s e -> Hints (Token s) -> m b)
-> (a -> b) -> a -> State s e -> Hints (Token s) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
x)
          ParseError s e -> State s e -> m b
cerr
          (Hints (Token s)
-> (a -> State s e -> Hints (Token s) -> m b)
-> a
-> State s e
-> Hints (Token s)
-> m b
forall t a s e (m :: * -> *) b.
Hints t
-> (a -> State s e -> Hints t -> m b)
-> a
-> State s e
-> Hints t
-> m b
accHints Hints (Token s)
hs (b -> State s e -> Hints (Token s) -> m b
eok (b -> State s e -> Hints (Token s) -> m b)
-> (a -> b) -> a -> State s e -> Hints (Token s) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
x))
          (Hints (Token s)
-> (ParseError s e -> State s e -> m b)
-> ParseError s e
-> State s e
-> m b
forall s e (m :: * -> *) b.
Stream s =>
Hints (Token s)
-> (ParseError s e -> State s e -> m b)
-> ParseError s e
-> State s e
-> m b
withHints Hints (Token s)
hs ParseError s e -> State s e -> m b
eerr)
   in ParsecT e s m (a -> b)
-> forall b.
   State s e
   -> ((a -> b) -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> ((a -> b) -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m (a -> b)
m State s e
s (a -> b) -> State s e -> Hints (Token s) -> m b
mcok ParseError s e -> State s e -> m b
cerr (a -> b) -> State s e -> Hints (Token s) -> m b
meok ParseError s e -> State s e -> m b
eerr
{-# INLINE pAp #-}

-- | 'empty' is a parser that __fails__ without consuming input.
instance (Ord e, Stream s) => Alternative (ParsecT e s m) where
  empty :: forall a. ParsecT e s m a
empty = ParsecT e s m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
  <|> :: forall a. ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
(<|>) = ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus

-- | 'return' returns a parser that __succeeds__ without consuming input.
instance Stream s => Monad (ParsecT e s m) where
  return :: forall a. a -> ParsecT e s m a
return = a -> ParsecT e s m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
  >>= :: forall a b.
ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b
(>>=) = ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b
forall s e (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b
pBind

pBind ::
  Stream s =>
  ParsecT e s m a ->
  (a -> ParsecT e s m b) ->
  ParsecT e s m b
pBind :: forall s e (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b
pBind ParsecT e s m a
m a -> ParsecT e s m b
k = (forall b.
 State s e
 -> (b -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (b -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m b
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (b -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (b -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m b)
-> (forall b.
    State s e
    -> (b -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (b -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m b
forall a b. (a -> b) -> a -> b
$ \State s e
s b -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
cerr b -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  let mcok :: a -> State s e -> Hints (Token s) -> m b
mcok a
x State s e
s' Hints (Token s)
hs =
        ParsecT e s m b
-> forall b.
   State s e
   -> (b -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (b -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser
          (a -> ParsecT e s m b
k a
x)
          State s e
s'
          b -> State s e -> Hints (Token s) -> m b
cok
          ParseError s e -> State s e -> m b
cerr
          (Hints (Token s)
-> (b -> State s e -> Hints (Token s) -> m b)
-> b
-> State s e
-> Hints (Token s)
-> m b
forall t a s e (m :: * -> *) b.
Hints t
-> (a -> State s e -> Hints t -> m b)
-> a
-> State s e
-> Hints t
-> m b
accHints Hints (Token s)
hs b -> State s e -> Hints (Token s) -> m b
cok)
          (Hints (Token s)
-> (ParseError s e -> State s e -> m b)
-> ParseError s e
-> State s e
-> m b
forall s e (m :: * -> *) b.
Stream s =>
Hints (Token s)
-> (ParseError s e -> State s e -> m b)
-> ParseError s e
-> State s e
-> m b
withHints Hints (Token s)
hs ParseError s e -> State s e -> m b
cerr)
      meok :: a -> State s e -> Hints (Token s) -> m b
meok a
x State s e
s' Hints (Token s)
hs =
        ParsecT e s m b
-> forall b.
   State s e
   -> (b -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (b -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser
          (a -> ParsecT e s m b
k a
x)
          State s e
s'
          b -> State s e -> Hints (Token s) -> m b
cok
          ParseError s e -> State s e -> m b
cerr
          (Hints (Token s)
-> (b -> State s e -> Hints (Token s) -> m b)
-> b
-> State s e
-> Hints (Token s)
-> m b
forall t a s e (m :: * -> *) b.
Hints t
-> (a -> State s e -> Hints t -> m b)
-> a
-> State s e
-> Hints t
-> m b
accHints Hints (Token s)
hs b -> State s e -> Hints (Token s) -> m b
eok)
          (Hints (Token s)
-> (ParseError s e -> State s e -> m b)
-> ParseError s e
-> State s e
-> m b
forall s e (m :: * -> *) b.
Stream s =>
Hints (Token s)
-> (ParseError s e -> State s e -> m b)
-> ParseError s e
-> State s e
-> m b
withHints Hints (Token s)
hs ParseError s e -> State s e -> m b
eerr)
   in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m a
m State s e
s a -> State s e -> Hints (Token s) -> m b
mcok ParseError s e -> State s e -> m b
cerr a -> State s e -> Hints (Token s) -> m b
meok ParseError s e -> State s e -> m b
eerr
{-# INLINE pBind #-}

instance Stream s => Fail.MonadFail (ParsecT e s m) where
  fail :: forall a. String -> ParsecT e s m a
fail = String -> ParsecT e s m a
forall e s (m :: * -> *) a. String -> ParsecT e s m a
pFail

pFail :: String -> ParsecT e s m a
pFail :: forall e s (m :: * -> *) a. String -> ParsecT e s m a
pFail String
msg = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \s :: State s e
s@(State s
_ Int
o PosState s
_ [ParseError s e]
_) a -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
_ a -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
eerr ->
  let d :: Set (ErrorFancy e)
d = ErrorFancy e -> Set (ErrorFancy e)
forall a. a -> Set a
E.singleton (String -> ErrorFancy e
forall e. String -> ErrorFancy e
ErrorFail String
msg)
   in ParseError s e -> State s e -> m b
eerr (Int -> Set (ErrorFancy e) -> ParseError s e
forall s e. Int -> Set (ErrorFancy e) -> ParseError s e
FancyError Int
o Set (ErrorFancy e)
d) State s e
s
{-# INLINE pFail #-}

instance (Stream s, MonadIO m) => MonadIO (ParsecT e s m) where
  liftIO :: forall a. IO a -> ParsecT e s m a
liftIO = m a -> ParsecT e s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ParsecT e s m a)
-> (IO a -> m a) -> IO a -> ParsecT e s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO

instance (Stream s, MonadReader r m) => MonadReader r (ParsecT e s m) where
  ask :: ParsecT e s m r
ask = m r -> ParsecT e s m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m r
forall r (m :: * -> *). MonadReader r m => m r
ask
  local :: forall a. (r -> r) -> ParsecT e s m a -> ParsecT e s m a
local r -> r
f ParsecT e s m a
p = (State s e -> m (Reply e s a)) -> ParsecT e s m a
forall (m :: * -> *) s e a.
Monad m =>
(State s e -> m (Reply e s a)) -> ParsecT e s m a
mkPT ((State s e -> m (Reply e s a)) -> ParsecT e s m a)
-> (State s e -> m (Reply e s a)) -> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s -> (r -> r) -> m (Reply e s a) -> m (Reply e s a)
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local r -> r
f (ParsecT e s m a -> State s e -> m (Reply e s a)
forall (m :: * -> *) e s a.
Monad m =>
ParsecT e s m a -> State s e -> m (Reply e s a)
runParsecT ParsecT e s m a
p State s e
s)

instance (Stream s, MonadState st m) => MonadState st (ParsecT e s m) where
  get :: ParsecT e s m st
get = m st -> ParsecT e s m st
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m st
forall s (m :: * -> *). MonadState s m => m s
get
  put :: st -> ParsecT e s m ()
put = m () -> ParsecT e s m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ParsecT e s m ())
-> (st -> m ()) -> st -> ParsecT e s m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. st -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put

instance (Stream s, MonadCont m) => MonadCont (ParsecT e s m) where
  callCC :: forall a b.
((a -> ParsecT e s m b) -> ParsecT e s m a) -> ParsecT e s m a
callCC (a -> ParsecT e s m b) -> ParsecT e s m a
f = (State s e -> m (Reply e s a)) -> ParsecT e s m a
forall (m :: * -> *) s e a.
Monad m =>
(State s e -> m (Reply e s a)) -> ParsecT e s m a
mkPT ((State s e -> m (Reply e s a)) -> ParsecT e s m a)
-> (State s e -> m (Reply e s a)) -> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s ->
    ((Reply e s a -> m (Reply e s b)) -> m (Reply e s a))
-> m (Reply e s a)
forall (m :: * -> *) a b. MonadCont m => ((a -> m b) -> m a) -> m a
callCC (((Reply e s a -> m (Reply e s b)) -> m (Reply e s a))
 -> m (Reply e s a))
-> ((Reply e s a -> m (Reply e s b)) -> m (Reply e s a))
-> m (Reply e s a)
forall a b. (a -> b) -> a -> b
$ \Reply e s a -> m (Reply e s b)
c ->
      ParsecT e s m a -> State s e -> m (Reply e s a)
forall (m :: * -> *) e s a.
Monad m =>
ParsecT e s m a -> State s e -> m (Reply e s a)
runParsecT ((a -> ParsecT e s m b) -> ParsecT e s m a
f (\a
a -> (State s e -> m (Reply e s b)) -> ParsecT e s m b
forall (m :: * -> *) s e a.
Monad m =>
(State s e -> m (Reply e s a)) -> ParsecT e s m a
mkPT ((State s e -> m (Reply e s b)) -> ParsecT e s m b)
-> (State s e -> m (Reply e s b)) -> ParsecT e s m b
forall a b. (a -> b) -> a -> b
$ \State s e
s' -> Reply e s a -> m (Reply e s b)
c (State s e -> a -> Reply e s a
forall {s} {e} {a}. State s e -> a -> Reply e s a
pack State s e
s' a
a))) State s e
s
    where
      pack :: State s e -> a -> Reply e s a
pack State s e
s a
a = State s e -> Consumption -> Result s e a -> Reply e s a
forall e s a.
State s e -> Consumption -> Result s e a -> Reply e s a
Reply State s e
s Consumption
Virgin (a -> Result s e a
forall s e a. a -> Result s e a
OK a
a)

instance (Stream s, MonadError e' m) => MonadError e' (ParsecT e s m) where
  throwError :: forall a. e' -> ParsecT e s m a
throwError = m a -> ParsecT e s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ParsecT e s m a) -> (e' -> m a) -> e' -> ParsecT e s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e' -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
  ParsecT e s m a
p catchError :: forall a.
ParsecT e s m a -> (e' -> ParsecT e s m a) -> ParsecT e s m a
`catchError` e' -> ParsecT e s m a
h = (State s e -> m (Reply e s a)) -> ParsecT e s m a
forall (m :: * -> *) s e a.
Monad m =>
(State s e -> m (Reply e s a)) -> ParsecT e s m a
mkPT ((State s e -> m (Reply e s a)) -> ParsecT e s m a)
-> (State s e -> m (Reply e s a)) -> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s ->
    ParsecT e s m a -> State s e -> m (Reply e s a)
forall (m :: * -> *) e s a.
Monad m =>
ParsecT e s m a -> State s e -> m (Reply e s a)
runParsecT ParsecT e s m a
p State s e
s m (Reply e s a) -> (e' -> m (Reply e s a)) -> m (Reply e s a)
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \e'
e ->
      ParsecT e s m a -> State s e -> m (Reply e s a)
forall (m :: * -> *) e s a.
Monad m =>
ParsecT e s m a -> State s e -> m (Reply e s a)
runParsecT (e' -> ParsecT e s m a
h e'
e) State s e
s

mkPT :: Monad m => (State s e -> m (Reply e s a)) -> ParsecT e s m a
mkPT :: forall (m :: * -> *) s e a.
Monad m =>
(State s e -> m (Reply e s a)) -> ParsecT e s m a
mkPT State s e -> m (Reply e s a)
k = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
cerr a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr -> do
  (Reply State s e
s' Consumption
consumption Result s e a
result) <- State s e -> m (Reply e s a)
k State s e
s
  case Consumption
consumption of
    Consumption
Consumed ->
      case Result s e a
result of
        OK a
x -> a -> State s e -> Hints (Token s) -> m b
cok a
x State s e
s' Hints (Token s)
forall a. Monoid a => a
mempty
        Error ParseError s e
e -> ParseError s e -> State s e -> m b
cerr ParseError s e
e State s e
s'
    Consumption
Virgin ->
      case Result s e a
result of
        OK a
x -> a -> State s e -> Hints (Token s) -> m b
eok a
x State s e
s' Hints (Token s)
forall a. Monoid a => a
mempty
        Error ParseError s e
e -> ParseError s e -> State s e -> m b
eerr ParseError s e
e State s e
s'

-- | 'mzero' is a parser that __fails__ without consuming input.
--
-- __Note__: strictly speaking, this instance is unlawful. The right
-- identity law does not hold, e.g. in general this is not true:
--
-- > v >> mzero = mero
--
-- However the following holds:
--
-- > try v >> mzero = mzero
instance (Ord e, Stream s) => MonadPlus (ParsecT e s m) where
  mzero :: forall a. ParsecT e s m a
mzero = ParsecT e s m a
forall e s (m :: * -> *) a. ParsecT e s m a
pZero
  mplus :: forall a. ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
mplus = ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
forall e s (m :: * -> *) a.
(Ord e, Stream s) =>
ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
pPlus

pZero :: ParsecT e s m a
pZero :: forall e s (m :: * -> *) a. ParsecT e s m a
pZero = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \s :: State s e
s@(State s
_ Int
o PosState s
_ [ParseError s e]
_) a -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
_ a -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
eerr ->
  ParseError s e -> State s e -> m b
eerr (Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
forall s e.
Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
TrivialError Int
o Maybe (ErrorItem (Token s))
forall a. Maybe a
Nothing Set (ErrorItem (Token s))
forall a. Set a
E.empty) State s e
s
{-# INLINE pZero #-}

pPlus ::
  (Ord e, Stream s) =>
  ParsecT e s m a ->
  ParsecT e s m a ->
  ParsecT e s m a
pPlus :: forall e s (m :: * -> *) a.
(Ord e, Stream s) =>
ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
pPlus ParsecT e s m a
m ParsecT e s m a
n = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
cerr a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  let meerr :: ParseError s e -> State s e -> m b
meerr ParseError s e
err State s e
ms =
        let ncerr :: ParseError s e -> State s e -> m b
ncerr ParseError s e
err' State s e
s' = ParseError s e -> State s e -> m b
cerr (ParseError s e
err' ParseError s e -> ParseError s e -> ParseError s e
forall a. Semigroup a => a -> a -> a
<> ParseError s e
err) (State s e -> State s e -> State s e
forall s e. State s e -> State s e -> State s e
longestMatch State s e
ms State s e
s')
            neok :: a -> State s e -> Hints (Token s) -> m b
neok a
x State s e
s' Hints (Token s)
hs = a -> State s e -> Hints (Token s) -> m b
eok a
x State s e
s' (Int -> ParseError s e -> Hints (Token s)
forall s e. Stream s => Int -> ParseError s e -> Hints (Token s)
toHints (State s e -> Int
forall s e. State s e -> Int
stateOffset State s e
s') ParseError s e
err Hints (Token s) -> Hints (Token s) -> Hints (Token s)
forall a. Semigroup a => a -> a -> a
<> Hints (Token s)
hs)
            neerr :: ParseError s e -> State s e -> m b
neerr ParseError s e
err' State s e
s' = ParseError s e -> State s e -> m b
eerr (ParseError s e
err' ParseError s e -> ParseError s e -> ParseError s e
forall a. Semigroup a => a -> a -> a
<> ParseError s e
err) (State s e -> State s e -> State s e
forall s e. State s e -> State s e -> State s e
longestMatch State s e
ms State s e
s')
         in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m a
n State s e
s a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
ncerr a -> State s e -> Hints (Token s) -> m b
neok ParseError s e -> State s e -> m b
neerr
   in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m a
m State s e
s a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
cerr a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
meerr
{-# INLINE pPlus #-}

-- | From two states, return the one with the greater number of processed
-- tokens. If the numbers of processed tokens are equal, prefer the second
-- state.
longestMatch :: State s e -> State s e -> State s e
longestMatch :: forall s e. State s e -> State s e -> State s e
longestMatch s1 :: State s e
s1@(State s
_ Int
o1 PosState s
_ [ParseError s e]
_) s2 :: State s e
s2@(State s
_ Int
o2 PosState s
_ [ParseError s e]
_) =
  case Int
o1 Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Int
o2 of
    Ordering
LT -> State s e
s2
    Ordering
EQ -> State s e
s2
    Ordering
GT -> State s e
s1
{-# INLINE longestMatch #-}

-- | @since 6.0.0
instance (Stream s, MonadFix m) => MonadFix (ParsecT e s m) where
  mfix :: forall a. (a -> ParsecT e s m a) -> ParsecT e s m a
mfix a -> ParsecT e s m a
f = (State s e -> m (Reply e s a)) -> ParsecT e s m a
forall (m :: * -> *) s e a.
Monad m =>
(State s e -> m (Reply e s a)) -> ParsecT e s m a
mkPT ((State s e -> m (Reply e s a)) -> ParsecT e s m a)
-> (State s e -> m (Reply e s a)) -> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s -> (Reply e s a -> m (Reply e s a)) -> m (Reply e s a)
forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
mfix ((Reply e s a -> m (Reply e s a)) -> m (Reply e s a))
-> (Reply e s a -> m (Reply e s a)) -> m (Reply e s a)
forall a b. (a -> b) -> a -> b
$ \(~(Reply State s e
_ Consumption
_ Result s e a
result)) -> do
    let a :: a
a = case Result s e a
result of
          OK a
a' -> a
a'
          Error ParseError s e
_ -> String -> a
forall a. HasCallStack => String -> a
error String
"mfix ParsecT"
    ParsecT e s m a -> State s e -> m (Reply e s a)
forall (m :: * -> *) e s a.
Monad m =>
ParsecT e s m a -> State s e -> m (Reply e s a)
runParsecT (a -> ParsecT e s m a
f a
a) State s e
s

instance Stream s => MonadTrans (ParsecT e s) where
  lift :: forall (m :: * -> *) a. Monad m => m a -> ParsecT e s m a
lift m a
amb = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s a -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
_ a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
_ ->
    m a
amb m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
a -> a -> State s e -> Hints (Token s) -> m b
eok a
a State s e
s Hints (Token s)
forall a. Monoid a => a
mempty

instance (Ord e, Stream s) => MonadParsec e s (ParsecT e s m) where
  parseError :: forall a. ParseError s e -> ParsecT e s m a
parseError = ParseError s e -> ParsecT e s m a
forall s e (m :: * -> *) a. ParseError s e -> ParsecT e s m a
pParseError
  label :: forall a. String -> ParsecT e s m a -> ParsecT e s m a
label = String -> ParsecT e s m a -> ParsecT e s m a
forall e s (m :: * -> *) a.
String -> ParsecT e s m a -> ParsecT e s m a
pLabel
  try :: forall a. ParsecT e s m a -> ParsecT e s m a
try = ParsecT e s m a -> ParsecT e s m a
forall e s (m :: * -> *) a. ParsecT e s m a -> ParsecT e s m a
pTry
  lookAhead :: forall a. ParsecT e s m a -> ParsecT e s m a
lookAhead = ParsecT e s m a -> ParsecT e s m a
forall e s (m :: * -> *) a. ParsecT e s m a -> ParsecT e s m a
pLookAhead
  notFollowedBy :: forall a. ParsecT e s m a -> ParsecT e s m ()
notFollowedBy = ParsecT e s m a -> ParsecT e s m ()
forall s e (m :: * -> *) a.
Stream s =>
ParsecT e s m a -> ParsecT e s m ()
pNotFollowedBy
  withRecovery :: forall a.
(ParseError s e -> ParsecT e s m a)
-> ParsecT e s m a -> ParsecT e s m a
withRecovery = (ParseError s e -> ParsecT e s m a)
-> ParsecT e s m a -> ParsecT e s m a
forall s e (m :: * -> *) a.
Stream s =>
(ParseError s e -> ParsecT e s m a)
-> ParsecT e s m a -> ParsecT e s m a
pWithRecovery
  observing :: forall a.
ParsecT e s m a -> ParsecT e s m (Either (ParseError s e) a)
observing = ParsecT e s m a -> ParsecT e s m (Either (ParseError s e) a)
forall s e (m :: * -> *) a.
Stream s =>
ParsecT e s m a -> ParsecT e s m (Either (ParseError s e) a)
pObserving
  eof :: ParsecT e s m ()
eof = ParsecT e s m ()
forall e s (m :: * -> *). Stream s => ParsecT e s m ()
pEof
  token :: forall a.
(Token s -> Maybe a)
-> Set (ErrorItem (Token s)) -> ParsecT e s m a
token = (Token s -> Maybe a)
-> Set (ErrorItem (Token s)) -> ParsecT e s m a
forall e s (m :: * -> *) a.
Stream s =>
(Token s -> Maybe a)
-> Set (ErrorItem (Token s)) -> ParsecT e s m a
pToken
  tokens :: (Tokens s -> Tokens s -> Bool)
-> Tokens s -> ParsecT e s m (Tokens s)
tokens = (Tokens s -> Tokens s -> Bool)
-> Tokens s -> ParsecT e s m (Tokens s)
forall e s (m :: * -> *).
Stream s =>
(Tokens s -> Tokens s -> Bool)
-> Tokens s -> ParsecT e s m (Tokens s)
pTokens
  takeWhileP :: Maybe String -> (Token s -> Bool) -> ParsecT e s m (Tokens s)
takeWhileP = Maybe String -> (Token s -> Bool) -> ParsecT e s m (Tokens s)
forall e s (m :: * -> *).
Stream s =>
Maybe String -> (Token s -> Bool) -> ParsecT e s m (Tokens s)
pTakeWhileP
  takeWhile1P :: Maybe String -> (Token s -> Bool) -> ParsecT e s m (Tokens s)
takeWhile1P = Maybe String -> (Token s -> Bool) -> ParsecT e s m (Tokens s)
forall e s (m :: * -> *).
Stream s =>
Maybe String -> (Token s -> Bool) -> ParsecT e s m (Tokens s)
pTakeWhile1P
  takeP :: Maybe String -> Int -> ParsecT e s m (Tokens s)
takeP = Maybe String -> Int -> ParsecT e s m (Tokens s)
forall e s (m :: * -> *).
Stream s =>
Maybe String -> Int -> ParsecT e s m (Tokens s)
pTakeP
  getParserState :: ParsecT e s m (State s e)
getParserState = ParsecT e s m (State s e)
forall e s (m :: * -> *). ParsecT e s m (State s e)
pGetParserState
  updateParserState :: (State s e -> State s e) -> ParsecT e s m ()
updateParserState = (State s e -> State s e) -> ParsecT e s m ()
forall s e (m :: * -> *).
(State s e -> State s e) -> ParsecT e s m ()
pUpdateParserState

pParseError ::
  ParseError s e ->
  ParsecT e s m a
pParseError :: forall s e (m :: * -> *) a. ParseError s e -> ParsecT e s m a
pParseError ParseError s e
e = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s a -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
_ a -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
eerr -> ParseError s e -> State s e -> m b
eerr ParseError s e
e State s e
s
{-# INLINE pParseError #-}

pLabel :: String -> ParsecT e s m a -> ParsecT e s m a
pLabel :: forall e s (m :: * -> *) a.
String -> ParsecT e s m a -> ParsecT e s m a
pLabel String
l ParsecT e s m a
p = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
cerr a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  let el :: Maybe (ErrorItem (Token s))
el = NonEmpty Char -> ErrorItem (Token s)
forall t. NonEmpty Char -> ErrorItem t
Label (NonEmpty Char -> ErrorItem (Token s))
-> Maybe (NonEmpty Char) -> Maybe (ErrorItem (Token s))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Maybe (NonEmpty Char)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty String
l
      cok' :: a -> State s e -> Hints (Token s) -> m b
cok' a
x State s e
s' Hints (Token s)
hs =
        case Maybe (ErrorItem (Token s))
el of
          Maybe (ErrorItem (Token s))
Nothing -> a -> State s e -> Hints (Token s) -> m b
cok a
x State s e
s' (Hints (Token s) -> Maybe (ErrorItem (Token s)) -> Hints (Token s)
forall t. Hints t -> Maybe (ErrorItem t) -> Hints t
refreshLastHint Hints (Token s)
hs Maybe (ErrorItem (Token s))
forall a. Maybe a
Nothing)
          Just ErrorItem (Token s)
_ -> a -> State s e -> Hints (Token s) -> m b
cok a
x State s e
s' Hints (Token s)
hs
      eok' :: a -> State s e -> Hints (Token s) -> m b
eok' a
x State s e
s' Hints (Token s)
hs = a -> State s e -> Hints (Token s) -> m b
eok a
x State s e
s' (Hints (Token s) -> Maybe (ErrorItem (Token s)) -> Hints (Token s)
forall t. Hints t -> Maybe (ErrorItem t) -> Hints t
refreshLastHint Hints (Token s)
hs Maybe (ErrorItem (Token s))
el)
      eerr' :: ParseError s e -> State s e -> m b
eerr' ParseError s e
err = ParseError s e -> State s e -> m b
eerr (ParseError s e -> State s e -> m b)
-> ParseError s e -> State s e -> m b
forall a b. (a -> b) -> a -> b
$
        case ParseError s e
err of
          (TrivialError Int
pos Maybe (ErrorItem (Token s))
us Set (ErrorItem (Token s))
_) ->
            Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
forall s e.
Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
TrivialError Int
pos Maybe (ErrorItem (Token s))
us (Set (ErrorItem (Token s))
-> (ErrorItem (Token s) -> Set (ErrorItem (Token s)))
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Set (ErrorItem (Token s))
forall a. Set a
E.empty ErrorItem (Token s) -> Set (ErrorItem (Token s))
forall a. a -> Set a
E.singleton Maybe (ErrorItem (Token s))
el)
          ParseError s e
_ -> ParseError s e
err
   in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m a
p State s e
s a -> State s e -> Hints (Token s) -> m b
cok' ParseError s e -> State s e -> m b
cerr a -> State s e -> Hints (Token s) -> m b
eok' ParseError s e -> State s e -> m b
eerr'
{-# INLINE pLabel #-}

pTry :: ParsecT e s m a -> ParsecT e s m a
pTry :: forall e s (m :: * -> *) a. ParsecT e s m a -> ParsecT e s m a
pTry ParsecT e s m a
p = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
_ a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  let eerr' :: ParseError s e -> State s e -> m b
eerr' ParseError s e
err State s e
_ = ParseError s e -> State s e -> m b
eerr ParseError s e
err State s e
s
   in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m a
p State s e
s a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
eerr' a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr'
{-# INLINE pTry #-}

pLookAhead :: ParsecT e s m a -> ParsecT e s m a
pLookAhead :: forall e s (m :: * -> *) a. ParsecT e s m a -> ParsecT e s m a
pLookAhead ParsecT e s m a
p = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s a -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
cerr a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  let eok' :: a -> State s e -> Hints (Token s) -> m b
eok' a
a State s e
_ Hints (Token s)
_ = a -> State s e -> Hints (Token s) -> m b
eok a
a State s e
s Hints (Token s)
forall a. Monoid a => a
mempty
   in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m a
p State s e
s a -> State s e -> Hints (Token s) -> m b
eok' ParseError s e -> State s e -> m b
cerr a -> State s e -> Hints (Token s) -> m b
eok' ParseError s e -> State s e -> m b
eerr
{-# INLINE pLookAhead #-}

pNotFollowedBy :: Stream s => ParsecT e s m a -> ParsecT e s m ()
pNotFollowedBy :: forall s e (m :: * -> *) a.
Stream s =>
ParsecT e s m a -> ParsecT e s m ()
pNotFollowedBy ParsecT e s m a
p = (forall b.
 State s e
 -> (() -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (() -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m ()
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (() -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (() -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m ())
-> (forall b.
    State s e
    -> (() -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (() -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m ()
forall a b. (a -> b) -> a -> b
$ \s :: State s e
s@(State s
input Int
o PosState s
_ [ParseError s e]
_) () -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
_ () -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  let what :: ErrorItem (Token s)
what = ErrorItem (Token s)
-> ((Token s, s) -> ErrorItem (Token s))
-> Maybe (Token s, s)
-> ErrorItem (Token s)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ErrorItem (Token s)
forall t. ErrorItem t
EndOfInput (NonEmpty (Token s) -> ErrorItem (Token s)
forall t. NonEmpty t -> ErrorItem t
Tokens (NonEmpty (Token s) -> ErrorItem (Token s))
-> ((Token s, s) -> NonEmpty (Token s))
-> (Token s, s)
-> ErrorItem (Token s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Token s -> NonEmpty (Token s)
forall a. a -> NonEmpty a
nes (Token s -> NonEmpty (Token s))
-> ((Token s, s) -> Token s) -> (Token s, s) -> NonEmpty (Token s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Token s, s) -> Token s
forall a b. (a, b) -> a
fst) (s -> Maybe (Token s, s)
forall s. Stream s => s -> Maybe (Token s, s)
take1_ s
input)
      unexpect :: ErrorItem (Token s) -> ParseError s e
unexpect ErrorItem (Token s)
u = Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
forall s e.
Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
TrivialError Int
o (ErrorItem (Token s) -> Maybe (ErrorItem (Token s))
forall (f :: * -> *) a. Applicative f => a -> f a
pure ErrorItem (Token s)
u) Set (ErrorItem (Token s))
forall a. Set a
E.empty
      cok' :: a -> State s e -> Hints (Token s) -> m b
cok' a
_ State s e
_ Hints (Token s)
_ = ParseError s e -> State s e -> m b
eerr (ErrorItem (Token s) -> ParseError s e
unexpect ErrorItem (Token s)
what) State s e
s
      cerr' :: ParseError s e -> State s e -> m b
cerr' ParseError s e
_ State s e
_ = () -> State s e -> Hints (Token s) -> m b
eok () State s e
s Hints (Token s)
forall a. Monoid a => a
mempty
      eok' :: a -> State s e -> Hints (Token s) -> m b
eok' a
_ State s e
_ Hints (Token s)
_ = ParseError s e -> State s e -> m b
eerr (ErrorItem (Token s) -> ParseError s e
unexpect ErrorItem (Token s)
what) State s e
s
      eerr' :: ParseError s e -> State s e -> m b
eerr' ParseError s e
_ State s e
_ = () -> State s e -> Hints (Token s) -> m b
eok () State s e
s Hints (Token s)
forall a. Monoid a => a
mempty
   in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m a
p State s e
s a -> State s e -> Hints (Token s) -> m b
cok' ParseError s e -> State s e -> m b
cerr' a -> State s e -> Hints (Token s) -> m b
eok' ParseError s e -> State s e -> m b
eerr'
{-# INLINE pNotFollowedBy #-}

pWithRecovery ::
  Stream s =>
  (ParseError s e -> ParsecT e s m a) ->
  ParsecT e s m a ->
  ParsecT e s m a
pWithRecovery :: forall s e (m :: * -> *) a.
Stream s =>
(ParseError s e -> ParsecT e s m a)
-> ParsecT e s m a -> ParsecT e s m a
pWithRecovery ParseError s e -> ParsecT e s m a
r ParsecT e s m a
p = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \State s e
s a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
cerr a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  let mcerr :: ParseError s e -> State s e -> m b
mcerr ParseError s e
err State s e
ms =
        let rcok :: a -> State s e -> Hints (Token s) -> m b
rcok a
x State s e
s' Hints (Token s)
_ = a -> State s e -> Hints (Token s) -> m b
cok a
x State s e
s' Hints (Token s)
forall a. Monoid a => a
mempty
            rcerr :: ParseError s e -> State s e -> m b
rcerr ParseError s e
_ State s e
_ = ParseError s e -> State s e -> m b
cerr ParseError s e
err State s e
ms
            reok :: a -> State s e -> Hints (Token s) -> m b
reok a
x State s e
s' Hints (Token s)
_ = a -> State s e -> Hints (Token s) -> m b
eok a
x State s e
s' (Int -> ParseError s e -> Hints (Token s)
forall s e. Stream s => Int -> ParseError s e -> Hints (Token s)
toHints (State s e -> Int
forall s e. State s e -> Int
stateOffset State s e
s') ParseError s e
err)
            reerr :: ParseError s e -> State s e -> m b
reerr ParseError s e
_ State s e
_ = ParseError s e -> State s e -> m b
cerr ParseError s e
err State s e
ms
         in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser (ParseError s e -> ParsecT e s m a
r ParseError s e
err) State s e
ms a -> State s e -> Hints (Token s) -> m b
rcok ParseError s e -> State s e -> m b
rcerr a -> State s e -> Hints (Token s) -> m b
reok ParseError s e -> State s e -> m b
reerr
      meerr :: ParseError s e -> State s e -> m b
meerr ParseError s e
err State s e
ms =
        let rcok :: a -> State s e -> Hints (Token s) -> m b
rcok a
x State s e
s' Hints (Token s)
_ = a -> State s e -> Hints (Token s) -> m b
cok a
x State s e
s' (Int -> ParseError s e -> Hints (Token s)
forall s e. Stream s => Int -> ParseError s e -> Hints (Token s)
toHints (State s e -> Int
forall s e. State s e -> Int
stateOffset State s e
s') ParseError s e
err)
            rcerr :: ParseError s e -> State s e -> m b
rcerr ParseError s e
_ State s e
_ = ParseError s e -> State s e -> m b
eerr ParseError s e
err State s e
ms
            reok :: a -> State s e -> Hints (Token s) -> m b
reok a
x State s e
s' Hints (Token s)
_ = a -> State s e -> Hints (Token s) -> m b
eok a
x State s e
s' (Int -> ParseError s e -> Hints (Token s)
forall s e. Stream s => Int -> ParseError s e -> Hints (Token s)
toHints (State s e -> Int
forall s e. State s e -> Int
stateOffset State s e
s') ParseError s e
err)
            reerr :: ParseError s e -> State s e -> m b
reerr ParseError s e
_ State s e
_ = ParseError s e -> State s e -> m b
eerr ParseError s e
err State s e
ms
         in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser (ParseError s e -> ParsecT e s m a
r ParseError s e
err) State s e
ms a -> State s e -> Hints (Token s) -> m b
rcok ParseError s e -> State s e -> m b
rcerr a -> State s e -> Hints (Token s) -> m b
reok ParseError s e -> State s e -> m b
reerr
   in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m a
p State s e
s a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
mcerr a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
meerr
{-# INLINE pWithRecovery #-}

pObserving ::
  Stream s =>
  ParsecT e s m a ->
  ParsecT e s m (Either (ParseError s e) a)
pObserving :: forall s e (m :: * -> *) a.
Stream s =>
ParsecT e s m a -> ParsecT e s m (Either (ParseError s e) a)
pObserving ParsecT e s m a
p = (forall b.
 State s e
 -> (Either (ParseError s e) a
     -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (Either (ParseError s e) a
     -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m (Either (ParseError s e) a)
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (Either (ParseError s e) a
      -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (Either (ParseError s e) a
      -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m (Either (ParseError s e) a))
-> (forall b.
    State s e
    -> (Either (ParseError s e) a
        -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (Either (ParseError s e) a
        -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m (Either (ParseError s e) a)
forall a b. (a -> b) -> a -> b
$ \State s e
s Either (ParseError s e) a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
_ Either (ParseError s e) a -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
_ ->
  let cerr' :: ParseError s e -> State s e -> m b
cerr' ParseError s e
err State s e
s' = Either (ParseError s e) a -> State s e -> Hints (Token s) -> m b
cok (ParseError s e -> Either (ParseError s e) a
forall a b. a -> Either a b
Left ParseError s e
err) State s e
s' Hints (Token s)
forall a. Monoid a => a
mempty
      eerr' :: ParseError s e -> State s e -> m b
eerr' ParseError s e
err State s e
s' = Either (ParseError s e) a -> State s e -> Hints (Token s) -> m b
eok (ParseError s e -> Either (ParseError s e) a
forall a b. a -> Either a b
Left ParseError s e
err) State s e
s' (Int -> ParseError s e -> Hints (Token s)
forall s e. Stream s => Int -> ParseError s e -> Hints (Token s)
toHints (State s e -> Int
forall s e. State s e -> Int
stateOffset State s e
s') ParseError s e
err)
   in ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
forall e s (m :: * -> *) a.
ParsecT e s m a
-> forall b.
   State s e
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> (a -> State s e -> Hints (Token s) -> m b)
   -> (ParseError s e -> State s e -> m b)
   -> m b
unParser ParsecT e s m a
p State s e
s (Either (ParseError s e) a -> State s e -> Hints (Token s) -> m b
cok (Either (ParseError s e) a -> State s e -> Hints (Token s) -> m b)
-> (a -> Either (ParseError s e) a)
-> a
-> State s e
-> Hints (Token s)
-> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either (ParseError s e) a
forall a b. b -> Either a b
Right) ParseError s e -> State s e -> m b
cerr' (Either (ParseError s e) a -> State s e -> Hints (Token s) -> m b
eok (Either (ParseError s e) a -> State s e -> Hints (Token s) -> m b)
-> (a -> Either (ParseError s e) a)
-> a
-> State s e
-> Hints (Token s)
-> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either (ParseError s e) a
forall a b. b -> Either a b
Right) ParseError s e -> State s e -> m b
eerr'
{-# INLINE pObserving #-}

pEof :: forall e s m. Stream s => ParsecT e s m ()
pEof :: forall e s (m :: * -> *). Stream s => ParsecT e s m ()
pEof = (forall b.
 State s e
 -> (() -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (() -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m ()
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (() -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (() -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m ())
-> (forall b.
    State s e
    -> (() -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (() -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m ()
forall a b. (a -> b) -> a -> b
$ \s :: State s e
s@(State s
input Int
o PosState s
pst [ParseError s e]
de) () -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
_ () -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  case s -> Maybe (Token s, s)
forall s. Stream s => s -> Maybe (Token s, s)
take1_ s
input of
    Maybe (Token s, s)
Nothing -> () -> State s e -> Hints (Token s) -> m b
eok () State s e
s Hints (Token s)
forall a. Monoid a => a
mempty
    Just (Token s
x, s
_) ->
      let us :: Maybe (ErrorItem (Token s))
us = (ErrorItem (Token s) -> Maybe (ErrorItem (Token s))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ErrorItem (Token s) -> Maybe (ErrorItem (Token s)))
-> (Token s -> ErrorItem (Token s))
-> Token s
-> Maybe (ErrorItem (Token s))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (Token s) -> ErrorItem (Token s)
forall t. NonEmpty t -> ErrorItem t
Tokens (NonEmpty (Token s) -> ErrorItem (Token s))
-> (Token s -> NonEmpty (Token s))
-> Token s
-> ErrorItem (Token s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Token s -> NonEmpty (Token s)
forall a. a -> NonEmpty a
nes) Token s
x
          ps :: Set (ErrorItem t)
ps = ErrorItem t -> Set (ErrorItem t)
forall a. a -> Set a
E.singleton ErrorItem t
forall t. ErrorItem t
EndOfInput
       in ParseError s e -> State s e -> m b
eerr
            (Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
forall s e.
Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
TrivialError Int
o Maybe (ErrorItem (Token s))
us Set (ErrorItem (Token s))
forall {t}. Set (ErrorItem t)
ps)
            (s -> Int -> PosState s -> [ParseError s e] -> State s e
forall s e. s -> Int -> PosState s -> [ParseError s e] -> State s e
State s
input Int
o PosState s
pst [ParseError s e]
de)
{-# INLINE pEof #-}

pToken ::
  forall e s m a.
  Stream s =>
  (Token s -> Maybe a) ->
  Set (ErrorItem (Token s)) ->
  ParsecT e s m a
pToken :: forall e s (m :: * -> *) a.
Stream s =>
(Token s -> Maybe a)
-> Set (ErrorItem (Token s)) -> ParsecT e s m a
pToken Token s -> Maybe a
test Set (ErrorItem (Token s))
ps = (forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (a -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m a)
-> (forall b.
    State s e
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (a -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m a
forall a b. (a -> b) -> a -> b
$ \s :: State s e
s@(State s
input Int
o PosState s
pst [ParseError s e]
de) a -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
_ a -> State s e -> Hints (Token s) -> m b
_ ParseError s e -> State s e -> m b
eerr ->
  case s -> Maybe (Token s, s)
forall s. Stream s => s -> Maybe (Token s, s)
take1_ s
input of
    Maybe (Token s, s)
Nothing ->
      let us :: Maybe (ErrorItem t)
us = ErrorItem t -> Maybe (ErrorItem t)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ErrorItem t
forall t. ErrorItem t
EndOfInput
       in ParseError s e -> State s e -> m b
eerr (Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
forall s e.
Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
TrivialError Int
o Maybe (ErrorItem (Token s))
forall {t}. Maybe (ErrorItem t)
us Set (ErrorItem (Token s))
ps) State s e
s
    Just (Token s
c, s
cs) ->
      case Token s -> Maybe a
test Token s
c of
        Maybe a
Nothing ->
          let us :: Maybe (ErrorItem (Token s))
us = (ErrorItem (Token s) -> Maybe (ErrorItem (Token s))
forall a. a -> Maybe a
Just (ErrorItem (Token s) -> Maybe (ErrorItem (Token s)))
-> (Token s -> ErrorItem (Token s))
-> Token s
-> Maybe (ErrorItem (Token s))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (Token s) -> ErrorItem (Token s)
forall t. NonEmpty t -> ErrorItem t
Tokens (NonEmpty (Token s) -> ErrorItem (Token s))
-> (Token s -> NonEmpty (Token s))
-> Token s
-> ErrorItem (Token s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Token s -> NonEmpty (Token s)
forall a. a -> NonEmpty a
nes) Token s
c
           in ParseError s e -> State s e -> m b
eerr
                (Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
forall s e.
Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
TrivialError Int
o Maybe (ErrorItem (Token s))
us Set (ErrorItem (Token s))
ps)
                (s -> Int -> PosState s -> [ParseError s e] -> State s e
forall s e. s -> Int -> PosState s -> [ParseError s e] -> State s e
State s
input Int
o PosState s
pst [ParseError s e]
de)
        Just a
x ->
          a -> State s e -> Hints (Token s) -> m b
cok a
x (s -> Int -> PosState s -> [ParseError s e] -> State s e
forall s e. s -> Int -> PosState s -> [ParseError s e] -> State s e
State s
cs (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) PosState s
pst [ParseError s e]
de) Hints (Token s)
forall a. Monoid a => a
mempty
{-# INLINE pToken #-}

pTokens ::
  forall e s m.
  Stream s =>
  (Tokens s -> Tokens s -> Bool) ->
  Tokens s ->
  ParsecT e s m (Tokens s)
pTokens :: forall e s (m :: * -> *).
Stream s =>
(Tokens s -> Tokens s -> Bool)
-> Tokens s -> ParsecT e s m (Tokens s)
pTokens Tokens s -> Tokens s -> Bool
f Tokens s
tts = (forall b.
 State s e
 -> (Tokens s -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (Tokens s -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m (Tokens s)
forall e s (m :: * -> *) a.
(forall b.
 State s e
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> (a -> State s e -> Hints (Token s) -> m b)
 -> (ParseError s e -> State s e -> m b)
 -> m b)
-> ParsecT e s m a
ParsecT ((forall b.
  State s e
  -> (Tokens s -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> (Tokens s -> State s e -> Hints (Token s) -> m b)
  -> (ParseError s e -> State s e -> m b)
  -> m b)
 -> ParsecT e s m (Tokens s))
-> (forall b.
    State s e
    -> (Tokens s -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> (Tokens s -> State s e -> Hints (Token s) -> m b)
    -> (ParseError s e -> State s e -> m b)
    -> m b)
-> ParsecT e s m (Tokens s)
forall a b. (a -> b) -> a -> b
$ \s :: State s e
s@(State s
input Int
o PosState s
pst [ParseError s e]
de) Tokens s -> State s e -> Hints (Token s) -> m b
cok ParseError s e -> State s e -> m b
_ Tokens s -> State s e -> Hints (Token s) -> m b
eok ParseError s e -> State s e -> m b
eerr ->
  let pxy :: Proxy s
pxy = Proxy s
forall {k} (t :: k). Proxy t
Proxy :: Proxy s
      unexpect :: Int -> ErrorItem (Token s) -> ParseError s e
unexpect Int
pos' ErrorItem (Token s)
u =
        let us :: Maybe (ErrorItem (Token s))
us = ErrorItem (Token s) -> Maybe (ErrorItem (Token s))
forall (f :: * -> *) a. Applicative f => a -> f a
pure ErrorItem (Token s)
u
            ps :: Set (ErrorItem (Token s))
ps = (ErrorItem (Token s) -> Set (ErrorItem (Token s))
forall a. a -> Set a
E.singleton (ErrorItem (Token s) -> Set (ErrorItem (Token s)))
-> (Tokens s -> ErrorItem (Token s))
-> Tokens s
-> Set (ErrorItem (Token s))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (Token s) -> ErrorItem (Token s)
forall t. NonEmpty t -> ErrorItem t
Tokens (NonEmpty (Token s) -> ErrorItem (Token s))
-> (Tokens s -> NonEmpty (Token s))
-> Tokens s
-> ErrorItem (Token s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Token s] -> NonEmpty (Token s)
forall a. [a] -> NonEmpty a
NE.fromList ([Token s] -> NonEmpty (Token s))
-> (Tokens s -> [Token s]) -> Tokens s -> NonEmpty (Token s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy s -> Tokens s -> [Token s]
forall s. Stream s => Proxy s -> Tokens s -> [Token s]
chunkToTokens Proxy s
pxy) Tokens s
tts
         in Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
forall s e.
Int
-> Maybe (ErrorItem (Token s))
-> Set (ErrorItem (Token s))
-> ParseError s e
TrivialError Int
pos' Maybe (ErrorItem (Token s))
us Set (ErrorItem (Token s))
ps
      le