-- | Mid-level parsers for XML comments
--
-- All documentation examples assume the following setup:
--
-- > :set -XOverloadedStrings
-- > import Data.Attoparsec.ByteString
module Data.XML.Parser.Mid.Comment where

import           Control.Monad.Compat
import           Data.Text               (Text)
import qualified Data.Text               as Text
import           Data.XML.Parser.Low
import           Text.Parser.Char
import           Text.Parser.Combinators

-- $setup
-- >>> :set -XOverloadedStrings
-- >>> import Data.Attoparsec.ByteString

-- | <https://www.w3.org/TR/REC-xml/#NT-Comment>
--
-- >>> parseOnly comment "<!-- declarations for <head> & <body> -->"
-- Right " declarations for <head> & <body> "
-- >>> parseOnly comment "<!-- B+, B, or B--->"
-- Right " B+, B, or B-"
comment :: CharParsing m => Monad m => m Text
comment :: m Text
comment = do
  m ()
forall (m :: * -> *). CharParsing m => m ()
tokenCommentOpen
  [Char]
content <- m Char -> m () -> m [Char]
forall (m :: * -> *) a end. Alternative m => m a -> m end -> m [a]
manyTill m Char
forall (m :: * -> *). CharParsing m => m Char
anyChar (m () -> m [Char]) -> m () -> m [Char]
forall a b. (a -> b) -> a -> b
$ m () -> m ()
forall (m :: * -> *) a. Parsing m => m a -> m a
try m ()
forall (m :: * -> *). CharParsing m => m ()
tokenCommentClose
  Text -> m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> m Text) -> Text -> m Text
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
Text.pack [Char]
content