#if __GLASGOW_HASKELL__ >= 702
#endif
module Data.Attoparsec.ByteString
(
I.Parser
, I.DirParser
, I.BackParser
, I.Directed
, I.Dir(..)
, Result
, T.IResult(..)
, I.compareResults
, parse
, parseBack
, dirParse
, feed
, I.parseOnly
, I.parseBackOnly
, parseWith
, parseBackWith
, 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.runScanner
, I.takeWhile
, I.takeWhile1
, I.takeWhileIncluding
, I.takeTill
, I.getChunk
, I.takeByteString
, I.takeLazyByteString
, I.DirectedTuple ((>*<))
, (*<)
, (>*)
, try
, (<?>)
, choice
, count
, option
, many'
, many1
, many1'
, manyTill
, manyTill'
, sepBy
, sepBy'
, sepBy1
, sepBy1'
, skipMany
, skipMany1
, eitherP
, I.match
, I.endOfInput
, I.endOfLine
, I.atEnd
) where
import Data.Attoparsec.Combinator
import Data.List (intercalate)
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, parseBack, dirParse, (>*), (*<))
import qualified Data.Attoparsec.Internal.Types as T
parseTest :: (Show a) => I.Parser a -> B.ByteString -> IO ()
parseTest :: forall a. Show a => Parser a -> ByteString -> IO ()
parseTest = DirParser 'Forward a -> ByteString -> IO ()
forall (d :: Dir) a.
(DefaultDrift d, BsParserCon d, Show a) =>
DirParser d a -> ByteString -> IO ()
dirParseTest
dirParseTest :: (I.DefaultDrift d, I.BsParserCon d, Show a) => I.DirParser d a -> B.ByteString -> IO ()
dirParseTest :: forall (d :: Dir) a.
(DefaultDrift d, BsParserCon d, Show a) =>
DirParser d a -> ByteString -> IO ()
dirParseTest DirParser d a
p ByteString
s = Result a -> IO ()
forall a. Show a => a -> IO ()
print (DirParser d a -> ByteString -> Result a
forall (d :: Dir) a.
(DefaultDrift d, BsParserCon d) =>
DirParser d a -> ByteString -> Result a
dirParse DirParser d a
p ByteString
s)
parseWith :: (Monad m) =>
(m B.ByteString)
-> I.Parser a
-> B.ByteString
-> m (Result a)
parseWith :: forall (m :: * -> *) a.
Monad m =>
m ByteString -> Parser a -> ByteString -> m (Result a)
parseWith m ByteString
refill Parser a
p ByteString
s = IResult ByteString a -> m (IResult ByteString a)
step (IResult ByteString a -> m (IResult ByteString a))
-> IResult ByteString a -> m (IResult ByteString a)
forall a b. (a -> b) -> a -> b
$ Parser a -> ByteString -> IResult ByteString a
forall a. Parser a -> ByteString -> Result a
parse Parser a
p ByteString
s
where step :: IResult ByteString a -> m (IResult ByteString a)
step (T.Partial ByteString -> IResult ByteString a
k) = (IResult ByteString a -> m (IResult ByteString a)
step (IResult ByteString a -> m (IResult ByteString a))
-> (ByteString -> IResult ByteString a)
-> ByteString
-> m (IResult ByteString a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> IResult ByteString a
k) (ByteString -> m (IResult ByteString a))
-> m ByteString -> m (IResult ByteString a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m ByteString
refill
step IResult ByteString a
r = IResult ByteString a -> m (IResult ByteString a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return IResult ByteString a
r
{-# INLINE parseWith #-}
parseBackWith :: (Monad m) =>
(m B.ByteString)
-> I.BackParser a
-> B.ByteString
-> m (Result a)
parseBackWith :: forall (m :: * -> *) a.
Monad m =>
m ByteString -> BackParser a -> ByteString -> m (Result a)
parseBackWith m ByteString
refill BackParser a
p ByteString
s = IResult ByteString a -> m (IResult ByteString a)
step (IResult ByteString a -> m (IResult ByteString a))
-> IResult ByteString a -> m (IResult ByteString a)
forall a b. (a -> b) -> a -> b
$ BackParser a -> ByteString -> IResult ByteString a
forall a. BackParser a -> ByteString -> Result a
parseBack BackParser a
p ByteString
s
where step :: IResult ByteString a -> m (IResult ByteString a)
step (T.Partial ByteString -> IResult ByteString a
k) = (IResult ByteString a -> m (IResult ByteString a)
step (IResult ByteString a -> m (IResult ByteString a))
-> (ByteString -> IResult ByteString a)
-> ByteString
-> m (IResult ByteString a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> IResult ByteString a
k) (ByteString -> m (IResult ByteString a))
-> m ByteString -> m (IResult ByteString a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m ByteString
refill
step IResult ByteString a
r = IResult ByteString a -> m (IResult ByteString a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return IResult ByteString a
r
{-# INLINE parseBackWith #-}
maybeResult :: Result r -> Maybe r
maybeResult :: forall r. Result r -> Maybe r
maybeResult (T.Done ByteString
_ r
r) = r -> Maybe r
forall a. a -> Maybe a
Just r
r
maybeResult IResult ByteString r
_ = Maybe r
forall a. Maybe a
Nothing
eitherResult :: Result r -> Either String r
eitherResult :: forall r. Result r -> Either String r
eitherResult (T.Done ByteString
_ r
r) = r -> Either String r
forall a b. b -> Either a b
Right r
r
eitherResult (T.Fail ByteString
_ [] String
msg) = String -> Either String r
forall a b. a -> Either a b
Left String
msg
eitherResult (T.Fail ByteString
_ [String]
ctxs String
msg) = String -> Either String r
forall a b. a -> Either a b
Left (String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
" > " [String]
ctxs String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
": " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
msg)
eitherResult IResult ByteString r
_ = String -> Either String r
forall a b. a -> Either a b
Left String
"Result: incomplete input"