Use attoparsec
's lookAhead
(which applies a parser without consuming any input) and manyTill
to write a parser that consumes everything up to (but excluding) a {{{
delimiter. You're then free to apply that parser and throw its result away.
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative ( (<|>) )
import Data.Text ( Text )
import qualified Data.Text as T
import Data.Attoparsec.Text
import Data.Attoparsec.Combinator ( lookAhead, manyTill )
myParser :: Parser Text
myParser = T.concat <$> manyTill (nonOpBraceSpan <|> opBraceSpan)
(lookAhead $ string "{{{")
<?> "{{{"
where
opBraceSpan = takeWhile1 (== '{')
nonOpBraceSpan = takeWhile1 (/= '{')
In GHCi:
λ> :set -XOverloadedStrings
λ> parseTest myParser "{foo{{bar{{{baz"
Done "{{{baz" "{foo{{bar"