git.iko.soy/typeable/attoparsec
on master help sign in
Drop a bunch of CPP macros

--HG-- extra : amend_source : 7661c8b72a5853e1b7cccf3d822fafb4aaaf651d

commitc92fa373ae4fa9e19439eed67369a0ba97c324b2 authorBryan O'Sullivan <bos@serpentine.com> dateFri 14 Feb 2014, 16:24 (13 years ago) parent09e21e6
3 files changed+7−48
Data/Attoparsec/ByteString/Internal.hs+1−9 Data/Attoparsec/Combinator.hs+4−27 Data/Attoparsec/Internal.hs+2−12
Data/Attoparsec/ByteString/Internal.hs+1−9
@@ -1,4 +1,4 @@
1−{-# LANGUAGE BangPatterns, CPP, Rank2Types, OverloadedStrings,
1+{-# LANGUAGE BangPatterns, Rank2Types, OverloadedStrings,
22 RecordWildCards, MagicHash, UnboxedTuples #-}
33-- |
44-- Module : Data.Attoparsec.ByteString.Internal
@@ -82,12 +82,8 @@ import qualified Data.ByteString.Internal as B
8282import qualified Data.ByteString.Lazy as L
8383import qualified Data.ByteString.Unsafe as B
8484
85−#if defined(__GLASGOW_HASKELL__)
8685import GHC.Base (realWorld#)
8786import GHC.IO (IO(IO))
88−#else
89−import System.IO.Unsafe (unsafePerformIO)
90−#endif
9187
9288type Parser = T.Parser B.ByteString
9389type Result = IResult B.ByteString
@@ -408,9 +404,5 @@ parseOnly m s = case T.runParser m (I s) mempty Complete failK successK of
408404-- particular, you should do no memory allocation inside an
409405-- 'inlinePerformIO' block. On Hugs this is just @unsafePerformIO@.
410406inlinePerformIO :: IO a -> a
411−#if defined(__GLASGOW_HASKELL__)
412407inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r
413−#else
414−inlinePerformIO = unsafePerformIO
415−#endif
416408{-# INLINE inlinePerformIO #-}
Data/Attoparsec/Combinator.hs+4−27
@@ -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.
Data/Attoparsec/Internal.hs+2−12
@@ -1,4 +1,4 @@
1−{-# LANGUAGE CPP, BangPatterns #-}
1+{-# LANGUAGE BangPatterns #-}
22-- |
33-- Module : Data.Attoparsec.Internal
44-- Copyright : Bryan O'Sullivan 2012
@@ -22,11 +22,9 @@ module Data.Attoparsec.Internal
2222 , wantInput
2323 ) where
2424
25−#if __GLASGOW_HASKELL__ >= 700
25+import Data.Attoparsec.Internal.Types
2626import Data.ByteString (ByteString)
2727import Data.Text (Text)
28−#endif
29−import Data.Attoparsec.Internal.Types
3028
3129-- | Compare two 'IResult' values for equality.
3230--
@@ -59,7 +57,6 @@ ensure' !n0 i0 a0 m0 kf0 ks0 =
5957 if chunkLengthAtLeast (unI i) n
6058 then ks i a m (unI i)
6159 else runParser (demandInput >> go n) i a m kf ks
62−#if __GLASGOW_HASKELL__ >= 700
6360{-# SPECIALIZE ensure' :: Int -> Input ByteString -> Added ByteString -> More
6461 -> Failure ByteString r
6562 -> Success ByteString ByteString r
@@ -67,7 +64,6 @@ ensure' !n0 i0 a0 m0 kf0 ks0 =
6764{-# SPECIALIZE ensure' :: Int -> Input Text -> Added Text -> More
6865 -> Failure Text r -> Success Text Text r
6966 -> IResult Text r #-}
70−#endif
7167
7268-- | If at least @n@ elements of input are available, return the
7369-- current input, otherwise fail.
@@ -91,7 +87,6 @@ prompt i0 a0 _m0 kf ks = Partial $ \s ->
9187 if nullChunk s
9288 then kf i0 a0 Complete
9389 else ks (i0 <> I s) (a0 <> A s) Incomplete
94−#if __GLASGOW_HASKELL__ >= 700
9590{-# SPECIALIZE prompt :: Input ByteString -> Added ByteString -> More
9691 -> (Input ByteString -> Added ByteString -> More
9792 -> IResult ByteString r)
@@ -102,7 +97,6 @@ prompt i0 a0 _m0 kf ks = Partial $ \s ->
10297 -> (Input Text -> Added Text -> More -> IResult Text r)
10398 -> (Input Text -> Added Text-> More -> IResult Text r)
10499 -> IResult Text r #-}
105−#endif
106100
107101-- | Immediately demand more input via a 'Partial' continuation
108102-- result.
@@ -113,10 +107,8 @@ demandInput = Parser $ \i0 a0 m0 kf ks ->
113107 else let kf' i a m = kf i a m ["demandInput"] "not enough input"
114108 ks' i a m = ks i a m ()
115109 in prompt i0 a0 m0 kf' ks'
116−#if __GLASGOW_HASKELL__ >= 700
117110{-# SPECIALIZE demandInput :: Parser ByteString () #-}
118111{-# SPECIALIZE demandInput :: Parser Text () #-}
119−#endif
120112
121113-- | This parser always succeeds. It returns 'True' if any input is
122114-- available either immediately or on demand, and 'False' if the end
@@ -129,7 +121,5 @@ wantInput = Parser $ \i0 a0 m0 _kf ks ->
129121 | otherwise -> let kf' i a m = ks i a m False
130122 ks' i a m = ks i a m True
131123 in prompt i0 a0 m0 kf' ks'
132−#if __GLASGOW_HASKELL__ >= 700
133124{-# SPECIALIZE wantInput :: Parser ByteString Bool #-}
134125{-# SPECIALIZE wantInput :: Parser Text Bool #-}
135−#endif