@@ -43,13 +43,12 @@ import Control.Monad (MonadPlus(..))
4343import Control.Applicative (many)
4444#endif
4545
46−import Data.Attoparsec.Internal.Types
47−import Data.Attoparsec.Internal
48−#if __GLASGOW_HASKELL__ >= 700
49−import qualified Data.Attoparsec.Zepto as Z
46+import Data.Attoparsec.Internal (demandInput, ensure, put, wantInput)
47+import Data.Attoparsec.Internal.Types (Chunk(..), Input(..), Parser(..), addS)
48+import Data.Attoparsec.Internal.Types (More(..))
5049import Data.ByteString (ByteString)
5150import Data.Text (Text)
52−#endif
51+import qualified Data.Attoparsec.Zepto as Z
5352
5453-- | Attempt a parse, and if it fails, rewind the input so that no
5554-- input appears to have been consumed.
@@ -75,11 +74,9 @@ infix 0 <?>
7574-- action.
7675choice :: Alternative f => [f a] -> f a
7776choice = foldr (<|>) empty
78−#if __GLASGOW_HASKELL__ >= 700
7977{-# SPECIALIZE choice :: [Parser ByteString a] -> Parser ByteString a #-}
8078{-# SPECIALIZE choice :: [Parser Text a] -> Parser Text a #-}
8179{-# SPECIALIZE choice :: [Z.Parser a] -> Z.Parser a #-}
82−#endif
8380
8481-- | @option x p@ tries to apply action @p@. If @p@ fails without
8582-- consuming input, it returns the value @x@, otherwise the value
@@ -88,11 +85,9 @@ choice = foldr (<|>) empty
8885-- > priority = option 0 (digitToInt <$> digit)
8986option :: Alternative f => a -> f a -> f a
9087option x p = p <|> pure x
91−#if __GLASGOW_HASKELL__ >= 700
9288{-# SPECIALIZE option :: a -> Parser ByteString a -> Parser ByteString a #-}
9389{-# SPECIALIZE option :: a -> Parser Text a -> Parser Text a #-}
9490{-# SPECIALIZE option :: a -> Z.Parser a -> Z.Parser a #-}
95−#endif
9691
9792-- | A version of 'liftM2' that is strict in the result of its first
9893-- action.
@@ -137,12 +132,10 @@ many1' p = liftM2' (:) p (many' p)
137132-- > commaSep p = p `sepBy` (symbol ",")
138133sepBy :: Alternative f => f a -> f s -> f [a]
139134sepBy p s = liftA2 (:) p ((s *> sepBy1 p s) <|> pure []) <|> pure []
140−#if __GLASGOW_HASKELL__ >= 700
141135{-# SPECIALIZE sepBy :: Parser ByteString a -> Parser ByteString s
142136 -> Parser ByteString [a] #-}
143137{-# SPECIALIZE sepBy :: Parser Text a -> Parser Text s -> Parser Text [a] #-}
144138{-# SPECIALIZE sepBy :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-}
145−#endif
146139
147140-- | @sepBy' p sep@ applies /zero/ or more occurrences of @p@, separated
148141-- by @sep@. Returns a list of the values returned by @p@. The value
@@ -152,12 +145,10 @@ sepBy p s = liftA2 (:) p ((s *> sepBy1 p s) <|> pure []) <|> pure []
152145sepBy' :: (MonadPlus m) => m a -> m s -> m [a]
153146sepBy' p s = scan `mplus` return []
154147 where scan = liftM2' (:) p ((s >> sepBy1' p s) `mplus` return [])
155−#if __GLASGOW_HASKELL__ >= 700
156148{-# SPECIALIZE sepBy' :: Parser ByteString a -> Parser ByteString s
157149 -> Parser ByteString [a] #-}
158150{-# SPECIALIZE sepBy' :: Parser Text a -> Parser Text s -> Parser Text [a] #-}
159151{-# SPECIALIZE sepBy' :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-}
160−#endif
161152
162153-- | @sepBy1 p sep@ applies /one/ or more occurrences of @p@, separated
163154-- by @sep@. Returns a list of the values returned by @p@.
@@ -166,12 +157,10 @@ sepBy' p s = scan `mplus` return []
166157sepBy1 :: Alternative f => f a -> f s -> f [a]
167158sepBy1 p s = scan
168159 where scan = liftA2 (:) p ((s *> scan) <|> pure [])
169−#if __GLASGOW_HASKELL__ >= 700
170160{-# SPECIALIZE sepBy1 :: Parser ByteString a -> Parser ByteString s
171161 -> Parser ByteString [a] #-}
172162{-# SPECIALIZE sepBy1 :: Parser Text a -> Parser Text s -> Parser Text [a] #-}
173163{-# SPECIALIZE sepBy1 :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-}
174−#endif
175164
176165-- | @sepBy1' p sep@ applies /one/ or more occurrences of @p@, separated
177166-- by @sep@. Returns a list of the values returned by @p@. The value
@@ -181,12 +170,10 @@ sepBy1 p s = scan
181170sepBy1' :: (MonadPlus m) => m a -> m s -> m [a]
182171sepBy1' p s = scan
183172 where scan = liftM2' (:) p ((s >> scan) `mplus` return [])
184−#if __GLASGOW_HASKELL__ >= 700
185173{-# SPECIALIZE sepBy1' :: Parser ByteString a -> Parser ByteString s
186174 -> Parser ByteString [a] #-}
187175{-# SPECIALIZE sepBy1' :: Parser Text a -> Parser Text s -> Parser Text [a] #-}
188176{-# SPECIALIZE sepBy1' :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-}
189−#endif
190177
191178-- | @manyTill p end@ applies action @p@ /zero/ or more times until
192179-- action @end@ succeeds, and returns the list of values returned by
@@ -199,12 +186,10 @@ sepBy1' p s = scan
199186manyTill :: Alternative f => f a -> f b -> f [a]
200187manyTill p end = scan
201188 where scan = (end *> pure []) <|> liftA2 (:) p scan
202−#if __GLASGOW_HASKELL__ >= 700
203189{-# SPECIALIZE manyTill :: Parser ByteString a -> Parser ByteString b
204190 -> Parser ByteString [a] #-}
205191{-# SPECIALIZE manyTill :: Parser Text a -> Parser Text b -> Parser Text [a] #-}
206192{-# SPECIALIZE manyTill :: Z.Parser a -> Z.Parser b -> Z.Parser [a] #-}
207−#endif
208193
209194-- | @manyTill' p end@ applies action @p@ /zero/ or more times until
210195-- action @end@ succeeds, and returns the list of values returned by
@@ -218,31 +203,25 @@ manyTill p end = scan
218203manyTill' :: (MonadPlus m) => m a -> m b -> m [a]
219204manyTill' p end = scan
220205 where scan = (end >> return []) `mplus` liftM2' (:) p scan
221−#if __GLASGOW_HASKELL__ >= 700
222206{-# SPECIALIZE manyTill' :: Parser ByteString a -> Parser ByteString b
223207 -> Parser ByteString [a] #-}
224208{-# SPECIALIZE manyTill' :: Parser Text a -> Parser Text b -> Parser Text [a] #-}
225209{-# SPECIALIZE manyTill' :: Z.Parser a -> Z.Parser b -> Z.Parser [a] #-}
226−#endif
227210
228211-- | Skip zero or more instances of an action.
229212skipMany :: Alternative f => f a -> f ()
230213skipMany p = scan
231214 where scan = (p *> scan) <|> pure ()
232−#if __GLASGOW_HASKELL__ >= 700
233215{-# SPECIALIZE skipMany :: Parser ByteString a -> Parser ByteString () #-}
234216{-# SPECIALIZE skipMany :: Parser Text a -> Parser Text () #-}
235217{-# SPECIALIZE skipMany :: Z.Parser a -> Z.Parser () #-}
236−#endif
237218
238219-- | Skip one or more instances of an action.
239220skipMany1 :: Alternative f => f a -> f ()
240221skipMany1 p = p *> skipMany p
241−#if __GLASGOW_HASKELL__ >= 700
242222{-# SPECIALIZE skipMany1 :: Parser ByteString a -> Parser ByteString () #-}
243223{-# SPECIALIZE skipMany1 :: Parser Text a -> Parser Text () #-}
244224{-# SPECIALIZE skipMany1 :: Z.Parser a -> Z.Parser () #-}
245−#endif
246225
247226-- | Apply the given action repeatedly, returning every result.
248227count :: Monad m => Int -> m a -> m [a]
@@ -282,10 +261,8 @@ endOfInput = Parser $ \i0 a0 m0 kf ks ->
282261 "endOfInput"
283262 in runParser demandInput i0 a0 m0 kf' ks'
284263 else kf i0 a0 m0 [] "endOfInput"
285−#if __GLASGOW_HASKELL__ >= 700
286264{-# SPECIALIZE endOfInput :: Parser ByteString () #-}
287265{-# SPECIALIZE endOfInput :: Parser Text () #-}
288−#endif
289266
290267-- | Return an indication of whether the end of input has been
291268-- reached.