{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE Safe #-}

-- |
-- Module      :  Text.Megaparsec.Common
-- Copyright   :  © 2018–present Megaparsec contributors
-- License     :  FreeBSD
--
-- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>
-- Stability   :  experimental
-- Portability :  portable
--
-- Common token combinators. This module is not public, the functions from
-- it are re-exported in "Text.Megaparsec.Byte" and "Text.Megaparsec.Char".
--
-- @since 7.0.0
module Text.Megaparsec.Common
  ( string,
    string',
  )
where

import qualified Data.CaseInsensitive as CI
import Data.Function (on)
import Text.Megaparsec

-- | A synonym for 'chunk'.
string :: MonadParsec e s m => Tokens s -> m (Tokens s)
string :: Tokens s -> m (Tokens s)
string = Tokens s -> m (Tokens s)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk
{-# INLINE string #-}

-- | The same as 'string', but case-insensitive. On success returns string
-- cased as actually parsed input.
--
-- >>> parseTest (string' "foobar") "foObAr"
-- "foObAr"
string' ::
  (MonadParsec e s m, CI.FoldCase (Tokens s)) =>
  Tokens s ->
  m (Tokens s)
string' :: Tokens s -> m (Tokens s)
string' = (Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Tokens s -> Tokens s -> Bool) -> Tokens s -> m (Tokens s)
tokens (CI (Tokens s) -> CI (Tokens s) -> Bool
forall a. Eq a => a -> a -> Bool
(==) (CI (Tokens s) -> CI (Tokens s) -> Bool)
-> (Tokens s -> CI (Tokens s)) -> Tokens s -> Tokens s -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Tokens s -> CI (Tokens s)
forall s. FoldCase s => s -> CI s
CI.mk)
{-# INLINE string' #-}