{-# language CPP #-}
{-# language GeneralizedNewtypeDeriving #-}
{-# language FlexibleInstances #-}
module Text.Megaparsec.Parsers
( module Text.Parser.Combinators
, module Text.Parser.Char
, module Text.Parser.LookAhead
, module Text.Parser.Token
, ParsecT(..)
)
where
import Control.Applicative (Applicative, Alternative)
import Control.Monad (MonadPlus)
import Control.Monad.Cont.Class (MonadCont)
import Control.Monad.Error.Class (MonadError)
import Control.Monad.Fail (MonadFail)
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Reader.Class (MonadReader)
import Control.Monad.State.Class (MonadState)
import Control.Monad.Trans (MonadTrans)
import Data.Monoid (Monoid)
import Data.Functor ((<$))
import Data.Semigroup (Semigroup)
import Data.String (fromString)
import Text.Megaparsec (MonadParsec, Stream, Token)
import Text.Parser.Combinators
import Text.Parser.Char
import Text.Parser.LookAhead
import Text.Parser.Token
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Text as Text
import qualified Data.Text.Lazy as Lazy
import qualified Text.Megaparsec as Parsec
import qualified Text.Megaparsec.Char as Parsec
newtype ParsecT e s m a
= ParsecT { forall e s (m :: * -> *) a. ParsecT e s m a -> ParsecT e s m a
unParsecT :: Parsec.ParsecT e s m a }
deriving
( forall a b. a -> ParsecT e s m b -> ParsecT e s m a
forall a b. (a -> b) -> ParsecT e s m a -> ParsecT e s m b
forall e s (m :: * -> *) a b.
a -> ParsecT e s m b -> ParsecT e s m a
forall e s (m :: * -> *) a b.
(a -> b) -> ParsecT e s m a -> ParsecT e s m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> ParsecT e s m b -> ParsecT e s m a
$c<$ :: forall e s (m :: * -> *) a b.
a -> ParsecT e s m b -> ParsecT e s m a
fmap :: forall a b. (a -> b) -> ParsecT e s m a -> ParsecT e s m b
$cfmap :: forall e s (m :: * -> *) a b.
(a -> b) -> ParsecT e s m a -> ParsecT e s m b
Functor, forall a. a -> ParsecT e s m a
forall a b. ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m a
forall a b. ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m b
forall a b.
ParsecT e s m (a -> b) -> ParsecT e s m a -> ParsecT e s m b
forall a b c.
(a -> b -> c)
-> ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m c
forall {e} {s} {m :: * -> *}. Stream s => Functor (ParsecT e s m)
forall e s (m :: * -> *) a. Stream s => a -> ParsecT e s m a
forall e s (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m a
forall e s (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m b
forall e s (m :: * -> *) a b.
Stream s =>
ParsecT e s m (a -> b) -> ParsecT e s m a -> ParsecT e s m b
forall e s (m :: * -> *) a b c.
Stream s =>
(a -> b -> c)
-> ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: forall a b. ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m a
$c<* :: forall e s (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m a
*> :: forall a b. ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m b
$c*> :: forall e s (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m b
liftA2 :: forall a b c.
(a -> b -> c)
-> ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m c
$cliftA2 :: forall e s (m :: * -> *) a b c.
Stream s =>
(a -> b -> c)
-> ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m c
<*> :: forall a b.
ParsecT e s m (a -> b) -> ParsecT e s m a -> ParsecT e s m b
$c<*> :: forall e s (m :: * -> *) a b.
Stream s =>
ParsecT e s m (a -> b) -> ParsecT e s m a -> ParsecT e s m b
pure :: forall a. a -> ParsecT e s m a
$cpure :: forall e s (m :: * -> *) a. Stream s => a -> ParsecT e s m a
Applicative, forall a. ParsecT e s m a
forall a. ParsecT e s m a -> ParsecT e s m [a]
forall a. ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
forall {e} {s} {m :: * -> *}.
(Stream s, Ord e) =>
Applicative (ParsecT e s m)
forall e s (m :: * -> *) a. (Stream s, Ord e) => ParsecT e s m a
forall e s (m :: * -> *) a.
(Stream s, Ord e) =>
ParsecT e s m a -> ParsecT e s m [a]
forall e s (m :: * -> *) a.
(Stream s, Ord e) =>
ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
many :: forall a. ParsecT e s m a -> ParsecT e s m [a]
$cmany :: forall e s (m :: * -> *) a.
(Stream s, Ord e) =>
ParsecT e s m a -> ParsecT e s m [a]
some :: forall a. ParsecT e s m a -> ParsecT e s m [a]
$csome :: forall e s (m :: * -> *) a.
(Stream s, Ord e) =>
ParsecT e s m a -> ParsecT e s m [a]
<|> :: forall a. ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
$c<|> :: forall e s (m :: * -> *) a.
(Stream s, Ord e) =>
ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
empty :: forall a. ParsecT e s m a
$cempty :: forall e s (m :: * -> *) a. (Stream s, Ord e) => ParsecT e s m a
Alternative, forall a. a -> ParsecT e s m a
forall a b. ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m b
forall a b.
ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b
forall e s (m :: * -> *). Stream s => Applicative (ParsecT e s m)
forall e s (m :: * -> *) a. Stream s => a -> ParsecT e s m a
forall e s (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m b
forall e s (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> ParsecT e s m a
$creturn :: forall e s (m :: * -> *) a. Stream s => a -> ParsecT e s m a
>> :: forall a b. ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m b
$c>> :: forall e s (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> ParsecT e s m b -> ParsecT e s m b
>>= :: forall a b.
ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b
$c>>= :: forall e s (m :: * -> *) a b.
Stream s =>
ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b
Monad, forall a. ParsecT e s m a
forall a. ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
forall {e} {s} {m :: * -> *}.
(Stream s, Ord e) =>
Monad (ParsecT e s m)
forall e s (m :: * -> *).
(Stream s, Ord e) =>
Alternative (ParsecT e s m)
forall e s (m :: * -> *) a. (Stream s, Ord e) => ParsecT e s m a
forall e s (m :: * -> *) a.
(Stream s, Ord e) =>
ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: forall a. ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
$cmplus :: forall e s (m :: * -> *) a.
(Stream s, Ord e) =>
ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
mzero :: forall a. ParsecT e s m a
$cmzero :: forall e s (m :: * -> *) a. (Stream s, Ord e) => ParsecT e s m a
MonadPlus
, MonadParsec e s, MonadError e', MonadReader r, MonadState st
, forall e s (m :: * -> *) a. Monad m => m a -> ParsecT e s m a
forall (m :: * -> *) a. Monad m => m a -> ParsecT e s m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: forall (m :: * -> *) a. Monad m => m a -> ParsecT e s m a
$clift :: forall e s (m :: * -> *) a. Monad m => m a -> ParsecT e s m a
MonadTrans, forall a. String -> ParsecT e s m a
forall e s (m :: * -> *). Stream s => Monad (ParsecT e s m)
forall e s (m :: * -> *) a. Stream s => String -> ParsecT e s m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
fail :: forall a. String -> ParsecT e s m a
$cfail :: forall e s (m :: * -> *) a. Stream s => String -> ParsecT e s m a
MonadFail, forall a. IO a -> ParsecT e s m a
forall {e} {s} {m :: * -> *}.
(Stream s, MonadIO m) =>
Monad (ParsecT e s m)
forall e s (m :: * -> *) a.
(Stream s, MonadIO m) =>
IO a -> ParsecT e s m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: forall a. IO a -> ParsecT e s m a
$cliftIO :: forall e s (m :: * -> *) a.
(Stream s, MonadIO m) =>
IO a -> ParsecT e s m a
MonadIO, forall a b.
((a -> ParsecT e s m b) -> ParsecT e s m a) -> ParsecT e s m a
forall {e} {s} {m :: * -> *}.
(Stream s, MonadCont m) =>
Monad (ParsecT e s m)
forall e s (m :: * -> *) a b.
(Stream s, MonadCont m) =>
((a -> ParsecT e s m b) -> ParsecT e s m a) -> ParsecT e s m a
forall (m :: * -> *).
Monad m -> (forall a b. ((a -> m b) -> m a) -> m a) -> MonadCont m
callCC :: forall a b.
((a -> ParsecT e s m b) -> ParsecT e s m a) -> ParsecT e s m a
$ccallCC :: forall e s (m :: * -> *) a b.
(Stream s, MonadCont m) =>
((a -> ParsecT e s m b) -> ParsecT e s m a) -> ParsecT e s m a
MonadCont, NonEmpty (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. Integral b => b -> ParsecT e s m a -> ParsecT e s m a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall e s (m :: * -> *) a.
(Stream s, Semigroup a) =>
NonEmpty (ParsecT e s m a) -> ParsecT e s m a
forall e s (m :: * -> *) a.
(Stream s, Semigroup a) =>
ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
forall e s (m :: * -> *) a b.
(Stream s, Semigroup a, Integral b) =>
b -> ParsecT e s m a -> ParsecT e s m a
stimes :: forall b. Integral b => b -> ParsecT e s m a -> ParsecT e s m a
$cstimes :: forall e s (m :: * -> *) a b.
(Stream s, Semigroup a, Integral b) =>
b -> ParsecT e s m a -> ParsecT e s m a
sconcat :: NonEmpty (ParsecT e s m a) -> ParsecT e s m a
$csconcat :: forall e s (m :: * -> *) a.
(Stream s, Semigroup a) =>
NonEmpty (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
$c<> :: forall e s (m :: * -> *) a.
(Stream s, Semigroup a) =>
ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
Semigroup, 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 a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall {e} {s} {m :: * -> *} {a}.
(Stream s, Monoid a) =>
Semigroup (ParsecT e s m a)
forall e s (m :: * -> *) a. (Stream s, Monoid a) => ParsecT e s m a
forall e s (m :: * -> *) a.
(Stream s, Monoid a) =>
[ParsecT e s m a] -> ParsecT e s m a
forall e s (m :: * -> *) a.
(Stream s, Monoid a) =>
ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
mconcat :: [ParsecT e s m a] -> ParsecT e s m a
$cmconcat :: forall e s (m :: * -> *) a.
(Stream s, Monoid 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
$cmappend :: forall e s (m :: * -> *) a.
(Stream s, Monoid a) =>
ParsecT e s m a -> ParsecT e s m a -> ParsecT e s m a
mempty :: ParsecT e s m a
$cmempty :: forall e s (m :: * -> *) a. (Stream s, Monoid a) => ParsecT e s m a
Monoid
)
instance (Ord e, Stream s) => Parsing (ParsecT e s m) where
{-# inline try#-}
try :: forall a. ParsecT e s m a -> ParsecT e s m a
try = forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
Parsec.try
{-# inline (<?>) #-}
<?> :: forall a. ParsecT e s m a -> String -> ParsecT e s m a
(<?>) = forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
(Parsec.<?>)
{-# inline notFollowedBy #-}
notFollowedBy :: forall a. Show a => ParsecT e s m a -> ParsecT e s m ()
notFollowedBy = forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
Parsec.notFollowedBy
{-# inline eof #-}
eof :: ParsecT e s m ()
eof = forall e s (m :: * -> *). MonadParsec e s m => m ()
Parsec.eof
{-# inline unexpected #-}
unexpected :: forall a. String -> ParsecT e s m a
unexpected = forall e s (m :: * -> *) a.
MonadParsec e s m =>
ErrorItem (Token s) -> m a
Parsec.unexpected forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. NonEmpty Char -> ErrorItem t
Parsec.Label forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> NonEmpty a
NonEmpty.fromList
instance Ord e => CharParsing (ParsecT e String m) where
{-# inline satisfy #-}
satisfy :: (Char -> Bool) -> ParsecT e String m Char
satisfy = forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
Parsec.satisfy
{-# inline char #-}
char :: Char -> ParsecT e String m Char
char = forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
Parsec.char
{-# inline string #-}
string :: String -> ParsecT e String m String
string = forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
Parsec.string
{-# inline text #-}
text :: Text -> ParsecT e String m Text
text Text
t = Text
t forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). CharParsing m => String -> m String
string (Text -> String
Text.unpack Text
t)
{-# inline notChar #-}
{-# inline anyChar #-}
#if !MIN_VERSION_megaparsec(7,0,0)
notChar = Parsec.notChar
anyChar = Parsec.anyChar
#else
notChar :: Char -> ParsecT e String m Char
notChar = forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
Parsec.anySingleBut
anyChar :: ParsecT e String m Char
anyChar = forall e s (m :: * -> *). MonadParsec e s m => m (Token s)
Parsec.anySingle
#endif
instance Ord e => CharParsing (ParsecT e Lazy.Text m) where
{-# inline satisfy #-}
satisfy :: (Char -> Bool) -> ParsecT e Text m Char
satisfy = forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
Parsec.satisfy
{-# inline char #-}
char :: Char -> ParsecT e Text m Char
char = forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
Parsec.char
{-# inline string #-}
string :: String -> ParsecT e Text m String
string String
t = String
t forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
Parsec.string (String -> Text
Lazy.pack String
t)
{-# inline text #-}
text :: Text -> ParsecT e Text m Text
text Text
t = Text
t forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
Parsec.string (Text -> Text
Lazy.fromStrict Text
t)
{-# inline notChar #-}
{-# inline anyChar #-}
#if !MIN_VERSION_megaparsec(7,0,0)
notChar = Parsec.notChar
anyChar = Parsec.anyChar
#else
notChar :: Char -> ParsecT e Text m Char
notChar = forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
Parsec.anySingleBut
anyChar :: ParsecT e Text m Char
anyChar = forall e s (m :: * -> *). MonadParsec e s m => m (Token s)
Parsec.anySingle
#endif
instance Ord e => CharParsing (ParsecT e Text.Text m) where
{-# inline satisfy #-}
satisfy :: (Char -> Bool) -> ParsecT e Text m Char
satisfy = forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
Parsec.satisfy
{-# inline char #-}
char :: Char -> ParsecT e Text m Char
char = forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
Parsec.char
{-# inline string #-}
string :: String -> ParsecT e Text m String
string String
t = String
t forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
Parsec.string (String -> Text
Text.pack String
t)
{-# inline text #-}
text :: Text -> ParsecT e Text m Text
text = forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
Parsec.string
{-# inline notChar #-}
{-# inline anyChar #-}
#if !MIN_VERSION_megaparsec(7,0,0)
notChar = Parsec.notChar
anyChar = Parsec.anyChar
#else
notChar :: Char -> ParsecT e Text m Char
notChar = forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
Parsec.anySingleBut
anyChar :: ParsecT e Text m Char
anyChar = forall e s (m :: * -> *). MonadParsec e s m => m (Token s)
Parsec.anySingle
#endif
instance (Ord e, Stream s) => LookAheadParsing (ParsecT e s m) where
{-# inline lookAhead #-}
lookAhead :: forall a. ParsecT e s m a -> ParsecT e s m a
lookAhead = forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
Parsec.lookAhead
instance Ord e => TokenParsing (ParsecT e String m)
instance Ord e => TokenParsing (ParsecT e Text.Text m)
instance Ord e => TokenParsing (ParsecT e Lazy.Text m)