@@ -211,16 +211,16 @@ failDesc err = Parser (\i0 a0 m0 kf _ks -> kf i0 a0 m0 [] msg)
211211 where msg = "Failed reading: " ++ err
212212{-# INLINE failDesc #-}
213213
214−-- | Succeed only if at least @n@ bytes of input are available.
215−ensure :: Int -> Parser ()
214+-- | If at least @n@ bytes of input are available, return the current
215+-- input, otherwise fail.
216+ensure :: Int -> Parser B.ByteString
216217ensure n = Parser $ \i0 a0 m0 kf ks ->
217218 if B.length (unI i0) >= n
218− then ks i0 a0 m0 ()
219+ then ks i0 a0 m0 (unI i0)
219220 else runParser (demandInput >> ensure n) i0 a0 m0 kf ks
220221
221222-- | Ask for input. If we receive any, pass it to a success
222223-- continuation, otherwise to a failure continuation.
223−--prompt :: S -> (S -> Result r) -> (S -> Result r) -> Result r
224224prompt :: Input -> Added -> More
225225 -> (Input -> Added -> More -> Result r)
226226 -> (Input -> Added -> More -> Result r)
@@ -283,8 +283,7 @@ try p = Parser $ \i0 a0 m0 kf ks ->
283283-- > where isDigit w = w >= 48 && w <= 57
284284satisfy :: (Word8 -> Bool) -> Parser Word8
285285satisfy p = do
286− ensure 1
287− s <- get
286+ s <- ensure 1
288287 let w = B.unsafeHead s
289288 if p w
290289 then put (B.unsafeTail s) >> return w
@@ -297,8 +296,7 @@ satisfy p = do
297296-- > where isDigit w = w >= 48 && w <= 57
298297skip :: (Word8 -> Bool) -> Parser ()
299298skip p = do
300− ensure 1
301− s <- get
299+ s <- ensure 1
302300 if p (B.unsafeHead s)
303301 then put (B.unsafeTail s)
304302 else fail "skip"
@@ -308,8 +306,7 @@ skip p = do
308306-- parser returns the transformed byte that was parsed.
309307satisfyWith :: (Word8 -> a) -> (a -> Bool) -> Parser a
310308satisfyWith f p = do
311− ensure 1
312− s <- get
309+ s <- ensure 1
313310 let c = f (B.unsafeHead s)
314311 if p c
315312 then put (B.unsafeTail s) >> return c
@@ -328,8 +325,7 @@ storable = hack undefined
328325-- returns 'True'.
329326takeWith :: Int -> (B.ByteString -> Bool) -> Parser B.ByteString
330327takeWith n p = do
331− ensure n
332− s <- get
328+ s <- ensure n
333329 let (h,t) = B.splitAt n s
334330 if p h
335331 then put t >> return h