Commits

Bryan O'Sullivan  committed f3a1545

Drop a bunch of CPP macros

  • Participants
  • Parent commits 0afd100

Comments (0)

Files changed (3)

File Data/Attoparsec/ByteString/Internal.hs

-{-# LANGUAGE BangPatterns, CPP, Rank2Types, OverloadedStrings,
+{-# LANGUAGE BangPatterns, Rank2Types, OverloadedStrings,
     RecordWildCards, MagicHash, UnboxedTuples #-}
 -- |
 -- Module      :  Data.Attoparsec.ByteString.Internal
 import qualified Data.ByteString.Lazy as L
 import qualified Data.ByteString.Unsafe as B
 
-#if defined(__GLASGOW_HASKELL__)
 import GHC.Base (realWorld#)
 import GHC.IO (IO(IO))
-#else
-import System.IO.Unsafe (unsafePerformIO)
-#endif
 
 type Parser = T.Parser B.ByteString
 type Result = IResult B.ByteString
 -- particular, you should do no memory allocation inside an
 -- 'inlinePerformIO' block. On Hugs this is just @unsafePerformIO@.
 inlinePerformIO :: IO a -> a
-#if defined(__GLASGOW_HASKELL__)
 inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r
-#else
-inlinePerformIO = unsafePerformIO
-#endif
 {-# INLINE inlinePerformIO #-}

File Data/Attoparsec/Combinator.hs

 import Control.Applicative (many)
 #endif
 
-import Data.Attoparsec.Internal.Types
-import Data.Attoparsec.Internal
-#if __GLASGOW_HASKELL__ >= 700
-import qualified Data.Attoparsec.Zepto as Z
+import Data.Attoparsec.Internal (demandInput, ensure, put, wantInput)
+import Data.Attoparsec.Internal.Types (Chunk(..), Input(..), Parser(..), addS)
+import Data.Attoparsec.Internal.Types (More(..))
 import Data.ByteString (ByteString)
 import Data.Text (Text)
-#endif
+import qualified Data.Attoparsec.Zepto as Z
 
 -- | Attempt a parse, and if it fails, rewind the input so that no
 -- input appears to have been consumed.
 -- action.
 choice :: Alternative f => [f a] -> f a
 choice = foldr (<|>) empty
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE choice :: [Parser ByteString a] -> Parser ByteString a #-}
 {-# SPECIALIZE choice :: [Parser Text a] -> Parser Text a #-}
 {-# SPECIALIZE choice :: [Z.Parser a] -> Z.Parser a #-}
-#endif
 
 -- | @option x p@ tries to apply action @p@. If @p@ fails without
 -- consuming input, it returns the value @x@, otherwise the value
 -- > priority  = option 0 (digitToInt <$> digit)
 option :: Alternative f => a -> f a -> f a
 option x p = p <|> pure x
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE option :: a -> Parser ByteString a -> Parser ByteString a #-}
 {-# SPECIALIZE option :: a -> Parser Text a -> Parser Text a #-}
 {-# SPECIALIZE option :: a -> Z.Parser a -> Z.Parser a #-}
-#endif
 
 -- | A version of 'liftM2' that is strict in the result of its first
 -- action.
 -- > commaSep p  = p `sepBy` (symbol ",")
 sepBy :: Alternative f => f a -> f s -> f [a]
 sepBy p s = liftA2 (:) p ((s *> sepBy1 p s) <|> pure []) <|> pure []
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE sepBy :: Parser ByteString a -> Parser ByteString s
                      -> Parser ByteString [a] #-}
 {-# SPECIALIZE sepBy :: Parser Text a -> Parser Text s -> Parser Text [a] #-}
 {-# SPECIALIZE sepBy :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-}
-#endif
 
 -- | @sepBy' p sep@ applies /zero/ or more occurrences of @p@, separated
 -- by @sep@. Returns a list of the values returned by @p@. The value
 sepBy' :: (MonadPlus m) => m a -> m s -> m [a]
 sepBy' p s = scan `mplus` return []
   where scan = liftM2' (:) p ((s >> sepBy1' p s) `mplus` return [])
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE sepBy' :: Parser ByteString a -> Parser ByteString s
                       -> Parser ByteString [a] #-}
 {-# SPECIALIZE sepBy' :: Parser Text a -> Parser Text s -> Parser Text [a] #-}
 {-# SPECIALIZE sepBy' :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-}
-#endif
 
 -- | @sepBy1 p sep@ applies /one/ or more occurrences of @p@, separated
 -- by @sep@. Returns a list of the values returned by @p@.
 sepBy1 :: Alternative f => f a -> f s -> f [a]
 sepBy1 p s = scan
     where scan = liftA2 (:) p ((s *> scan) <|> pure [])
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE sepBy1 :: Parser ByteString a -> Parser ByteString s
                       -> Parser ByteString [a] #-}
 {-# SPECIALIZE sepBy1 :: Parser Text a -> Parser Text s -> Parser Text [a] #-}
 {-# SPECIALIZE sepBy1 :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-}
-#endif
 
 -- | @sepBy1' p sep@ applies /one/ or more occurrences of @p@, separated
 -- by @sep@. Returns a list of the values returned by @p@. The value
 sepBy1' :: (MonadPlus m) => m a -> m s -> m [a]
 sepBy1' p s = scan
     where scan = liftM2' (:) p ((s >> scan) `mplus` return [])
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE sepBy1' :: Parser ByteString a -> Parser ByteString s
                        -> Parser ByteString [a] #-}
 {-# SPECIALIZE sepBy1' :: Parser Text a -> Parser Text s -> Parser Text [a] #-}
 {-# SPECIALIZE sepBy1' :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-}
-#endif
 
 -- | @manyTill p end@ applies action @p@ /zero/ or more times until
 -- action @end@ succeeds, and returns the list of values returned by
 manyTill :: Alternative f => f a -> f b -> f [a]
 manyTill p end = scan
     where scan = (end *> pure []) <|> liftA2 (:) p scan
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE manyTill :: Parser ByteString a -> Parser ByteString b
                         -> Parser ByteString [a] #-}
 {-# SPECIALIZE manyTill :: Parser Text a -> Parser Text b -> Parser Text [a] #-}
 {-# SPECIALIZE manyTill :: Z.Parser a -> Z.Parser b -> Z.Parser [a] #-}
-#endif
 
 -- | @manyTill' p end@ applies action @p@ /zero/ or more times until
 -- action @end@ succeeds, and returns the list of values returned by
 manyTill' :: (MonadPlus m) => m a -> m b -> m [a]
 manyTill' p end = scan
     where scan = (end >> return []) `mplus` liftM2' (:) p scan
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE manyTill' :: Parser ByteString a -> Parser ByteString b
                          -> Parser ByteString [a] #-}
 {-# SPECIALIZE manyTill' :: Parser Text a -> Parser Text b -> Parser Text [a] #-}
 {-# SPECIALIZE manyTill' :: Z.Parser a -> Z.Parser b -> Z.Parser [a] #-}
-#endif
 
 -- | Skip zero or more instances of an action.
 skipMany :: Alternative f => f a -> f ()
 skipMany p = scan
     where scan = (p *> scan) <|> pure ()
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE skipMany :: Parser ByteString a -> Parser ByteString () #-}
 {-# SPECIALIZE skipMany :: Parser Text a -> Parser Text () #-}
 {-# SPECIALIZE skipMany :: Z.Parser a -> Z.Parser () #-}
-#endif
 
 -- | Skip one or more instances of an action.
 skipMany1 :: Alternative f => f a -> f ()
 skipMany1 p = p *> skipMany p
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE skipMany1 :: Parser ByteString a -> Parser ByteString () #-}
 {-# SPECIALIZE skipMany1 :: Parser Text a -> Parser Text () #-}
 {-# SPECIALIZE skipMany1 :: Z.Parser a -> Z.Parser () #-}
-#endif
 
 -- | Apply the given action repeatedly, returning every result.
 count :: Monad m => Int -> m a -> m [a]
                                                             "endOfInput"
                        in  runParser demandInput i0 a0 m0 kf' ks'
              else kf i0 a0 m0 [] "endOfInput"
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE endOfInput :: Parser ByteString () #-}
 {-# SPECIALIZE endOfInput :: Parser Text () #-}
-#endif
 
 -- | Return an indication of whether the end of input has been
 -- reached.

File Data/Attoparsec/Internal.hs

-{-# LANGUAGE CPP, BangPatterns #-}
+{-# LANGUAGE BangPatterns #-}
 -- |
 -- Module      :  Data.Attoparsec.Internal
 -- Copyright   :  Bryan O'Sullivan 2012
     , wantInput
     ) where
 
-#if __GLASGOW_HASKELL__ >= 700
+import Data.Attoparsec.Internal.Types
 import Data.ByteString (ByteString)
 import Data.Text (Text)
-#endif
-import Data.Attoparsec.Internal.Types
 
 -- | Compare two 'IResult' values for equality.
 --
         if chunkLengthAtLeast (unI i) n
         then ks i a m (unI i)
         else runParser (demandInput >> go n) i a m kf ks
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE ensure' :: Int -> Input ByteString -> Added ByteString -> More
                        -> Failure ByteString r
                        -> Success ByteString ByteString r
 {-# SPECIALIZE ensure' :: Int -> Input Text -> Added Text -> More
                        -> Failure Text r -> Success Text Text r
                        -> IResult Text r #-}
-#endif
 
 -- | If at least @n@ elements of input are available, return the
 -- current input, otherwise fail.
     if nullChunk s
     then kf i0 a0 Complete
     else ks (i0 <> I s) (a0 <> A s) Incomplete
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE prompt :: Input ByteString -> Added ByteString -> More
                       -> (Input ByteString -> Added ByteString -> More
                           -> IResult ByteString r)
                       -> (Input Text -> Added Text -> More -> IResult Text r)
                       -> (Input Text -> Added Text-> More -> IResult Text r)
                       -> IResult Text r #-}
-#endif
 
 -- | Immediately demand more input via a 'Partial' continuation
 -- result.
     else let kf' i a m = kf i a m ["demandInput"] "not enough input"
              ks' i a m = ks i a m ()
          in prompt i0 a0 m0 kf' ks'
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE demandInput :: Parser ByteString () #-}
 {-# SPECIALIZE demandInput :: Parser Text () #-}
-#endif
 
 -- | This parser always succeeds.  It returns 'True' if any input is
 -- available either immediately or on demand, and 'False' if the end
       | otherwise       -> let kf' i a m = ks i a m False
                                ks' i a m = ks i a m True
                            in prompt i0 a0 m0 kf' ks'
-#if __GLASGOW_HASKELL__ >= 700
 {-# SPECIALIZE wantInput :: Parser ByteString Bool #-}
 {-# SPECIALIZE wantInput :: Parser Text Bool #-}
-#endif