{-# LANGUAGE CPP, FlexibleContexts, Safe #-}
module Text.Parsec.Char where
import Data.Char (isSpace, isUpper, isLower, isAlphaNum, isAlpha, isDigit, isHexDigit, isOctDigit)
#if !(MIN_VERSION_base(4,8,0))
import Control.Applicative ((*>))
#endif
import Text.Parsec.Pos
import Text.Parsec.Prim
oneOf :: (Stream s m Char) => [Char] -> ParsecT s u m Char
{-# INLINABLE oneOf #-}
oneOf :: forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf [Char]
cs = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\Char
c -> Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem Char
c [Char]
cs)
noneOf :: (Stream s m Char) => [Char] -> ParsecT s u m Char
{-# INLINABLE noneOf #-}
noneOf :: forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
cs = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\Char
c -> Bool -> Bool
not (Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem Char
c [Char]
cs))
spaces :: (Stream s m Char) => ParsecT s u m ()
{-# INLINABLE spaces #-}
spaces :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces = ParsecT s u m Char -> ParsecT s u m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT s u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space ParsecT s u m () -> [Char] -> ParsecT s u m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"white space"
space :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE space #-}
space :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isSpace ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"space"
newline :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE newline #-}
newline :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline = Char -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\n' ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"lf new-line"
crlf :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE crlf #-}
crlf :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
crlf = Char -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\r' ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char
forall a b. ParsecT s u m a -> ParsecT s u m b -> ParsecT s u m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\n' ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"crlf new-line"
endOfLine :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE endOfLine #-}
endOfLine :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
endOfLine = ParsecT s u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
newline ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT s u m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
crlf ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"new-line"
tab :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE tab #-}
tab :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
tab = Char -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\t' ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"tab"
upper :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE upper #-}
upper :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
upper = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isUpper ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"uppercase letter"
lower :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE lower #-}
lower :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
lower = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isLower ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"lowercase letter"
alphaNum :: (Stream s m Char => ParsecT s u m Char)
{-# INLINABLE alphaNum #-}
alphaNum :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isAlphaNum ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"letter or digit"
letter :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE letter #-}
letter :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isAlpha ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"letter"
digit :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE digit #-}
digit :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isDigit ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"digit"
hexDigit :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE hexDigit #-}
hexDigit :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
hexDigit = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isHexDigit ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"hexadecimal digit"
octDigit :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE octDigit #-}
octDigit :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
octDigit = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isOctDigit ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"octal digit"
char :: (Stream s m Char) => Char -> ParsecT s u m Char
{-# INLINABLE char #-}
char :: forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
c) ParsecT s u m Char -> [Char] -> ParsecT s u m Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char] -> [Char]
forall a. Show a => a -> [Char]
show [Char
c]
anyChar :: (Stream s m Char) => ParsecT s u m Char
{-# INLINABLE anyChar #-}
anyChar :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar = (Char -> Bool) -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (Bool -> Char -> Bool
forall a b. a -> b -> a
const Bool
True)
satisfy :: (Stream s m Char) => (Char -> Bool) -> ParsecT s u m Char
{-# INLINABLE satisfy #-}
satisfy :: forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
f = (Char -> [Char])
-> (SourcePos -> Char -> s -> SourcePos)
-> (Char -> Maybe Char)
-> ParsecT s u m Char
forall s (m :: * -> *) t a u.
Stream s m t =>
(t -> [Char])
-> (SourcePos -> t -> s -> SourcePos)
-> (t -> Maybe a)
-> ParsecT s u m a
tokenPrim (\Char
c -> [Char] -> [Char]
forall a. Show a => a -> [Char]
show [Char
c])
(\SourcePos
pos Char
c s
_cs -> SourcePos -> Char -> SourcePos
updatePosChar SourcePos
pos Char
c)
(\Char
c -> if Char -> Bool
f Char
c then Char -> Maybe Char
forall a. a -> Maybe a
Just Char
c else Maybe Char
forall a. Maybe a
Nothing)
string :: (Stream s m Char) => String -> ParsecT s u m String
{-# INLINABLE string #-}
string :: forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
s = ([Char] -> [Char])
-> (SourcePos -> [Char] -> SourcePos)
-> [Char]
-> ParsecT s u m [Char]
forall s (m :: * -> *) t u.
(Stream s m t, Eq t) =>
([t] -> [Char])
-> (SourcePos -> [t] -> SourcePos) -> [t] -> ParsecT s u m [t]
tokens [Char] -> [Char]
forall a. Show a => a -> [Char]
show SourcePos -> [Char] -> SourcePos
updatePosString [Char]
s
string' :: (Stream s m Char) => String -> ParsecT s u m String
{-# INLINABLE string' #-}
string' :: forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string' [Char]
s = ([Char] -> [Char])
-> (SourcePos -> [Char] -> SourcePos)
-> [Char]
-> ParsecT s u m [Char]
forall s (m :: * -> *) t u.
(Stream s m t, Eq t) =>
([t] -> [Char])
-> (SourcePos -> [t] -> SourcePos) -> [t] -> ParsecT s u m [t]
tokens' [Char] -> [Char]
forall a. Show a => a -> [Char]
show SourcePos -> [Char] -> SourcePos
updatePosString [Char]
s