git.iko.soy/typeable/attoparsec
on master help sign in
peekChar/peekWord8: Return Nothing at end-of-input

Fixes #20.

commit464f095705f72a6e68d60b7a6ca05d39f1a83fb9 authorJohan Tibell <johan.tibell@gmail.com> dateMon 13 Aug 2012, 21:46 (14 years ago) parentb8f0605
5 files changed+19−16
Data/Attoparsec/ByteString/Internal.hs+8−7 Data/Attoparsec/Text/Internal.hs+8−7 tests/QC.hs+1 tests/QC/ByteString.hs+1−1 tests/QC/Text.hs+1−1
Data/Attoparsec/ByteString/Internal.hs+8−7
@@ -407,13 +407,14 @@ notWord8 c = satisfy (/= c) <?> "not " ++ show c
407407-- combinators such as 'many', because such parsers loop until a
408408-- failure occurs. Careless use will thus result in an infinite loop.
409409peekWord8 :: Parser (Maybe Word8)
410−peekWord8 = T.Parser $ \i0 a0 m0 _kf ks ->
411− let ks' i a m = let w = B.unsafeHead (unI i)
412− in w `seq` ks i a m (Just w)
413− kf' i a m = ks i a m Nothing
414− in if B.null (unI i0)
415− then prompt i0 a0 m0 kf' ks'
416− else ks' i0 a0 m0
410+peekWord8 = T.Parser $ \i0 a0 m0 _kf ks -> case m0 of
411+ Complete -> ks i0 a0 m0 Nothing
412+ Incomplete -> let ks' i a m = let w = B.unsafeHead (unI i)
413+ in w `seq` ks i a m (Just w)
414+ kf' i a m = ks i a m Nothing
415+ in if B.null (unI i0)
416+ then prompt i0 a0 m0 kf' ks'
417+ else ks' i0 a0 m0
417418{-# INLINE peekWord8 #-}
418419
419420-- | Match only if all input has been consumed.
Data/Attoparsec/Text/Internal.hs+8−7
@@ -410,13 +410,14 @@ notChar c = satisfy (/= c) <?> "not " ++ show c
410410-- combinators such as 'many', because such parsers loop until a
411411-- failure occurs. Careless use will thus result in an infinite loop.
412412peekChar :: Parser (Maybe Char)
413−peekChar = T.Parser $ \i0 a0 m0 _kf ks ->
414− let ks' i a m = let w = unsafeHead (unI i)
415− in w `seq` ks i a m (Just w)
416− kf' i a m = ks i a m Nothing
417− in if T.null (unI i0)
418− then prompt i0 a0 m0 kf' ks'
419− else ks' i0 a0 m0
413+peekChar = T.Parser $ \i0 a0 m0 _kf ks -> case m0 of
414+ Complete -> ks i0 a0 m0 Nothing
415+ Incomplete -> let ks' i a m = let w = unsafeHead (unI i)
416+ in w `seq` ks i a m (Just w)
417+ kf' i a m = ks i a m Nothing
418+ in if T.null (unI i0)
419+ then prompt i0 a0 m0 kf' ks'
420+ else ks' i0 a0 m0
420421{-# INLINE peekChar #-}
421422
422423-- | Match only if all input has been consumed.
tests/QC.hs+1
@@ -1,3 +1,4 @@
1+{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
12module Main (main) where
23
34import qualified QC.ByteString as ByteString
tests/QC/ByteString.hs+1−1
@@ -1,5 +1,5 @@
11{-# LANGUAGE OverloadedStrings #-}
2−{-# OPTIONS_GHC -fno-warn-orphans #-}
2+{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-orphans #-}
33module QC.ByteString (tests) where
44
55import Control.Applicative ((<$>), (<*>))
tests/QC/Text.hs+1−1
@@ -1,5 +1,5 @@
11{-# LANGUAGE OverloadedStrings #-}
2−{-# OPTIONS_GHC -fno-warn-orphans #-}
2+{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-orphans #-}
33module QC.Text (tests) where
44
55import Control.Applicative ((<$>), (<*>))