{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fspec-constr -fspec-constr-count=8 #-}
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 704
#define USE_DEFAULT_SIGNATURES
#endif
#ifdef USE_DEFAULT_SIGNATURES
{-# LANGUAGE DefaultSignatures, TypeFamilies, TypeOperators #-}
#endif
module Text.Parser.Char
(
oneOf
, noneOf
, oneOfSet
, noneOfSet
, spaces
, space
, newline
, tab
, upper
, lower
, alphaNum
, letter
, digit
, hexDigit
, octDigit
, satisfyRange
, CharParsing(..)
) where
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
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
#if __GLASGOW_HASKELL__ < 710
import Data.Monoid
#endif
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 :: 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" #-}
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 :: 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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
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 #-}
class Parsing m => CharParsing m where
satisfy :: (Char -> Bool) -> m Char
#ifdef USE_DEFAULT_SIGNATURES
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
#endif
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 :: 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 #-}
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 :: 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 :: 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