tibbe avatar tibbe committed 4a52e1f

peekChar/peekWord8: Return Nothing at end-of-input

Fixes #20.

Comments (0)

Files changed (5)

Data/Attoparsec/ByteString/Internal.hs

 -- combinators such as 'many', because such parsers loop until a
 -- failure occurs.  Careless use will thus result in an infinite loop.
 peekWord8 :: Parser (Maybe Word8)
-peekWord8 = T.Parser $ \i0 a0 m0 _kf ks ->
-            let ks' i a m = let w = B.unsafeHead (unI i)
-                            in w `seq` ks i a m (Just w)
-                kf' i a m = ks i a m Nothing
-            in if B.null (unI i0)
-               then prompt i0 a0 m0 kf' ks'
-               else ks' i0 a0 m0
+peekWord8 = T.Parser $ \i0 a0 m0 _kf ks -> case m0 of
+    Complete   -> ks i0 a0 m0 Nothing
+    Incomplete -> let ks' i a m = let w = B.unsafeHead (unI i)
+                                  in w `seq` ks i a m (Just w)
+                      kf' i a m = ks i a m Nothing
+                  in if B.null (unI i0)
+                     then prompt i0 a0 m0 kf' ks'
+                     else ks' i0 a0 m0
 {-# INLINE peekWord8 #-}
 
 -- | Match only if all input has been consumed.

Data/Attoparsec/Text/Internal.hs

 -- combinators such as 'many', because such parsers loop until a
 -- failure occurs.  Careless use will thus result in an infinite loop.
 peekChar :: Parser (Maybe Char)
-peekChar = T.Parser $ \i0 a0 m0 _kf ks ->
-       let ks' i a m = let w = unsafeHead (unI i)
-                       in w `seq` ks i a m (Just w)
-           kf' i a m = ks i a m Nothing
-       in if T.null (unI i0)
-          then prompt i0 a0 m0 kf' ks'
-          else ks' i0 a0 m0
+peekChar = T.Parser $ \i0 a0 m0 _kf ks -> case m0 of
+    Complete   -> ks i0 a0 m0 Nothing
+    Incomplete -> let ks' i a m = let w = unsafeHead (unI i)
+                                  in w `seq` ks i a m (Just w)
+                      kf' i a m = ks i a m Nothing
+                  in if T.null (unI i0)
+                     then prompt i0 a0 m0 kf' ks'
+                     else ks' i0 a0 m0
 {-# INLINE peekChar #-}
 
 -- | Match only if all input has been consumed.
+{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
 module Main (main) where
 
 import qualified QC.ByteString as ByteString

tests/QC/ByteString.hs

 {-# LANGUAGE OverloadedStrings #-}
-{-# OPTIONS_GHC -fno-warn-orphans #-}
+{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-orphans #-}
 module QC.ByteString (tests) where
 
 import Control.Applicative ((<$>), (<*>))
 {-# LANGUAGE OverloadedStrings #-}
-{-# OPTIONS_GHC -fno-warn-orphans #-}
+{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-orphans #-}
 module QC.Text (tests) where
 
 import Control.Applicative ((<$>), (<*>))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.