@@ -369,18 +369,18 @@ takeTill p = takeWhile (not . p)
369-- combinators such as 'many', because such parsers loop until a
369-- combinators such as 'many', because such parsers loop until a
370-- failure occurs. Careless use will thus result in an infinite loop.
370-- failure occurs. Careless use will thus result in an infinite loop.
371takeWhile :: (Word8 -> Bool) -> Parser B.ByteString
371takeWhile :: (Word8 -> Bool) -> Parser B.ByteString
372−takeWhile p = go
372+takeWhile p = (B.concat . reverse) `fmap` go []
374− go = do
374+ go acc = do
375 input <- wantInput
375 input <- wantInput
378 (h,t) <- B8.span p <$> get
378 (h,t) <- B8.span p <$> get
380 if B.null t
380 if B.null t
381− then (h+++) `fmapP` go
381+ then go (h:acc)
382− else return h
382+ else return (h:acc)
383− else return B.empty
383+ else return []
385-- | A stateful scanner. The predicate consumes and transforms a
385-- | A stateful scanner. The predicate consumes and transforms a
386-- state argument, and each transformed state is passed to successive
386-- state argument, and each transformed state is passed to successive
@@ -394,9 +394,9 @@ takeWhile p = go
394-- combinators such as 'many', because such parsers loop until a
394-- combinators such as 'many', because such parsers loop until a
395-- failure occurs. Careless use will thus result in an infinite loop.
395-- failure occurs. Careless use will thus result in an infinite loop.
396scan :: s -> (s -> Word8 -> Maybe s) -> Parser B.ByteString
396scan :: s -> (s -> Word8 -> Maybe s) -> Parser B.ByteString
397−scan s0 p = go s0
397+scan s0 p = (B.concat . reverse) `fmap` go [] s0
399− go s1 = do
399+ go acc s1 = do
400 input <- wantInput
400 input <- wantInput
@@ -413,9 +413,9 @@ scan s0 p = go s0
413 (h,t,s') <- (unsafePerformIO . scanner) <$> get
413 (h,t,s') <- (unsafePerformIO . scanner) <$> get
415 if B.null t
415 if B.null t
416− then (h+++) `fmapP` go s'
416+ then go (h:acc) s'
417− else return h
417+ else return (h:acc)
418− else return B.empty
418+ else return acc
419{-# INLINE scan #-}
419{-# INLINE scan #-}
421-- | Consume input as long as the predicate returns 'True', and return
421-- | Consume input as long as the predicate returns 'True', and return