{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fspec-constr -fspec-constr-count=8 #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Text.Parser.Char
-- Copyright   :  (c) Edward Kmett 2011
-- License     :  BSD3
--
-- Maintainer  :  ekmett@gmail.com
-- Stability   :  experimental
-- Portability :  non-portable
--
-- Parsers for character streams
--
-----------------------------------------------------------------------------
module Text.Parser.Char
  (
  -- * Combinators
    oneOf        -- :: CharParsing m => [Char] -> m Char
  , noneOf       -- :: CharParsing m => [Char] -> m Char
  , oneOfSet     -- :: CharParsing m => CharSet -> m Char
  , noneOfSet    -- :: CharParsing m => CharSet -> m Char
  , spaces       -- :: CharParsing m => m ()
  , space        -- :: CharParsing m => m Char
  , newline      -- :: CharParsing m => m Char
  , tab          -- :: CharParsing m => m Char
  , upper        -- :: CharParsing m => m Char
  , lower        -- :: CharParsing m => m Char
  , alphaNum     -- :: CharParsing m => m Char
  , letter       -- :: CharParsing m => m Char
  , digit        -- :: CharParsing m => m Char
  , hexDigit     -- :: CharParsing m => m Char
  , octDigit     -- :: CharParsing m => m Char
  , satisfyRange -- :: CharParsing m => Char -> Char -> m Char
  -- * Class
  , CharParsing(..)
  ) where

import Control.Monad.Trans.Class
import Control.Monad.Trans.State.Lazy as Lazy
import Control.Monad.Trans.State.Strict as Strict
import Control.Monad.Trans.Writer.Lazy as Lazy
import Control.Monad.Trans.Writer.Strict as Strict
import Control.Monad.Trans.RWS.Lazy as Lazy
import Control.Monad.Trans.RWS.Strict as Strict
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Identity
import Control.Monad (MonadPlus(..))
import Data.Char
import Data.CharSet (CharSet(..))
import qualified Data.CharSet as CharSet
import Data.Foldable
import qualified Data.IntSet as IntSet
import qualified Data.Text as Text
import Data.Text (Text)
import qualified Text.ParserCombinators.ReadP as ReadP
import Text.Parser.Combinators

#ifdef MIN_VERSION_parsec
import qualified Text.Parsec as Parsec
#endif

#ifdef MIN_VERSION_attoparsec
import qualified Data.Attoparsec.Types as Att
import qualified Data.Attoparsec.Combinator as Att
#endif

-- | @oneOf cs@ succeeds if the current character is in the supplied
-- list of characters @cs@. Returns the parsed character. See also
-- 'satisfy'.
--
-- >   vowel  = oneOf "aeiou"
oneOf :: CharParsing m => [Char] -> m Char
oneOf :: forall (m :: * -> *). CharParsing m => [Char] -> m Char
oneOf [Char]
xs = CharSet -> m Char
forall (m :: * -> *). CharParsing m => CharSet -> m Char
oneOfSet ([Char] -> CharSet
CharSet.fromList [Char]
xs)
{-# INLINE oneOf #-}
{-# ANN oneOf "HLint: ignore Use String" #-}

-- | As the dual of 'oneOf', @noneOf cs@ succeeds if the current
-- character is /not/ in the supplied list of characters @cs@. Returns the
-- parsed character.
--
-- >  consonant = noneOf "aeiou"
noneOf :: CharParsing m => [Char] -> m Char
noneOf :: forall (m :: * -> *). CharParsing m => [Char] -> m Char
noneOf [Char]
xs = CharSet -> m Char
forall (m :: * -> *). CharParsing m => CharSet -> m Char
noneOfSet ([Char] -> CharSet
CharSet.fromList [Char]
xs)
{-# INLINE noneOf #-}
{-# ANN noneOf "HLint: ignore Use String" #-}

-- | @oneOfSet cs@ succeeds if the current character is in the supplied
-- set of characters @cs@. Returns the parsed character. See also
-- 'satisfy'.
--
-- >   vowel  = oneOf "aeiou"
oneOfSet :: CharParsing m => CharSet -> m Char
oneOfSet :: forall (m :: * -> *). CharParsing m => CharSet -> m Char
oneOfSet (CharSet Bool
True ByteSet
_ IntSet
is)  = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (\Char
c -> Key -> IntSet -> Bool
IntSet.member (Char -> Key
forall a. Enum a => a -> Key
fromEnum Char
c) IntSet
is)
oneOfSet (CharSet Bool
False ByteSet
_ IntSet
is) = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (\Char
c -> Bool -> Bool
not (Key -> IntSet -> Bool
IntSet.member (Char -> Key
forall a. Enum a => a -> Key
fromEnum Char
c) IntSet
is))
{-# INLINE oneOfSet #-}

-- | As the dual of 'oneOf', @noneOf cs@ succeeds if the current
-- character is /not/ in the supplied list of characters @cs@. Returns the
-- parsed character.
--
-- >  consonant = noneOf "aeiou"
noneOfSet :: CharParsing m => CharSet -> m Char
noneOfSet :: forall (m :: * -> *). CharParsing m => CharSet -> m Char
noneOfSet CharSet
s = CharSet -> m Char
forall (m :: * -> *). CharParsing m => CharSet -> m Char
oneOfSet (CharSet -> CharSet
CharSet.complement CharSet
s)
{-# INLINE noneOfSet #-}

-- | Skips /zero/ or more white space characters. See also 'skipMany'.
spaces :: CharParsing m => m ()
spaces :: forall (m :: * -> *). CharParsing m => m ()
spaces = m Char -> m ()
forall a. m a -> m ()
forall (m :: * -> *) a. Parsing m => m a -> m ()
skipMany m Char
forall (m :: * -> *). CharParsing m => m Char
space m () -> [Char] -> m ()
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"white space"
{-# INLINE spaces #-}

-- | Parses a white space character (any character which satisfies 'isSpace')
-- Returns the parsed character.
space :: CharParsing m => m Char
space :: forall (m :: * -> *). CharParsing m => m Char
space = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy Char -> Bool
isSpace m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"space"
{-# INLINE space #-}

-- | Parses a newline character (\'\\n\'). Returns a newline character.
newline :: CharParsing m => m Char
newline :: forall (m :: * -> *). CharParsing m => m Char
newline = Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\n' m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"new-line"
{-# INLINE newline #-}

-- | Parses a tab character (\'\\t\'). Returns a tab character.
tab :: CharParsing m => m Char
tab :: forall (m :: * -> *). CharParsing m => m Char
tab = Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'\t' m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"tab"
{-# INLINE tab #-}

-- | Parses an upper case letter. Returns the parsed character.
upper :: CharParsing m => m Char
upper :: forall (m :: * -> *). CharParsing m => m Char
upper = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy Char -> Bool
isUpper m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"uppercase letter"
{-# INLINE upper #-}

-- | Parses a lower case character. Returns the parsed character.
lower :: CharParsing m => m Char
lower :: forall (m :: * -> *). CharParsing m => m Char
lower = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy Char -> Bool
isLower m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"lowercase letter"
{-# INLINE lower #-}

-- | Parses a letter or digit. Returns the parsed character.
alphaNum :: CharParsing m => m Char
alphaNum :: forall (m :: * -> *). CharParsing m => m Char
alphaNum = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy Char -> Bool
isAlphaNum m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"letter or digit"
{-# INLINE alphaNum #-}

-- | Parses a letter (an upper case or lower case character). Returns the
-- parsed character.
letter :: CharParsing m => m Char
letter :: forall (m :: * -> *). CharParsing m => m Char
letter = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy Char -> Bool
isAlpha m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"letter"
{-# INLINE letter #-}

-- | Parses a digit. Returns the parsed character.
digit :: CharParsing m => m Char
digit :: forall (m :: * -> *). CharParsing m => m Char
digit = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy Char -> Bool
isDigit m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"digit"
{-# INLINE digit #-}

-- | Parses a hexadecimal digit (a digit or a letter between \'a\' and
-- \'f\' or \'A\' and \'F\'). Returns the parsed character.
hexDigit :: CharParsing m => m Char
hexDigit :: forall (m :: * -> *). CharParsing m => m Char
hexDigit = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy Char -> Bool
isHexDigit m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"hexadecimal digit"
{-# INLINE hexDigit #-}

-- | Parses an octal digit (a character between \'0\' and \'7\'). Returns
-- the parsed character.
octDigit :: CharParsing m => m Char
octDigit :: forall (m :: * -> *). CharParsing m => m Char
octDigit = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy Char -> Bool
isOctDigit m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char]
"octal digit"
{-# INLINE octDigit #-}

satisfyRange :: CharParsing m => Char -> Char -> m Char
satisfyRange :: forall (m :: * -> *). CharParsing m => Char -> Char -> m Char
satisfyRange Char
a Char
z = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (\Char
c -> Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
a Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
z)
{-# INLINE satisfyRange #-}

-- | Additional functionality needed to parse character streams.
class Parsing m => CharParsing m where
  -- | Parse a single character of the input, with UTF-8 decoding
  satisfy :: (Char -> Bool) -> m Char
  default satisfy :: (MonadTrans t, CharParsing n, Monad n, m ~ t n) =>
                     (Char -> Bool) ->
                     m Char
  satisfy = n Char -> m Char
n Char -> t n Char
forall (m :: * -> *) a. Monad m => m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (n Char -> m Char)
-> ((Char -> Bool) -> n Char) -> (Char -> Bool) -> m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> n Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy

  -- | @char c@ parses a single character @c@. Returns the parsed
  -- character (i.e. @c@).
  --
  -- /e.g./
  --
  -- @semiColon = 'char' ';'@
  char :: Char -> m Char
  char Char
c = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==) m Char -> [Char] -> m Char
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char] -> [Char]
forall a. Show a => a -> [Char]
show [Char
c]
  {-# INLINE char #-}

  -- | @notChar c@ parses any single character other than @c@. Returns the parsed
  -- character.
  notChar :: Char -> m Char
  notChar Char
c = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=)
  {-# INLINE notChar #-}

  -- | This parser succeeds for any character. Returns the parsed character.
  anyChar :: m Char
  anyChar = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy (Bool -> Char -> Bool
forall a b. a -> b -> a
const Bool
True)
  {-# INLINE anyChar #-}

  -- | @string s@ parses a sequence of characters given by @s@. Returns
  -- the parsed string (i.e. @s@).
  --
  -- >  divOrMod    =   string "div"
  -- >              <|> string "mod"
  string :: String -> m String
  string [Char]
s = [Char]
s [Char] -> m () -> m [Char]
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
try ((Char -> m Char) -> [Char] -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char [Char]
s) m [Char] -> [Char] -> m [Char]
forall a. m a -> [Char] -> m a
forall (m :: * -> *) a. Parsing m => m a -> [Char] -> m a
<?> [Char] -> [Char]
forall a. Show a => a -> [Char]
show [Char]
s
  {-# INLINE string #-}

  -- | @text t@ parses a sequence of characters determined by the text @t@ Returns
  -- the parsed text fragment (i.e. @t@).
  --
  -- Using @OverloadedStrings@:
  --
  -- >  divOrMod    =   text "div"
  -- >              <|> text "mod"
  text :: Text -> m Text
  text Text
t = Text
t Text -> m [Char] -> m Text
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string (Text -> [Char]
Text.unpack Text
t)
  {-# INLINE text #-}

instance (CharParsing m, MonadPlus m) => CharParsing (Lazy.StateT s m) where
  satisfy :: (Char -> Bool) -> StateT s m Char
satisfy = m Char -> StateT s m Char
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> StateT s m Char)
-> ((Char -> Bool) -> m Char) -> (Char -> Bool) -> StateT s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy
  {-# INLINE satisfy #-}
  char :: Char -> StateT s m Char
char    = m Char -> StateT s m Char
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> StateT s m Char)
-> (Char -> m Char) -> Char -> StateT s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char
  {-# INLINE char #-}
  notChar :: Char -> StateT s m Char
notChar = m Char -> StateT s m Char
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> StateT s m Char)
-> (Char -> m Char) -> Char -> StateT s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
notChar
  {-# INLINE notChar #-}
  anyChar :: StateT s m Char
anyChar = m Char -> StateT s m Char
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
forall (m :: * -> *). CharParsing m => m Char
anyChar
  {-# INLINE anyChar #-}
  string :: [Char] -> StateT s m [Char]
string  = m [Char] -> StateT s m [Char]
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m [Char] -> StateT s m [Char])
-> ([Char] -> m [Char]) -> [Char] -> StateT s m [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string
  {-# INLINE string #-}
  text :: Text -> StateT s m Text
text = m Text -> StateT s m Text
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Text -> StateT s m Text)
-> (Text -> m Text) -> Text -> StateT s m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m Text
forall (m :: * -> *). CharParsing m => Text -> m Text
text
  {-# INLINE text #-}

instance (CharParsing m, MonadPlus m) => CharParsing (Strict.StateT s m) where
  satisfy :: (Char -> Bool) -> StateT s m Char
satisfy = m Char -> StateT s m Char
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> StateT s m Char)
-> ((Char -> Bool) -> m Char) -> (Char -> Bool) -> StateT s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy
  {-# INLINE satisfy #-}
  char :: Char -> StateT s m Char
char    = m Char -> StateT s m Char
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> StateT s m Char)
-> (Char -> m Char) -> Char -> StateT s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char
  {-# INLINE char #-}
  notChar :: Char -> StateT s m Char
notChar = m Char -> StateT s m Char
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> StateT s m Char)
-> (Char -> m Char) -> Char -> StateT s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
notChar
  {-# INLINE notChar #-}
  anyChar :: StateT s m Char
anyChar = m Char -> StateT s m Char
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
forall (m :: * -> *). CharParsing m => m Char
anyChar
  {-# INLINE anyChar #-}
  string :: [Char] -> StateT s m [Char]
string  = m [Char] -> StateT s m [Char]
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m [Char] -> StateT s m [Char])
-> ([Char] -> m [Char]) -> [Char] -> StateT s m [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string
  {-# INLINE string #-}
  text :: Text -> StateT s m Text
text = m Text -> StateT s m Text
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Text -> StateT s m Text)
-> (Text -> m Text) -> Text -> StateT s m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m Text
forall (m :: * -> *). CharParsing m => Text -> m Text
text
  {-# INLINE text #-}

instance (CharParsing m, MonadPlus m) => CharParsing (ReaderT e m) where
  satisfy :: (Char -> Bool) -> ReaderT e m Char
satisfy = m Char -> ReaderT e m Char
forall (m :: * -> *) a. Monad m => m a -> ReaderT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> ReaderT e m Char)
-> ((Char -> Bool) -> m Char) -> (Char -> Bool) -> ReaderT e m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy
  {-# INLINE satisfy #-}
  char :: Char -> ReaderT e m Char
char    = m Char -> ReaderT e m Char
forall (m :: * -> *) a. Monad m => m a -> ReaderT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> ReaderT e m Char)
-> (Char -> m Char) -> Char -> ReaderT e m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char
  {-# INLINE char #-}
  notChar :: Char -> ReaderT e m Char
notChar = m Char -> ReaderT e m Char
forall (m :: * -> *) a. Monad m => m a -> ReaderT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> ReaderT e m Char)
-> (Char -> m Char) -> Char -> ReaderT e m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
notChar
  {-# INLINE notChar #-}
  anyChar :: ReaderT e m Char
anyChar = m Char -> ReaderT e m Char
forall (m :: * -> *) a. Monad m => m a -> ReaderT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
forall (m :: * -> *). CharParsing m => m Char
anyChar
  {-# INLINE anyChar #-}
  string :: [Char] -> ReaderT e m [Char]
string  = m [Char] -> ReaderT e m [Char]
forall (m :: * -> *) a. Monad m => m a -> ReaderT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m [Char] -> ReaderT e m [Char])
-> ([Char] -> m [Char]) -> [Char] -> ReaderT e m [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string
  {-# INLINE string #-}
  text :: Text -> ReaderT e m Text
text = m Text -> ReaderT e m Text
forall (m :: * -> *) a. Monad m => m a -> ReaderT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Text -> ReaderT e m Text)
-> (Text -> m Text) -> Text -> ReaderT e m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m Text
forall (m :: * -> *). CharParsing m => Text -> m Text
text
  {-# INLINE text #-}

instance (CharParsing m, MonadPlus m, Monoid w) => CharParsing (Strict.WriterT w m) where
  satisfy :: (Char -> Bool) -> WriterT w m Char
satisfy = m Char -> WriterT w m Char
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> WriterT w m Char)
-> ((Char -> Bool) -> m Char) -> (Char -> Bool) -> WriterT w m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy
  {-# INLINE satisfy #-}
  char :: Char -> WriterT w m Char
char    = m Char -> WriterT w m Char
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> WriterT w m Char)
-> (Char -> m Char) -> Char -> WriterT w m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char
  {-# INLINE char #-}
  notChar :: Char -> WriterT w m Char
notChar = m Char -> WriterT w m Char
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> WriterT w m Char)
-> (Char -> m Char) -> Char -> WriterT w m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
notChar
  {-# INLINE notChar #-}
  anyChar :: WriterT w m Char
anyChar = m Char -> WriterT w m Char
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
forall (m :: * -> *). CharParsing m => m Char
anyChar
  {-# INLINE anyChar #-}
  string :: [Char] -> WriterT w m [Char]
string  = m [Char] -> WriterT w m [Char]
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m [Char] -> WriterT w m [Char])
-> ([Char] -> m [Char]) -> [Char] -> WriterT w m [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string
  {-# INLINE string #-}
  text :: Text -> WriterT w m Text
text = m Text -> WriterT w m Text
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Text -> WriterT w m Text)
-> (Text -> m Text) -> Text -> WriterT w m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m Text
forall (m :: * -> *). CharParsing m => Text -> m Text
text
  {-# INLINE text #-}

instance (CharParsing m, MonadPlus m, Monoid w) => CharParsing (Lazy.WriterT w m) where
  satisfy :: (Char -> Bool) -> WriterT w m Char
satisfy = m Char -> WriterT w m Char
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> WriterT w m Char)
-> ((Char -> Bool) -> m Char) -> (Char -> Bool) -> WriterT w m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy
  {-# INLINE satisfy #-}
  char :: Char -> WriterT w m Char
char    = m Char -> WriterT w m Char
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> WriterT w m Char)
-> (Char -> m Char) -> Char -> WriterT w m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char
  {-# INLINE char #-}
  notChar :: Char -> WriterT w m Char
notChar = m Char -> WriterT w m Char
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> WriterT w m Char)
-> (Char -> m Char) -> Char -> WriterT w m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
notChar
  {-# INLINE notChar #-}
  anyChar :: WriterT w m Char
anyChar = m Char -> WriterT w m Char
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
forall (m :: * -> *). CharParsing m => m Char
anyChar
  {-# INLINE anyChar #-}
  string :: [Char] -> WriterT w m [Char]
string  = m [Char] -> WriterT w m [Char]
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m [Char] -> WriterT w m [Char])
-> ([Char] -> m [Char]) -> [Char] -> WriterT w m [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string
  {-# INLINE string #-}
  text :: Text -> WriterT w m Text
text = m Text -> WriterT w m Text
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Text -> WriterT w m Text)
-> (Text -> m Text) -> Text -> WriterT w m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m Text
forall (m :: * -> *). CharParsing m => Text -> m Text
text
  {-# INLINE text #-}

instance (CharParsing m, MonadPlus m, Monoid w) => CharParsing (Lazy.RWST r w s m) where
  satisfy :: (Char -> Bool) -> RWST r w s m Char
satisfy = m Char -> RWST r w s m Char
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> RWST r w s m Char)
-> ((Char -> Bool) -> m Char)
-> (Char -> Bool)
-> RWST r w s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy
  {-# INLINE satisfy #-}
  char :: Char -> RWST r w s m Char
char    = m Char -> RWST r w s m Char
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> RWST r w s m Char)
-> (Char -> m Char) -> Char -> RWST r w s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char
  {-# INLINE char #-}
  notChar :: Char -> RWST r w s m Char
notChar = m Char -> RWST r w s m Char
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> RWST r w s m Char)
-> (Char -> m Char) -> Char -> RWST r w s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
notChar
  {-# INLINE notChar #-}
  anyChar :: RWST r w s m Char
anyChar = m Char -> RWST r w s m Char
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
forall (m :: * -> *). CharParsing m => m Char
anyChar
  {-# INLINE anyChar #-}
  string :: [Char] -> RWST r w s m [Char]
string  = m [Char] -> RWST r w s m [Char]
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m [Char] -> RWST r w s m [Char])
-> ([Char] -> m [Char]) -> [Char] -> RWST r w s m [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string
  {-# INLINE string #-}
  text :: Text -> RWST r w s m Text
text = m Text -> RWST r w s m Text
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Text -> RWST r w s m Text)
-> (Text -> m Text) -> Text -> RWST r w s m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m Text
forall (m :: * -> *). CharParsing m => Text -> m Text
text
  {-# INLINE text #-}

instance (CharParsing m, MonadPlus m, Monoid w) => CharParsing (Strict.RWST r w s m) where
  satisfy :: (Char -> Bool) -> RWST r w s m Char
satisfy = m Char -> RWST r w s m Char
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> RWST r w s m Char)
-> ((Char -> Bool) -> m Char)
-> (Char -> Bool)
-> RWST r w s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy
  {-# INLINE satisfy #-}
  char :: Char -> RWST r w s m Char
char    = m Char -> RWST r w s m Char
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> RWST r w s m Char)
-> (Char -> m Char) -> Char -> RWST r w s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char
  {-# INLINE char #-}
  notChar :: Char -> RWST r w s m Char
notChar = m Char -> RWST r w s m Char
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> RWST r w s m Char)
-> (Char -> m Char) -> Char -> RWST r w s m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
notChar
  {-# INLINE notChar #-}
  anyChar :: RWST r w s m Char
anyChar = m Char -> RWST r w s m Char
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
forall (m :: * -> *). CharParsing m => m Char
anyChar
  {-# INLINE anyChar #-}
  string :: [Char] -> RWST r w s m [Char]
string  = m [Char] -> RWST r w s m [Char]
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m [Char] -> RWST r w s m [Char])
-> ([Char] -> m [Char]) -> [Char] -> RWST r w s m [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string
  {-# INLINE string #-}
  text :: Text -> RWST r w s m Text
text = m Text -> RWST r w s m Text
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Text -> RWST r w s m Text)
-> (Text -> m Text) -> Text -> RWST r w s m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m Text
forall (m :: * -> *). CharParsing m => Text -> m Text
text
  {-# INLINE text #-}

instance (CharParsing m, MonadPlus m) => CharParsing (IdentityT m) where
  satisfy :: (Char -> Bool) -> IdentityT m Char
satisfy = m Char -> IdentityT m Char
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> IdentityT m Char)
-> ((Char -> Bool) -> m Char) -> (Char -> Bool) -> IdentityT m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy
  {-# INLINE satisfy #-}
  char :: Char -> IdentityT m Char
char    = m Char -> IdentityT m Char
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> IdentityT m Char)
-> (Char -> m Char) -> Char -> IdentityT m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
char
  {-# INLINE char #-}
  notChar :: Char -> IdentityT m Char
notChar = m Char -> IdentityT m Char
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Char -> IdentityT m Char)
-> (Char -> m Char) -> Char -> IdentityT m Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
notChar
  {-# INLINE notChar #-}
  anyChar :: IdentityT m Char
anyChar = m Char -> IdentityT m Char
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m Char
forall (m :: * -> *). CharParsing m => m Char
anyChar
  {-# INLINE anyChar #-}
  string :: [Char] -> IdentityT m [Char]
string  = m [Char] -> IdentityT m [Char]
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m [Char] -> IdentityT m [Char])
-> ([Char] -> m [Char]) -> [Char] -> IdentityT m [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string
  {-# INLINE string #-}
  text :: Text -> IdentityT m Text
text = m Text -> IdentityT m Text
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Text -> IdentityT m Text)
-> (Text -> m Text) -> Text -> IdentityT m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m Text
forall (m :: * -> *). CharParsing m => Text -> m Text
text
  {-# INLINE text #-}

#ifdef MIN_VERSION_parsec
instance Parsec.Stream s m Char => CharParsing (Parsec.ParsecT s u m) where
  satisfy :: (Char -> Bool) -> ParsecT s u m Char
satisfy   = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
Parsec.satisfy
  char :: Char -> ParsecT s u m Char
char      = Char -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
Parsec.char
  notChar :: Char -> ParsecT s u m Char
notChar Char
c = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
Parsec.satisfy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
c)
  anyChar :: ParsecT s u m Char
anyChar   = ParsecT s u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
Parsec.anyChar
  string :: [Char] -> ParsecT s u m [Char]
string    = [Char] -> ParsecT s u m [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
Parsec.string
#endif

#ifdef MIN_VERSION_attoparsec
instance Att.Chunk t => CharParsing (Att.Parser t) where
  satisfy :: (Char -> Bool) -> Parser t Char
satisfy Char -> Bool
p = (ChunkElem t -> Char) -> Parser t (ChunkElem t) -> Parser t Char
forall a b. (a -> b) -> Parser t a -> Parser t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ChunkElem t -> Char
e2c (Parser t (ChunkElem t) -> Parser t Char)
-> Parser t (ChunkElem t) -> Parser t Char
forall a b. (a -> b) -> a -> b
$ (ChunkElem t -> Bool) -> Parser t (ChunkElem t)
forall t.
Chunk t =>
(ChunkElem t -> Bool) -> Parser t (ChunkElem t)
Att.satisfyElem ((ChunkElem t -> Bool) -> Parser t (ChunkElem t))
-> (ChunkElem t -> Bool) -> Parser t (ChunkElem t)
forall a b. (a -> b) -> a -> b
$ Char -> Bool
p (Char -> Bool) -> (ChunkElem t -> Char) -> ChunkElem t -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ChunkElem t -> Char
e2c
    where e2c :: ChunkElem t -> Char
e2c = t -> ChunkElem t -> Char
forall c. Chunk c => c -> ChunkElem c -> Char
Att.chunkElemToChar (t
forall a. HasCallStack => a
undefined :: t)
  {-# INLINE satisfy #-}
#endif

instance CharParsing ReadP.ReadP where
  satisfy :: (Char -> Bool) -> ReadP Char
satisfy   = (Char -> Bool) -> ReadP Char
ReadP.satisfy
  char :: Char -> ReadP Char
char      = Char -> ReadP Char
ReadP.char
  notChar :: Char -> ReadP Char
notChar Char
c = (Char -> Bool) -> ReadP Char
ReadP.satisfy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
c)
  anyChar :: ReadP Char
anyChar   = ReadP Char
ReadP.get
  string :: [Char] -> ReadP [Char]
string    = [Char] -> ReadP [Char]
ReadP.string