{-# 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 { unParsecT :: Parsec.ParsecT e s m a }
deriving
( Functor, Applicative, Alternative, Monad, MonadPlus
, MonadParsec e s, MonadError e', MonadReader r, MonadState st
, MonadTrans, MonadFail, MonadIO, MonadCont, Semigroup, Monoid
)
instance (Ord e, Stream s) => Parsing (ParsecT e s m) where
{-# inline try#-}
try = Parsec.try
{-# inline (<?>) #-}
(<?>) = (Parsec.<?>)
{-# inline notFollowedBy #-}
notFollowedBy = Parsec.notFollowedBy
{-# inline eof #-}
eof = Parsec.eof
{-# inline unexpected #-}
unexpected = Parsec.unexpected . Parsec.Label . NonEmpty.fromList
instance Ord e => CharParsing (ParsecT e String m) where
{-# inline satisfy #-}
satisfy = Parsec.satisfy
{-# inline char #-}
char = Parsec.char
{-# inline string #-}
string = Parsec.string
{-# inline text #-}
text t = t <$ string (Text.unpack t)
{-# inline notChar #-}
{-# inline anyChar #-}
#if !MIN_VERSION_megaparsec(7,0,0)
notChar = Parsec.notChar
anyChar = Parsec.anyChar
#else
notChar = Parsec.anySingleBut
anyChar = Parsec.anySingle
#endif
instance Ord e => CharParsing (ParsecT e Lazy.Text m) where
{-# inline satisfy #-}
satisfy = Parsec.satisfy
{-# inline char #-}
char = Parsec.char
{-# inline string #-}
string t = t <$ Parsec.string (Lazy.pack t)
{-# inline text #-}
text t = t <$ Parsec.string (Lazy.fromStrict t)
{-# inline notChar #-}
{-# inline anyChar #-}
#if !MIN_VERSION_megaparsec(7,0,0)
notChar = Parsec.notChar
anyChar = Parsec.anyChar
#else
notChar = Parsec.anySingleBut
anyChar = Parsec.anySingle
#endif
instance Ord e => CharParsing (ParsecT e Text.Text m) where
{-# inline satisfy #-}
satisfy = Parsec.satisfy
{-# inline char #-}
char = Parsec.char
{-# inline string #-}
string t = t <$ Parsec.string (Text.pack t)
{-# inline text #-}
text = Parsec.string
{-# inline notChar #-}
{-# inline anyChar #-}
#if !MIN_VERSION_megaparsec(7,0,0)
notChar = Parsec.notChar
anyChar = Parsec.anyChar
#else
notChar = Parsec.anySingleBut
anyChar = Parsec.anySingle
#endif
instance (Ord e, Stream s) => LookAheadParsing (ParsecT e s m) where
{-# inline lookAhead #-}
lookAhead = 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)