@@ -1,5 +1,5 @@
11{-# LANGUAGE BangPatterns, CPP, GeneralizedNewtypeDeriving, OverloadedStrings,
2− Rank2Types, RecordWildCards #-}
2+ Rank2Types, RecordWildCards, TypeFamilies #-}
33-- |
44-- Module : Data.Attoparsec.Internal.Types
55-- Copyright : Bryan O'Sullivan 2007-2011
@@ -23,11 +23,17 @@ module Data.Attoparsec.Internal.Types
2323 , More(..)
2424 , addS
2525 , (<>)
26+ , Chunk(..)
2627 ) where
2728
2829import Control.Applicative (Alternative(..), Applicative(..), (<$>))
2930import Control.DeepSeq (NFData(rnf))
3031import Control.Monad (MonadPlus(..))
32+import Data.Word (Word8)
33+import Data.ByteString (ByteString)
34+import qualified Data.ByteString as BS
35+import Data.Text (Text)
36+import qualified Data.Text as T
3137import Data.Monoid (Monoid(..))
3238import Prelude hiding (getChar, take, takeWhile)
3339
@@ -225,3 +231,19 @@ failDesc err = Parser (\i0 a0 m0 kf _ks -> kf i0 a0 m0 [] msg)
225231(<>) :: (Monoid m) => m -> m -> m
226232(<>) = mappend
227233{-# INLINE (<>) #-}
234+
235+-- | A common interface for input chunks.
236+class Monoid c => Chunk c where
237+ type ChunkElem c
238+ -- | Test if the chunk is empty.
239+ nullChunk :: c -> Bool
240+
241+instance Chunk ByteString where
242+ type ChunkElem ByteString = Word8
243+ nullChunk = BS.null
244+ {-# INLINE nullChunk #-}
245+
246+instance Chunk Text where
247+ type ChunkElem Text = Char
248+ nullChunk = T.null
249+ {-# INLINE nullChunk #-}