-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Fast non-backtracking incremental combinator parsing for bytestrings
--   
--   Parser combinator library designed to be fast. It doesn't support
--   backtracking.
@package scanner
@version 0.3


-- | Scanner implementation
module Scanner.Internal

-- | CPS scanner without backtracking
newtype Scanner a
Scanner :: (forall r. ByteString -> Next a r -> Result r) -> Scanner a
[run] :: Scanner a -> forall r. ByteString -> Next a r -> Result r

-- | Scanner continuation
type Next a r = ByteString -> a -> Result r

-- | Scanner result
data Result r

-- | Successful result with the rest of input
Done :: ByteString -> r -> Result r

-- | Scanner failed with rest of input and error message
Fail :: ByteString -> String -> Result r

-- | Need more input
More :: (ByteString -> Result r) -> Result r

-- | Run scanner with the input
scan :: Scanner r -> ByteString -> Result r

-- | Consume the next word
--   
--   It fails if end of input
anyWord8 :: Scanner Word8

-- | Take input while the predicate is <a>True</a>
takeWhile :: (Word8 -> Bool) -> Scanner ByteString

-- | Take the specified number of bytes
take :: Int -> Scanner ByteString

-- | Returns <a>True</a> when there is no more input
endOfInput :: Scanner Bool

-- | Consume the specified string
--   
--   Warning: it is not optimized yet, so for for small string it is better
--   to consume it byte-by-byte using <a>word8</a>
string :: ByteString -> Scanner ()

-- | Return the next byte, if any, without consuming it
lookAhead :: Scanner (Maybe Word8)

-- | Fold over the octets, which satisfy the predicate
foldlWhile :: (Word8 -> Bool) -> (a -> Word8 -> a) -> a -> Scanner a

-- | Fold over the octets, which satisfy the predicate, ensuring that
--   there's at least one
foldlWhile1 :: (Word8 -> Bool) -> (a -> Word8 -> a) -> a -> Scanner a

-- | Consume a single octet which satisfies the predicate and fail if it
--   does not
satisfy :: (Word8 -> Bool) -> Scanner Word8

-- | Consume a single octet in case it satisfies the predicate
satisfyMaybe :: (Word8 -> Bool) -> Scanner (Maybe Word8)

-- | Parse a non-negative decimal number in ASCII
decimal :: Integral n => Scanner n
instance GHC.Base.Functor Scanner.Internal.Scanner
instance GHC.Base.Applicative Scanner.Internal.Scanner
instance GHC.Base.Monad Scanner.Internal.Scanner


-- | Fast not-backtracking incremental scanner for bytestrings
--   
--   Unlike attoparsec or most of other parser combinator libraries,
--   scanner doesn't support backtracking. But you probably don't need it
--   anyway, at least if you need fast parser.
--   
--   Scanner processes input incrementally. When more input is needed,
--   scanner returns <a>More</a> continuation. All the already processed
--   input is discarded.
module Scanner

-- | CPS scanner without backtracking
data Scanner a

-- | Scanner result
data Result r

-- | Successful result with the rest of input
Done :: ByteString -> r -> Result r

-- | Scanner failed with rest of input and error message
Fail :: ByteString -> String -> Result r

-- | Need more input
More :: (ByteString -> Result r) -> Result r

-- | Run scanner with the input
scan :: Scanner r -> ByteString -> Result r

-- | Scan the complete input, without resupplying
scanOnly :: Scanner a -> ByteString -> Either String a

-- | Scan lazy bytestring by resupplying scanner with chunks
scanLazy :: Scanner a -> ByteString -> Either String a

-- | Scan with the provided resupply action
scanWith :: Monad m => m ByteString -> Scanner a -> ByteString -> m (Result a)

-- | Consume the next word
--   
--   It fails if end of input
anyWord8 :: Scanner Word8

-- | Consume the next 8-bit char
--   
--   It fails if end of input
anyChar8 :: Scanner Char

-- | Consume the specified word or fail
word8 :: Word8 -> Scanner ()

-- | Consume the specified 8-bit char or fail
char8 :: Char -> Scanner ()

-- | Take the specified number of bytes
take :: Int -> Scanner ByteString

-- | Take input while the predicate is <a>True</a>
takeWhile :: (Word8 -> Bool) -> Scanner ByteString

-- | Take input while the predicate is <a>True</a>
takeWhileChar8 :: (Char -> Bool) -> Scanner ByteString

-- | Consume the specified string
--   
--   Warning: it is not optimized yet, so for for small string it is better
--   to consume it byte-by-byte using <a>word8</a>
string :: ByteString -> Scanner ()

-- | Skip any input while the preducate is <a>True</a>
skipWhile :: (Word8 -> Bool) -> Scanner ()

-- | Skip space
skipSpace :: Scanner ()

-- | Return the next byte, if any, without consuming it
lookAhead :: Scanner (Maybe Word8)

-- | Return the next byte, if any, without consuming it
lookAheadChar8 :: Scanner (Maybe Char)

-- | Fold over the octets, which satisfy the predicate
foldlWhile :: (Word8 -> Bool) -> (a -> Word8 -> a) -> a -> Scanner a

-- | Fold over the octets, which satisfy the predicate, ensuring that
--   there's at least one
foldlWhile1 :: (Word8 -> Bool) -> (a -> Word8 -> a) -> a -> Scanner a

-- | Consume a single octet which satisfies the predicate and fail if it
--   does not
satisfy :: (Word8 -> Bool) -> Scanner Word8

-- | Consume a single octet in case it satisfies the predicate
satisfyMaybe :: (Word8 -> Bool) -> Scanner (Maybe Word8)

-- | Parse a non-negative decimal number in ASCII
decimal :: Integral n => Scanner n
