module Data.Attoparsec.ByteString
(
I.Parser
, Result
, T.IResult(..)
, I.compareResults
, parse
, feed
, I.parseOnly
, parseWith
, parseTest
, maybeResult
, eitherResult
, I.word8
, I.anyWord8
, I.notWord8
, I.satisfy
, I.satisfyWith
, I.skip
, I.peekWord8
, I.peekWord8'
, I.inClass
, I.notInClass
, I.string
, I.skipWhile
, I.take
, I.scan
, I.takeWhile
, I.takeWhile1
, I.takeTill
, I.takeByteString
, I.takeLazyByteString
, try
, (<?>)
, choice
, count
, option
, many'
, many1
, many1'
, manyTill
, manyTill'
, sepBy
, sepBy'
, sepBy1
, sepBy1'
, skipMany
, skipMany1
, eitherP
, I.match
, I.endOfInput
, I.atEnd
) where
import Data.Attoparsec.Combinator
import qualified Data.Attoparsec.ByteString.Internal as I
import qualified Data.Attoparsec.Internal as I
import qualified Data.ByteString as B
import Data.Attoparsec.ByteString.Internal (Result, parse)
import qualified Data.Attoparsec.Internal.Types as T
parseTest :: (Show a) => I.Parser a -> B.ByteString -> IO ()
parseTest p s = print (parse p s)
parseWith :: Monad m =>
(m B.ByteString)
-> I.Parser a
-> B.ByteString
-> m (Result a)
parseWith refill p s = step $ parse p s
where step (T.Partial k) = (step . k) =<< refill
step r = return r
{-# INLINE parseWith #-}
maybeResult :: Result r -> Maybe r
maybeResult (T.Done _ r) = Just r
maybeResult _ = Nothing
eitherResult :: Result r -> Either String r
eitherResult (T.Done _ r) = Right r
eitherResult (T.Fail _ _ msg) = Left msg
eitherResult _ = Left "Result: incomplete input"