@@ -33,11 +33,13 @@ module Data.Attoparsec.Combinator
3333
3434import Control.Applicative (Alternative, Applicative(..), empty, liftA2,
3535 (<|>), (*>), (<$>))
36+import Data.Attoparsec.Internal.Types (Parser)
3637
3738-- | @choice ps@ tries to apply the actions in the list @ps@ in order,
3839-- until one of them succeeds. Returns the value of the succeeding
3940-- action.
4041choice :: Alternative f => [f a] -> f a
42+{-# SPECIALIZE choice :: [Parser a] -> Parser a #-}
4143choice = foldr (<|>) empty
4244
4345-- | @option x p@ tries to apply action @p@. If @p@ fails without
@@ -46,6 +48,7 @@ choice = foldr (<|>) empty
4648--
4749-- > priority = option 0 (digitToInt <$> digit)
4850option :: Alternative f => a -> f a -> f a
51+{-# SPECIALIZE option :: a -> Parser a -> Parser a #-}
4952option x p = p <|> pure x
5053
5154-- | @many1 p@ applies the action @p@ /one/ or more times. Returns a
@@ -61,6 +64,7 @@ many1 p = liftA2 (:) p (many p)
6164--
6265-- > commaSep p = p `sepBy` (symbol ",")
6366sepBy :: Alternative f => f a -> f s -> f [a]
67+{-# SPECIALIZE sepBy :: Parser a -> Parser s -> Parser [a] #-}
6468sepBy p s = liftA2 (:) p ((s *> sepBy1 p s) <|> pure []) <|> pure []
6569
6670-- | @sepBy1 p sep@ applies /one/ or more occurrences of @p@, separated
@@ -68,6 +72,7 @@ sepBy p s = liftA2 (:) p ((s *> sepBy1 p s) <|> pure []) <|> pure []
6872--
6973-- > commaSep p = p `sepBy` (symbol ",")
7074sepBy1 :: Alternative f => f a -> f s -> f [a]
75+{-# SPECIALIZE sepBy1 :: Parser a -> Parser s -> Parser [a] #-}
7176sepBy1 p s = scan
7277 where scan = liftA2 (:) p ((s *> scan) <|> pure [])
7378
@@ -80,16 +85,19 @@ sepBy1 p s = scan
8085-- Note the overlapping parsers @anyChar@ and @string \"<!--\"@, and
8186-- therefore the use of the 'try' combinator.
8287manyTill :: Alternative f => f a -> f b -> f [a]
88+{-# SPECIALIZE manyTill :: Parser a -> Parser b -> Parser [a] #-}
8389manyTill p end = scan
8490 where scan = (end *> pure []) <|> liftA2 (:) p scan
8591
8692-- | Skip zero or more instances of an action.
8793skipMany :: Alternative f => f a -> f ()
94+{-# SPECIALIZE skipMany :: Parser a -> Parser () #-}
8895skipMany p = scan
8996 where scan = (p *> scan) <|> pure ()
9097
9198-- | Skip one or more instances of an action.
9299skipMany1 :: Alternative f => f a -> f ()
100+{-# SPECIALIZE skipMany1 :: Parser a -> Parser () #-}
93101skipMany1 p = p *> skipMany p
94102
95103-- | Apply the given action repeatedly, returning every result.