@@ -8,7 +8,7 @@
88-- Stability : experimental
99-- Portability : unknown
1010--
11−-- Simple, efficient parser combinators for 'B.ByteString' strings,
11+-- Simple, efficient parser combinators for 'ByteString' strings,
1212-- loosely based on the Parsec library.
1313
1414module Data.Attoparsec.ByteString.Internal
@@ -86,10 +86,10 @@ import qualified Data.ByteString.Internal as B
8686import qualified Data.ByteString.Lazy as L
8787import qualified Data.ByteString.Unsafe as B
8888
89−type Parser = T.Parser B.ByteString Buffer
90−type Result = IResult B.ByteString
91−type Failure r = T.Failure B.ByteString Buffer r
92−type Success a r = T.Success B.ByteString Buffer a r
89+type Parser = T.Parser ByteString Buffer
90+type Result = IResult ByteString
91+type Failure r = T.Failure ByteString Buffer r
92+type Success a r = T.Success ByteString Buffer a r
9393
9494-- | The parser @satisfy p@ succeeds for any byte for which the
9595-- predicate @p@ returns 'True'. Returns the byte that is actually
@@ -140,7 +140,7 @@ storable = hack undefined
140140
141141-- | Consume @n@ bytes of input, but succeed only if the predicate
142142-- returns 'True'.
143−takeWith :: Int -> (B.ByteString -> Bool) -> Parser B.ByteString
143+takeWith :: Int -> (ByteString -> Bool) -> Parser ByteString
144144takeWith n0 p = do
145145 let n = max n0 0
146146 s <- ensure n
@@ -149,7 +149,7 @@ takeWith n0 p = do
149149 else fail "takeWith"
150150
151151-- | Consume exactly @n@ bytes of input.
152−take :: Int -> Parser B.ByteString
152+take :: Int -> Parser ByteString
153153take n = takeWith n (const True)
154154{-# INLINE take #-}
155155
@@ -168,12 +168,12 @@ take n = takeWith n (const True)
168168-- partial match, and will consume the letters @\'f\'@ and @\'o\'@
169169-- before failing. In attoparsec, the above parser will /succeed/ on
170170-- that input, because the failed first branch will consume nothing.
171−string :: B.ByteString -> Parser B.ByteString
171+string :: ByteString -> Parser ByteString
172172string s = takeWith (B.length s) (==s)
173173{-# INLINE string #-}
174174
175−stringTransform :: (B.ByteString -> B.ByteString) -> B.ByteString
176− -> Parser B.ByteString
175+stringTransform :: (ByteString -> ByteString) -> ByteString
176+ -> Parser ByteString
177177stringTransform f s = takeWith (B.length s) ((==f s) . f)
178178{-# INLINE stringTransform #-}
179179
@@ -200,7 +200,7 @@ skipWhile p = go
200200-- combinators such as 'Control.Applicative.many', because such
201201-- parsers loop until a failure occurs. Careless use will thus result
202202-- in an infinite loop.
203−takeTill :: (Word8 -> Bool) -> Parser B.ByteString
203+takeTill :: (Word8 -> Bool) -> Parser ByteString
204204takeTill p = takeWhile (not . p)
205205{-# INLINE takeTill #-}
206206
@@ -214,7 +214,7 @@ takeTill p = takeWhile (not . p)
214214-- combinators such as 'Control.Applicative.many', because such
215215-- parsers loop until a failure occurs. Careless use will thus result
216216-- in an infinite loop.
217−takeWhile :: (Word8 -> Bool) -> Parser B.ByteString
217+takeWhile :: (Word8 -> Bool) -> Parser ByteString
218218takeWhile p = (B.concat . reverse) `fmap` go []
219219 where
220220 go acc = do
@@ -230,7 +230,7 @@ takeWhile p = (B.concat . reverse) `fmap` go []
230230 else return (s:acc)
231231{-# INLINE takeWhile #-}
232232
233−takeRest :: Parser [B.ByteString]
233+takeRest :: Parser [ByteString]
234234takeRest = go []
235235 where
236236 go acc = do
@@ -243,7 +243,7 @@ takeRest = go []
243243 else return (reverse acc)
244244
245245-- | Consume all remaining input and return it as a single string.
246−takeByteString :: Parser B.ByteString
246+takeByteString :: Parser ByteString
247247takeByteString = B.concat `fmap` takeRest
248248
249249-- | Consume all remaining input and return it as a single string.
@@ -252,7 +252,7 @@ takeLazyByteString = L.fromChunks `fmap` takeRest
252252
253253data T s = T {-# UNPACK #-} !Int s
254254
255−scan_ :: (s -> [B.ByteString] -> Parser r) -> s -> (s -> Word8 -> Maybe s)
255+scan_ :: (s -> [ByteString] -> Parser r) -> s -> (s -> Word8 -> Maybe s)
256256 -> Parser r
257257scan_ f s0 p = go [] s0
258258 where
@@ -296,7 +296,7 @@ scan_ f s0 p = go [] s0
296296-- combinators such as 'Control.Applicative.many', because such
297297-- parsers loop until a failure occurs. Careless use will thus result
298298-- in an infinite loop.
299−scan :: s -> (s -> Word8 -> Maybe s) -> Parser B.ByteString
299+scan :: s -> (s -> Word8 -> Maybe s) -> Parser ByteString
300300scan = scan_ $ \_ chunks ->
301301 case chunks of
302302 [x] -> return x
@@ -305,7 +305,7 @@ scan = scan_ $ \_ chunks ->
305305
306306-- | Like 'scan', but generalized to return the final state of the
307307-- scanner.
308−runScanner :: s -> (s -> Word8 -> Maybe s) -> Parser (B.ByteString, s)
308+runScanner :: s -> (s -> Word8 -> Maybe s) -> Parser (ByteString, s)
309309runScanner = scan_ $ \s xs -> return (B.concat (reverse xs), s)
310310{-# INLINE runScanner #-}
311311
@@ -315,7 +315,7 @@ runScanner = scan_ $ \s xs -> return (B.concat (reverse xs), s)
315315-- This parser requires the predicate to succeed on at least one byte
316316-- of input: it will fail if the predicate never returns 'True' or if
317317-- there is no input left.
318−takeWhile1 :: (Word8 -> Bool) -> Parser B.ByteString
318+takeWhile1 :: (Word8 -> Bool) -> Parser ByteString
319319takeWhile1 p = do
320320 (`when` demandInput) =<< endOfChunk
321321 s <- B8.takeWhile p <$> get
@@ -413,12 +413,12 @@ successK t (Pos pos) _more a = Done (Buf.unsafeDrop pos t) a
413413{-# INLINE successK #-}
414414
415415-- | Run a parser.
416−parse :: Parser a -> B.ByteString -> Result a
416+parse :: Parser a -> ByteString -> Result a
417417parse m s = T.runParser m (buffer s) (Pos 0) Incomplete failK successK
418418{-# INLINE parse #-}
419419
420420-- | Run a parser that cannot be resupplied via a 'Partial' result.
421−parseOnly :: Parser a -> B.ByteString -> Either String a
421+parseOnly :: Parser a -> ByteString -> Either String a
422422parseOnly m s = case T.runParser m (buffer s) (Pos 0) Complete failK successK of
423423 Fail _ _ err -> Left err
424424 Done _ a -> Right a