attoparsec 0.9.0.0 → 0.9.1.1
raw patch · 5 files changed
+42/−57 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Attoparsec.Combinator: foldSepBy :: MonadPlus m => (a -> m a) -> m z -> a -> m a
Files
- Data/Attoparsec/Combinator.hs +0/−12
- Data/Attoparsec/Internal.hs +4/−18
- Data/Attoparsec/Internal/Types.hs +28/−26
- Data/Attoparsec/Number.hs +9/−0
- attoparsec.cabal +1/−1
Data/Attoparsec/Combinator.hs view
@@ -18,7 +18,6 @@ , manyTill , sepBy , sepBy1- , foldSepBy , skipMany , skipMany1 , eitherP@@ -34,7 +33,6 @@ import Control.Applicative (Alternative, Applicative(..), empty, liftA2, (<|>), (*>), (<$>))-import Control.Monad (MonadPlus(..)) #if __GLASGOW_HASKELL__ >= 700 import Data.Attoparsec.Internal.Types (Parser) import qualified Data.Attoparsec.Zepto as Z@@ -91,16 +89,6 @@ #if __GLASGOW_HASKELL__ >= 700 {-# SPECIALIZE sepBy1 :: Parser a -> Parser s -> Parser [a] #-} {-# SPECIALIZE sepBy1 :: Z.Parser a -> Z.Parser s -> Z.Parser [a] #-}-#endif--foldSepBy :: (MonadPlus m) => (a -> m a) -> m z -> a -> m a-foldSepBy p s z0 = go z0 `mplus` return z0- where go z = do- z' <- p z- (s >> go z') `mplus` return z'-#if __GLASGOW_HASKELL__ >= 700-{-# SPECIALIZE foldSepBy :: (a -> Parser a) -> Parser z -> a -> Parser a #-}-{-# SPECIALIZE foldSepBy :: (a -> Z.Parser a) -> Z.Parser z -> a -> Z.Parser a #-} #endif -- | @manyTill p end@ applies action @p@ /zero/ or more times until
Data/Attoparsec/Internal.hs view
@@ -69,7 +69,6 @@ import Data.Attoparsec.Combinator import Data.Attoparsec.FastSet (charClass, memberWord8) import Data.Attoparsec.Internal.Types-import Data.Monoid (Monoid(..)) import Data.Word (Word8) import Foreign.ForeignPtr (withForeignPtr) import Foreign.Ptr (castPtr, minusPtr, plusPtr)@@ -99,7 +98,7 @@ prompt i0 a0 _m0 kf ks = Partial $ \s -> if B.null s then kf i0 a0 Complete- else ks (i0 <> I s) (a0 <> Added s) Incomplete+ else ks (I (unI i0 +++ s)) (A (unA a0 +++ s)) Incomplete -- | Immediately demand more input via a 'Partial' continuation -- result.@@ -141,19 +140,6 @@ noAdds i0 a0 m0 $ \i1 a1 m1 -> let kf' i2 a2 m2 = addS i0 a0 m0 i2 a2 m2 kf in runParser p i1 a1 m1 kf' ks- where noAdds i0 _a0 m0 f = f i0 mempty m0- -addS :: Input -> Added -> More- -> Input -> Added -> More- -> (Input -> Added -> More -> r) -> r-addS i0 a0 m0 _i1 a1 m1 f =- let !i = case a1 of- Dropped -> i0- Added s -> i0 <> I s- !a = a0 <> a1- !m = m0 <> m1- in f i a m-{-# INLINE addS #-} -- | The parser @satisfy p@ succeeds for any byte for which the -- predicate @p@ returns 'True'. Returns the byte that is actually@@ -370,7 +356,7 @@ when (B.null h) $ fail "takeWhile1" put t if B.null t- then (h<>) <$> takeWhile p+ then (h+++) `fmap` takeWhile p else return h -- | Match any byte in a set.@@ -455,12 +441,12 @@ -- | Run a parser. parse :: Parser a -> B.ByteString -> Result a-parse m s = runParser m (I s) mempty Incomplete failK successK+parse m s = runParser m (I s) (A B.empty) Incomplete failK successK {-# INLINE parse #-} -- | Run a parser that cannot be resupplied via a 'Partial' result. parseOnly :: Parser a -> B.ByteString -> Either String a-parseOnly m s = case runParser m (I s) mempty Complete failK successK of+parseOnly m s = case runParser m (I s) (A B.empty) Complete failK successK of Fail _ _ err -> Left err Done _ a -> Right a _ -> error "parseOnly: impossible error!"
Data/Attoparsec/Internal/Types.hs view
@@ -20,7 +20,9 @@ , Input(..) , Added(..) , More(..)- , (<>)+ , addS+ , noAdds+ , (+++) ) where import Control.Applicative (Alternative(..), Applicative(..))@@ -68,21 +70,7 @@ {-# INLINE fmap #-} newtype Input = I {unI :: B.ByteString}- deriving (Show)--instance Monoid Input where- mempty = I B.empty- mappend (I a) (I b) = I (a <> b)--data Added = Dropped- | Added B.ByteString- deriving (Show)--instance Monoid Added where- mempty = Dropped- mappend a@Dropped _ = a- mappend a Dropped = a- mappend (Added a) (Added b) = Added (a <> b)+newtype Added = A {unA :: B.ByteString} -- | The 'Parser' type is a monad. newtype Parser a = Parser {@@ -99,11 +87,19 @@ data More = Complete | Incomplete deriving (Eq, Show) -instance Monoid More where- mempty = Incomplete- mappend Complete _ = Complete- mappend _ Complete = Complete- mappend _ _ = Incomplete+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 =@@ -120,10 +116,16 @@ (>>=) = 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 _ _ = runParser b i1 a1 m1 kf ks- in runParser a 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@@ -178,6 +180,6 @@ where msg = "Failed reading: " ++ err {-# INLINE failDesc #-} -(<>) :: (Monoid a) => a -> a -> a-(<>) = mappend-{-# INLINE (<>) #-}+(+++) :: B.ByteString -> B.ByteString -> B.ByteString+(+++) = B.append+{-# INLINE (+++) #-}
Data/Attoparsec/Number.hs view
@@ -54,8 +54,17 @@ (<) = binop (<) (<) {-# INLINE (<) #-} + (<=) = binop (<=) (<=)+ {-# INLINE (<=) #-}+ (>) = binop (>) (>) {-# INLINE (>) #-}++ (>=) = binop (>=) (>=)+ {-# INLINE (>=) #-}++ compare = binop compare compare+ {-# INLINE compare #-} instance Num Number where (+) = binop (((I$!).) . (+)) (((D$!).) . (+))
attoparsec.cabal view
@@ -1,5 +1,5 @@ name: attoparsec-version: 0.9.0.0+version: 0.9.1.1 license: BSD3 license-file: LICENSE category: Text, Parsing