packages feed

attoparsec 0.8.5.3 → 0.8.6.0

raw patch · 7 files changed

+234/−160 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Data/Attoparsec.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Data.Attoparsec--- Copyright   :  Bryan O'Sullivan 2007-2010+-- Copyright   :  Bryan O'Sullivan 2007-2011 -- License     :  BSD3 --  -- Maintainer  :  bos@serpentine.com
Data/Attoparsec/Char8.hs view
@@ -417,6 +417,9 @@ -- -- >rational "3.foo" == Done 3.0 ".foo" -- >rational "3e"    == Done 3.0 "e"+--+-- This function does not accept string representations of \"NaN\" or+-- \"Infinity\". rational :: Fractional a => Parser a {-# SPECIALIZE rational :: Parser Double #-} {-# SPECIALIZE rational :: Parser Float #-}@@ -436,6 +439,9 @@ -- results, but for the remaining 5.8%, this function loses precision -- around the 15th decimal place.  For 0.001% of numbers, this -- function will lose precision at the 13th or 14th decimal place.+--+-- This function does not accept string representations of \"NaN\" or+-- \"Infinity\". double :: Parser Double double = floaty asDouble @@ -452,6 +458,9 @@ -- On integral inputs, it gives perfectly accurate answers, and on -- floating point inputs, it is slightly less accurate than -- 'rational'.+--+-- This function does not accept string representations of \"NaN\" or+-- \"Infinity\". number :: Parser Number number = floaty $ \real frac fracDenom ->          if frac == 0 && fracDenom == 0
Data/Attoparsec/Combinator.hs view
@@ -33,11 +33,15 @@  import Control.Applicative (Alternative, Applicative(..), empty, liftA2,                             (<|>), (*>), (<$>))+import Data.Attoparsec.Internal.Types (Parser)+import qualified Data.Attoparsec.Zepto as Z  -- | @choice ps@ tries to apply the actions in the list @ps@ in order, -- until one of them succeeds. Returns the value of the succeeding -- action. choice :: Alternative f => [f a] -> f a+{-# SPECIALIZE choice :: [Parser a] -> Parser a #-}+{-# SPECIALIZE choice :: [Z.Parser a] -> Z.Parser a #-} choice = foldr (<|>) empty  -- | @option x p@ tries to apply action @p@. If @p@ fails without@@ -46,6 +50,8 @@ -- -- > priority  = option 0 (digitToInt <$> digit) option :: Alternative f => a -> f a -> f a+{-# SPECIALIZE option :: a -> Parser a -> Parser a #-}+{-# SPECIALIZE option :: a -> Z.Parser a -> Z.Parser a #-} option x p = p <|> pure x  -- | @many1 p@ applies the action @p@ /one/ or more times. Returns a@@ -61,6 +67,8 @@ -- -- > commaSep p  = p `sepBy` (symbol ",") sepBy :: Alternative f => f a -> f s -> f [a]+{-# SPECIALIZE sepBy :: Parser a -> Parser s -> Parser [a] #-}+{-# SPECIALIZE sepBy :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-} sepBy p s = liftA2 (:) p ((s *> sepBy1 p s) <|> pure []) <|> pure []  -- | @sepBy1 p sep@ applies /one/ or more occurrences of @p@, separated@@ -68,6 +76,8 @@ -- -- > commaSep p  = p `sepBy` (symbol ",") sepBy1 :: Alternative f => f a -> f s -> f [a]+{-# SPECIALIZE sepBy1 :: Parser a -> Parser s -> Parser [a] #-}+{-# SPECIALIZE sepBy1 :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-} sepBy1 p s = scan     where scan = liftA2 (:) p ((s *> scan) <|> pure []) @@ -80,16 +90,22 @@ -- Note the overlapping parsers @anyChar@ and @string \"<!--\"@, and -- therefore the use of the 'try' combinator. manyTill :: Alternative f => f a -> f b -> f [a]+{-# SPECIALIZE manyTill :: Parser a -> Parser b -> Parser [a] #-}+{-# SPECIALIZE manyTill :: Z.Parser a -> Z.Parser b -> Z.Parser [a] #-} manyTill p end = scan     where scan = (end *> pure []) <|> liftA2 (:) p scan  -- | Skip zero or more instances of an action. skipMany :: Alternative f => f a -> f ()+{-# SPECIALIZE skipMany :: Parser a -> Parser () #-}+{-# SPECIALIZE skipMany :: Z.Parser a -> Z.Parser () #-} skipMany p = scan     where scan = (p *> scan) <|> pure ()  -- | Skip one or more instances of an action. skipMany1 :: Alternative f => f a -> f ()+{-# SPECIALIZE skipMany1 :: Parser a -> Parser () #-}+{-# SPECIALIZE skipMany1 :: Z.Parser a -> Z.Parser () #-} skipMany1 p = p *> skipMany p  -- | Apply the given action repeatedly, returning every result.
Data/Attoparsec/Internal.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE BangPatterns, Rank2Types, OverloadedStrings, RecordWildCards #-} -- | -- Module      :  Data.Attoparsec.Internal--- Copyright   :  Bryan O'Sullivan 2007-2010+-- Copyright   :  Bryan O'Sullivan 2007-2011 -- License     :  BSD3 -- -- Maintainer  :  bos@serpentine.com@@ -64,12 +64,11 @@     , endOfLine     ) where -import Control.Applicative (Alternative(..), Applicative(..), (<$>))-import Control.DeepSeq (NFData(rnf))-import Control.Monad (MonadPlus(..), when)+import Control.Applicative ((<|>), (<$>))+import Control.Monad (when) import Data.Attoparsec.Combinator import Data.Attoparsec.FastSet (charClass, memberWord8)-import Data.Monoid (Monoid(..))+import Data.Attoparsec.Internal.Types import Data.Word (Word8) import Foreign.ForeignPtr (withForeignPtr) import Foreign.Ptr (castPtr, minusPtr, plusPtr)@@ -79,148 +78,8 @@ import qualified Data.ByteString as B8 import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Internal as B-import qualified Data.ByteString.Unsafe as B import qualified Data.ByteString.Lazy as L---- | The result of a parse.-data Result r = Fail B.ByteString [String] String-              -- ^ The parse failed.  The 'B.ByteString' is the input-              -- that had not yet been consumed when the failure-              -- occurred.  The @[@'String'@]@ is a list of contexts-              -- in which the error occurred.  The 'String' is the-              -- message describing the error, if any.-              | Partial (B.ByteString -> Result r)-              -- ^ Supply this continuation with more input so that-              -- the parser can resume.  To indicate that no more-              -- input is available, use an 'B.empty' string.-              | Done B.ByteString r-              -- ^ The parse succeeded.  The 'B.ByteString' is the-              -- input that had not yet been consumed (if any) when-              -- the parse succeeded.--instance Show r => Show (Result r) where-    show (Fail bs stk msg) =-        "Fail " ++ show bs ++ " " ++ show stk ++ " " ++ show msg-    show (Partial _)       = "Partial _"-    show (Done bs r)       = "Done " ++ show bs ++ " " ++ show r--instance (NFData r) => NFData (Result r) where-    rnf (Fail _ _ _) = ()-    rnf (Partial _)  = ()-    rnf (Done _ r)   = rnf r-    {-# INLINE rnf #-}--fmapR :: (a -> b) -> Result a -> Result b-fmapR _ (Fail st stk msg) = Fail st stk msg-fmapR f (Partial k)       = Partial (fmapR f . k)-fmapR f (Done bs r)       = Done bs (f r)--instance Functor Result where-    fmap = fmapR--newtype Input = I {unI :: B.ByteString}-newtype Added = A {unA :: B.ByteString}---- | The 'Parser' type is a monad.-newtype Parser a = Parser {-      runParser :: forall r. Input -> Added -> More-                -> Failure   r-                -> Success a r-                -> Result r-    }--type Failure   r = Input -> Added -> More -> [String] -> String -> Result r-type Success a r = Input -> Added -> More -> a -> Result r---- | Have we read all available input?-data More = Complete | Incomplete-            deriving (Eq, Show)--addS :: Input -> Added -> More-     -> Input -> Added -> More-     -> (Input -> Added -> More -> r) -> r-addS i0 a0 m0 _i1 a1 m1 f =-    let !i = I (unI i0 +++ unA a1)-        a  = A (unA a0 +++ unA a1)-        !m = m0 <> m1-    in f i a m-  where-    Complete <> _ = Complete-    _ <> Complete = Complete-    _ <> _        = Incomplete-{-# INLINE addS #-}--bindP :: Parser a -> (a -> Parser b) -> Parser b-bindP m g =-    Parser $ \i0 a0 m0 kf ks -> runParser m i0 a0 m0 kf $-                                \i1 a1 m1 a -> runParser (g a) i1 a1 m1 kf ks-{-# INLINE bindP #-}--returnP :: a -> Parser a-returnP a = Parser (\i0 a0 m0 _kf ks -> ks i0 a0 m0 a)-{-# INLINE returnP #-}--instance Monad Parser where-    return = returnP-    (>>=)  = bindP-    fail   = failDesc--noAdds :: Input -> Added -> More-       -> (Input -> Added -> More -> r) -> r-noAdds i0 _a0 m0 f = f i0 (A B.empty) m0-{-# INLINE noAdds #-}--plus :: Parser a -> Parser a -> Parser a-plus a b = Parser $ \i0 a0 m0 kf ks ->-           let kf' i1 a1 m1 _ _ = addS i0 a0 m0 i1 a1 m1 $-                                  \ i2 a2 m2 -> runParser b i2 a2 m2 kf ks-           in  noAdds i0 a0 m0 $ \i2 a2 m2 -> runParser a i2 a2 m2 kf' ks-{-# INLINE plus #-}--instance MonadPlus Parser where-    mzero = failDesc "mzero"-    {-# INLINE mzero #-}-    mplus = plus--fmapP :: (a -> b) -> Parser a -> Parser b-fmapP p m = Parser $ \i0 a0 m0 f k ->-            runParser m i0 a0 m0 f $ \i1 a1 s1 a -> k i1 a1 s1 (p a)-{-# INLINE fmapP #-}--instance Functor Parser where-    fmap = fmapP--apP :: Parser (a -> b) -> Parser a -> Parser b-apP d e = do-  b <- d-  a <- e-  return (b a)-{-# INLINE apP #-}--instance Applicative Parser where-    pure   = returnP-    (<*>)  = apP--    -- These definitions are equal to the defaults, but this-    -- way the optimizer doesn't have to work so hard to figure-    -- that out.-    (*>)   = (>>)-    x <* y = x >>= \a -> y >> return a--instance Monoid (Parser a) where-    mempty  = failDesc "mempty"-    {-# INLINE mempty #-}-    mappend = plus--instance Alternative Parser where-    empty = failDesc "empty"-    {-# INLINE empty #-}-    (<|>) = plus--failDesc :: String -> Parser a-failDesc err = Parser (\i0 a0 m0 kf _ks -> kf i0 a0 m0 [] msg)-    where msg = "Failed reading: " ++ err-{-# INLINE failDesc #-}+import qualified Data.ByteString.Unsafe as B  -- | If at least @n@ bytes of input are available, return the current -- input, otherwise fail.@@ -269,10 +128,6 @@ put :: B.ByteString -> Parser () put s = Parser $ \_i0 a0 m0 _kf ks -> ks (I s) a0 m0 () -(+++) :: B.ByteString -> B.ByteString -> B.ByteString-(+++) = B.append-{-# INLINE (+++) #-}- -- | Attempt a parse, and if it fails, rewind the input so that no -- input appears to have been consumed. --@@ -328,7 +183,7 @@  where   hack :: Storable b => b -> Parser b   hack dummy = do-    (fp,o,_) <- B.toForeignPtr `fmapP` take (sizeOf dummy)+    (fp,o,_) <- B.toForeignPtr `fmap` take (sizeOf dummy)     return . B.inlinePerformIO . withForeignPtr fp $ \p ->         peek (castPtr $ p `plusPtr` o) @@ -341,7 +196,7 @@       t = B.unsafeDrop n s   if p h     then put t >> return h-    else failDesc "takeWith"+    else fail "takeWith"  -- | Consume exactly @n@ bytes of input. take :: Int -> Parser B.ByteString@@ -498,10 +353,10 @@ takeWhile1 p = do   (`when` demandInput) =<< B.null <$> get   (h,t) <- B8.span p <$> get-  when (B.null h) $ failDesc "takeWhile1"+  when (B.null h) $ fail "takeWhile1"   put t   if B.null t-    then (h+++) `fmapP` takeWhile p+    then (h+++) `fmap` takeWhile p     else return h  -- | Match any byte in a set.
+ Data/Attoparsec/Internal/Types.hs view
@@ -0,0 +1,185 @@+{-# LANGUAGE BangPatterns, Rank2Types, OverloadedStrings, RecordWildCards #-}+-- |+-- Module      :  Data.Attoparsec.Internal.Types+-- Copyright   :  Bryan O'Sullivan 2007-2011+-- License     :  BSD3+--+-- Maintainer  :  bos@serpentine.com+-- Stability   :  experimental+-- Portability :  unknown+--+-- Simple, efficient parser combinators for 'B.ByteString' strings,+-- loosely based on the Parsec library.++module Data.Attoparsec.Internal.Types+    (+      Parser(..)+    , Failure+    , Success+    , Result(..)+    , Input(..)+    , Added(..)+    , More(..)+    , addS+    , noAdds+    , (+++)+    ) where++import Control.Applicative (Alternative(..), Applicative(..))+import Control.DeepSeq (NFData(rnf))+import Control.Monad (MonadPlus(..))+import Data.Monoid (Monoid(..))+import Prelude hiding (getChar, take, takeWhile)+import qualified Data.ByteString.Char8 as B++-- | The result of a parse.+data Result r = Fail B.ByteString [String] String+              -- ^ The parse failed.  The 'B.ByteString' is the input+              -- that had not yet been consumed when the failure+              -- occurred.  The @[@'String'@]@ is a list of contexts+              -- in which the error occurred.  The 'String' is the+              -- message describing the error, if any.+              | Partial (B.ByteString -> Result r)+              -- ^ Supply this continuation with more input so that+              -- the parser can resume.  To indicate that no more+              -- input is available, use an 'B.empty' string.+              | Done B.ByteString r+              -- ^ The parse succeeded.  The 'B.ByteString' is the+              -- input that had not yet been consumed (if any) when+              -- the parse succeeded.++instance Show r => Show (Result r) where+    show (Fail bs stk msg) =+        "Fail " ++ show bs ++ " " ++ show stk ++ " " ++ show msg+    show (Partial _)       = "Partial _"+    show (Done bs r)       = "Done " ++ show bs ++ " " ++ show r++instance (NFData r) => NFData (Result r) where+    rnf (Fail _ _ _) = ()+    rnf (Partial _)  = ()+    rnf (Done _ r)   = rnf r+    {-# INLINE rnf #-}++fmapR :: (a -> b) -> Result a -> Result b+fmapR _ (Fail st stk msg) = Fail st stk msg+fmapR f (Partial k)       = Partial (fmapR f . k)+fmapR f (Done bs r)       = Done bs (f r)++instance Functor Result where+    fmap = fmapR+    {-# INLINE fmap #-}++newtype Input = I {unI :: B.ByteString}+newtype Added = A {unA :: B.ByteString}++-- | The 'Parser' type is a monad.+newtype Parser a = Parser {+      runParser :: forall r. Input -> Added -> More+                -> Failure   r+                -> Success a r+                -> Result r+    }++type Failure   r = Input -> Added -> More -> [String] -> String -> Result r+type Success a r = Input -> Added -> More -> a -> Result r++-- | Have we read all available input?+data More = Complete | Incomplete+            deriving (Eq, Show)++addS :: Input -> Added -> More+     -> Input -> Added -> More+     -> (Input -> Added -> More -> r) -> r+addS i0 a0 m0 _i1 a1 m1 f =+    let !i = I (unI i0 +++ unA a1)+        a  = A (unA a0 +++ unA a1)+        !m = m0 <> m1+    in f i a m+  where+    Complete <> _ = Complete+    _ <> Complete = Complete+    _ <> _        = Incomplete+{-# INLINE addS #-}++bindP :: Parser a -> (a -> Parser b) -> Parser b+bindP m g =+    Parser $ \i0 a0 m0 kf ks -> runParser m i0 a0 m0 kf $+                                \i1 a1 m1 a -> runParser (g a) i1 a1 m1 kf ks+{-# INLINE bindP #-}++returnP :: a -> Parser a+returnP a = Parser (\i0 a0 m0 _kf ks -> ks i0 a0 m0 a)+{-# INLINE returnP #-}++instance Monad Parser where+    return = returnP+    (>>=)  = bindP+    fail   = failDesc++noAdds :: Input -> Added -> More+       -> (Input -> Added -> More -> r) -> r+noAdds i0 _a0 m0 f = f i0 (A B.empty) m0+{-# INLINE noAdds #-}++plus :: Parser a -> Parser a -> Parser a+plus a b = Parser $ \i0 a0 m0 kf ks ->+           let kf' i1 a1 m1 _ _ = addS i0 a0 m0 i1 a1 m1 $+                                  \ i2 a2 m2 -> runParser b i2 a2 m2 kf ks+           in  noAdds i0 a0 m0 $ \i2 a2 m2 -> runParser a i2 a2 m2 kf' ks+{-# INLINE plus #-}++instance MonadPlus Parser where+    mzero = failDesc "mzero"+    {-# INLINE mzero #-}+    mplus = plus++fmapP :: (a -> b) -> Parser a -> Parser b+fmapP p m = Parser $ \i0 a0 m0 f k ->+            runParser m i0 a0 m0 f $ \i1 a1 s1 a -> k i1 a1 s1 (p a)+{-# INLINE fmapP #-}++instance Functor Parser where+    fmap = fmapP+    {-# INLINE fmap #-}++apP :: Parser (a -> b) -> Parser a -> Parser b+apP d e = do+  b <- d+  a <- e+  return (b a)+{-# INLINE apP #-}++instance Applicative Parser where+    pure   = returnP+    {-# INLINE pure #-}+    (<*>)  = apP+    {-# INLINE (<*>) #-}++    -- These definitions are equal to the defaults, but this+    -- way the optimizer doesn't have to work so hard to figure+    -- that out.+    (*>)   = (>>)+    {-# INLINE (*>) #-}+    x <* y = x >>= \a -> y >> return a+    {-# INLINE (<*) #-}++instance Monoid (Parser a) where+    mempty  = failDesc "mempty"+    {-# INLINE mempty #-}+    mappend = plus+    {-# INLINE mappend #-}++instance Alternative Parser where+    empty = failDesc "empty"+    {-# INLINE empty #-}+    (<|>) = plus+    {-# INLINE (<|>) #-}++failDesc :: String -> Parser a+failDesc err = Parser (\i0 a0 m0 kf _ks -> kf i0 a0 m0 [] msg)+    where msg = "Failed reading: " ++ err+{-# INLINE failDesc #-}++(+++) :: B.ByteString -> B.ByteString -> B.ByteString+(+++) = B.append+{-# INLINE (+++) #-}
Data/Attoparsec/Zepto.hs view
@@ -86,7 +86,9 @@  instance Applicative Parser where     pure   = return+    {-# INLINE pure #-}     (<*>)  = ap+    {-# INLINE (<*>) #-}  gets :: (S -> a) -> Parser a gets f = Parser $ \s -> (# OK (f s), s #)@@ -106,11 +108,13 @@     mempty  = fail "mempty"     {-# INLINE mempty #-}     mappend = mplus+    {-# INLINE mappend #-}  instance Alternative Parser where     empty = fail "empty"     {-# INLINE empty #-}     (<|>) = mplus+    {-# INLINE (<|>) #-}  -- | Consume input while the predicate returns 'True'. takeWhile :: (Word8 -> Bool) -> Parser ByteString
attoparsec.cabal view
@@ -1,16 +1,16 @@ name:            attoparsec-version:         0.8.5.3+version:         0.8.6.0 license:         BSD3 license-file:    LICENSE category:        Text, Parsing author:          Bryan O'Sullivan <bos@serpentine.com> maintainer:      Bryan O'Sullivan <bos@serpentine.com> stability:       experimental-tested-with:     GHC == 6.10.4, GHC == 6.12.3, GHC == 7.0.1+tested-with:     GHC == 6.10.4, GHC == 6.12.3, GHC == 7.0.3 synopsis:        Fast combinator parsing for bytestrings cabal-version:   >= 1.6-homepage:        http://bitbucket.org/bos/attoparsec-bug-reports:     http://bitbucket.org/bos/attoparsec/issues+homepage:        https://bitbucket.org/bos/attoparsec+bug-reports:     https://bitbucket.org/bos/attoparsec/issues build-type:      Simple description:     A fast parser combinator library, aimed particularly at dealing@@ -63,6 +63,7 @@                    Data.Attoparsec.Number                    Data.Attoparsec.Zepto   other-modules:   Data.Attoparsec.Internal+                   Data.Attoparsec.Internal.Types   ghc-options:     -Wall    if flag(developer)@@ -70,4 +71,8 @@  source-repository head   type:     mercurial-  location: http://bitbucket.org/bos/attoparsec+  location: https://bitbucket.org/bos/attoparsec++source-repository head+  type:     git+  location: https://github.com/bos/attoparsec