git.iko.soy/typeable/attoparsec
on master help sign in
Added Chunk.chunkElemToChar,

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

commitf6d7f5e79e4a642cd7d5c6bcd89806261e95d240 authorMikhail Vorozhtsov <mikhail.vorozhtsov@gmail.com> dateTue 10 Jun 2014, 17:22 (12 years ago) parentb0fed37
2 files changed+10−2
Data/Attoparsec/Internal/Types.hs+8 Data/Attoparsec/Types.hs+2−2
Data/Attoparsec/Internal/Types.hs+8
@@ -31,6 +31,7 @@ import Control.Monad (MonadPlus(..))
3131import Data.Word (Word8)
3232import Data.ByteString (ByteString)
3333import qualified Data.ByteString as BS
34+import Data.ByteString.Internal (w2c)
3435import Data.Monoid (Monoid(..))
3536import Data.Text (Text)
3637import qualified Data.Text as Text
@@ -214,6 +215,9 @@ class Monoid c => Chunk c where
214215 atBufferEnd :: c -> State c -> Pos
215216 -- | Return the buffer element at the given position along with its length.
216217 bufferElemAt :: c -> Pos -> State c -> Maybe (ChunkElem c, Int)
218+ -- | Map an element to the corresponding character.
219+ -- The first argument is ignored.
220+ chunkElemToChar :: c -> ChunkElem c -> Char
217221
218222instance Chunk ByteString where
219223 type ChunkElem ByteString = Word8
@@ -227,6 +231,8 @@ instance Chunk ByteString where
227231 | i < B.length buf = Just (B.unsafeIndex buf i, 1)
228232 | otherwise = Nothing
229233 {-# INLINE bufferElemAt #-}
234+ chunkElemToChar _ = w2c
235+ {-# INLINE chunkElemToChar #-}
230236
231237instance Chunk Text where
232238 type ChunkElem Text = Char
@@ -240,3 +246,5 @@ instance Chunk Text where
240246 | i < T.length buf = let Iter c l = T.iter buf i in Just (c, l)
241247 | otherwise = Nothing
242248 {-# INLINE bufferElemAt #-}
249+ chunkElemToChar _ = id
250+ {-# INLINE chunkElemToChar #-}
Data/Attoparsec/Types.hs+2−2
@@ -14,7 +14,7 @@ module Data.Attoparsec.Types
1414 (
1515 Parser
1616 , IResult(..)
17− , Chunk
17+ , Chunk(chunkElemToChar)
1818 ) where
1919
20−import Data.Attoparsec.Internal.Types (Parser(..), IResult(..), Chunk)
20+import Data.Attoparsec.Internal.Types (Parser(..), IResult(..), Chunk(..))