Commits

Anonymous committed a42ba33

Added Chunk.chunkElemToChar,

it is needed to implement CharParsing.satisfy in ekmett/parsers.

Comments (0)

Files changed (2)

Data/Attoparsec/Internal/Types.hs

 import Data.Word (Word8)
 import Data.ByteString (ByteString)
 import qualified Data.ByteString as BS
+import Data.ByteString.Internal (w2c)
 import Data.Monoid (Monoid(..))
 import Data.Text (Text)
 import qualified Data.Text as Text
   atBufferEnd :: c -> State c -> Pos
   -- | Return the buffer element at the given position along with its length.
   bufferElemAt :: c -> Pos -> State c -> Maybe (ChunkElem c, Int)
+  -- | Map an element to the corresponding character.
+  --   The first argument is ignored.
+  chunkElemToChar :: c -> ChunkElem c -> Char
 
 instance Chunk ByteString where
   type ChunkElem ByteString = Word8
     | i < B.length buf = Just (B.unsafeIndex buf i, 1)
     | otherwise = Nothing
   {-# INLINE bufferElemAt #-}
+  chunkElemToChar _ = w2c
+  {-# INLINE chunkElemToChar #-}
 
 instance Chunk Text where
   type ChunkElem Text = Char
     | i < T.length buf = let Iter c l = T.iter buf i in Just (c, l)
     | otherwise = Nothing
   {-# INLINE bufferElemAt #-}
+  chunkElemToChar _ = id
+  {-# INLINE chunkElemToChar #-}

Data/Attoparsec/Types.hs

     (
       Parser
     , IResult(..)
-    , Chunk
+    , Chunk(chunkElemToChar)
     ) where
 
-import Data.Attoparsec.Internal.Types (Parser(..), IResult(..), Chunk)
+import Data.Attoparsec.Internal.Types (Parser(..), IResult(..), Chunk(..))