module Text.Megaparsec.Compat (
module Text.Megaparsec
#if MIN_VERSION_megaparsec(6,0,0)
,module Text.Megaparsec.Char
#endif
,MPErr
,mptext
,mpMkPos
,mpUnPos
,mpMkParseError
)
where
import qualified Data.Set as S
import Data.Text
import Text.Megaparsec
#if MIN_VERSION_megaparsec(6,0,0)
import Text.Megaparsec.Char
import Data.List.NonEmpty (fromList)
import Data.Void (Void)
type MPErr = Void
mpMkParseError :: FilePath -> String -> ParseError Char String
mpMkParseError f s = FancyError (fromList [initialPos f]) (S.singleton $ ErrorFail s)
mpMkPos :: Int -> Pos
mpMkPos = mkPos
mpUnPos :: Pos -> Int
mpUnPos = unPos
mptext :: MonadParsec e Text m => Tokens Text -> m (Tokens Text)
mptext = string
#else
import Text.Megaparsec.Prim (MonadParsec)
type MPErr = Dec
mpMkParseError :: FilePath -> String -> ParseError Char String
mpMkParseError f s = (mempty :: ParseError Char String){errorCustom = S.singleton $ f ++ ": " ++ s}
mpMkPos :: Int -> Pos
mpMkPos = unsafePos . fromIntegral
mpUnPos :: Pos -> Int
mpUnPos = fromIntegral . unPos
mptext :: MonadParsec e Text m => Text -> m Text
mptext = fmap pack . string . unpack
#endif