packages feed

replace-attoparsec 1.4.2.0 → 1.4.4.0

raw patch · 7 files changed

+37/−19 lines, 7 files

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for replace-attoparsec +## 1.4.4.0 -- 2021-01-08++Deprecate `findAll` and `findAllCap`.+ ## 1.4.2.0 -- 2020-09-28  Bugfix sepCap backtracking when sep fails
README.md view
@@ -211,10 +211,9 @@ let editThree :: Char -> MTL.State Int T.Text     editThree x = do         i <- get-        let i' = i+1-        if i'<=3+        if i<3             then do-                put i'+                put $ i+1                 pure $ T.singleton $ toUpper x             else pure $ T.singleton x @@ -236,7 +235,7 @@ #!/usr/bin/env stack {- stack   script-  --resolver lts-15+  --resolver lts-16   --package attoparsec   --package text   --package text-show
replace-attoparsec.cabal view
@@ -1,5 +1,5 @@ name:                replace-attoparsec-version:             1.4.2.0+version:             1.4.4.0 cabal-version:       1.18 synopsis:            Find, replace, and split string patterns with Attoparsec parsers (instead of regex) homepage:            https://github.com/jamesdbrock/replace-attoparsec
src/Replace/Attoparsec/ByteString.hs view
@@ -43,7 +43,8 @@   (     -- * Running parser     ---    -- | Functions in this section are ways to run parsers. They take+    -- | Functions in this section are /ways to run parsers/+    -- (like 'Data.Attoparsec.ByteString.parse'). They take     -- as arguments a @sep@ parser and some input, run the parser on the input,     -- and return a result.     breakCap@@ -52,7 +53,7 @@   , streamEditT     -- * Parser combinator     ---    -- | Functions in this section are parser combinators. They take+    -- | Functions in this section are /parser combinators/. They take     -- a @sep@ parser for an argument, combine @sep@ with another parser,     -- and return a new parser.   , anyTill@@ -214,7 +215,7 @@   -- |--- === Stream editor transformer+-- === Stream editor -- -- Monad transformer version of 'streamEdit'. --@@ -244,7 +245,7 @@         -- can never fail. If this function ever throws an error, please         -- report that as a bug.         -- (We don't use MonadFail because Identity is not a MonadFail.)-        (Right r) -> fmap mconcat $ traverse (either return editor) r+        (Right r) ->  mconcat <$> traverse (either return editor) r {-# INLINABLE streamEditT #-}  @@ -351,7 +352,7 @@                 -- the Maybe then the benchmarks get dramatically worse.                 thisiter <- (<|>)                     ( do-                        x <- try $ sep+                        x <- try sep                         !offsetAfter <- getOffset                         -- Don't allow a match of a zero-width pattern                         when (offsetAfter <= offsetThis) empty@@ -390,6 +391,7 @@     -> Parser [Either B.ByteString (B.ByteString, a)] -- ^ parser findAllCap sep = sepCap (match sep) {-# INLINABLE findAllCap #-}+{-# DEPRECATED findAllCap "replace with `findAllCap sep = sepCap (match sep)`" #-}   -- |@@ -411,6 +413,7 @@     -> Parser [Either B.ByteString B.ByteString] -- ^ parser findAll sep = (fmap.fmap) (second fst) $ sepCap (match sep) {-# INLINABLE findAll #-}+{-# DEPRECATED findAll "replace with `findAll sep = (fmap.fmap) (second fst) $ sepCap (match sep)`" #-}   -- |
src/Replace/Attoparsec/Text.hs view
@@ -43,7 +43,8 @@   (     -- * Running parser     ---    -- | Functions in this section are ways to run parsers. They take+    -- | Functions in this section are /ways to run parsers/+    -- (like 'Data.Attoparsec.Text.parse'). They take     -- as arguments a @sep@ parser and some input, run the parser on the input,     -- and return a result.     breakCap@@ -52,7 +53,7 @@   , streamEditT     -- * Parser combinator     ---    -- | Functions in this section are parser combinators. They take+    -- | Functions in this section are /parser combinators/. They take     -- a @sep@ parser for an argument, combine @sep@ with another parser,     -- and return a new parser.   , anyTill@@ -215,7 +216,7 @@   -- |--- === Stream editor transformer+-- === Stream editor -- -- Monad transformer version of 'streamEdit'. --@@ -389,6 +390,7 @@     -> Parser [Either T.Text (T.Text, a)] -- ^ parser findAllCap sep = sepCap (match sep) {-# INLINABLE findAllCap #-}+{-# DEPRECATED findAllCap "replace with `findAllCap sep = sepCap (match sep)`" #-}  -- | -- === Find all occurences@@ -409,6 +411,7 @@     -> Parser [Either T.Text T.Text] -- ^ parser findAll sep = (fmap.fmap) (second fst) $ sepCap (match sep) {-# INLINABLE findAll #-}+{-# DEPRECATED findAll "replace with `findAll sep = (fmap.fmap) (second fst) $ sepCap (match sep)`" #-}   -- Get the 'Data.Attoparsec.Internal.Types.Parser' current offset
tests/TestByteString.hs view
@@ -14,10 +14,13 @@ import Replace.Attoparsec.ByteString import Control.Applicative +findAllCap' :: Parser a -> Parser [Either B.ByteString (B.ByteString, a)]+findAllCap' sep = sepCap (match sep)+ tests :: IO [Test] tests = return-    [ Test $ runParserTest "findAll upperChar"-        (findAllCap upperChar)+    [ Test $ runParserTest "findAllCap upperChar"+        (findAllCap' upperChar)         ("aBcD" :: B.ByteString)         [Left "a", Right ("B", c2w 'B'), Left "c", Right ("D", c2w 'D')]     -- check that sepCap can progress even when parser consumes nothing
tests/TestText.hs view
@@ -11,11 +11,17 @@ import qualified Data.Text as T import Text.Parser.Char (upper) import Control.Applicative+import Data.Bifunctor +findAllCap' :: Parser a -> Parser [Either T.Text (T.Text, a)]+findAllCap' sep = sepCap (match sep)+findAll' :: Parser b -> Parser [Either T.Text T.Text]+findAll' sep = (fmap.fmap) (second fst) $ sepCap (match sep)+ tests :: IO [Test] tests = return-    [ Test $ runParserTest "findAll upperChar"-        (findAllCap (upper :: Parser Char))+    [ Test $ runParserTest "findAllCap upperChar"+        (findAllCap' (upper :: Parser Char))         ("aBcD" :: T.Text)         [Left "a", Right ("B", 'B'), Left "c", Right ("D", 'D')]     -- check that sepCap can progress even when parser consumes nothing@@ -39,7 +45,7 @@         ([Left "a"]) #endif     , Test $ runParserTest "findAll astral"-        (findAll ((A.takeWhile (=='𝅘𝅥𝅯') :: Parser T.Text)))+        (findAll' ((A.takeWhile (=='𝅘𝅥𝅯') :: Parser T.Text)))         ("𝄞𝅘𝅥𝅘𝅥𝅘𝅥𝅘𝅥𝅘𝅥𝅯𝅘𝅥𝅯𝅘𝅥𝅯𝅘𝅥𝅯𝅘𝅥𝅘𝅥𝅘𝅥𝅘𝅥" :: T.Text)         [Left "𝄞𝅘𝅥𝅘𝅥𝅘𝅥𝅘𝅥", Right "𝅘𝅥𝅯𝅘𝅥𝅯𝅘𝅥𝅯𝅘𝅥𝅯", Left "𝅘𝅥𝅘𝅥𝅘𝅥𝅘𝅥"]     , Test $ runParserFeed "const string"@@ -47,7 +53,7 @@         (" a") ("a ")         ([Left " ",Right"aa",Left" "])     , Test $ runParserFeed "findAll astral"-        (findAll ((A.takeWhile (=='𝅘𝅥𝅯') :: Parser T.Text)))+        (findAll' ((A.takeWhile (=='𝅘𝅥𝅯') :: Parser T.Text)))         ("𝄞𝅘𝅥𝅘𝅥𝅘𝅥𝅘𝅥𝅘𝅥𝅯𝅘𝅥𝅯") ("𝅘𝅥𝅯𝅘𝅥𝅯𝅘𝅥𝅘𝅥𝅘𝅥𝅘𝅥" :: T.Text)         [Left "𝄞𝅘𝅥𝅘𝅥𝅘𝅥𝅘𝅥", Right "𝅘𝅥𝅯𝅘𝅥𝅯𝅘𝅥𝅯𝅘𝅥𝅯", Left "𝅘𝅥𝅘𝅥𝅘𝅥𝅘𝅥"]     , Test $ runParserTest "empty input" (sepCap (fail "" :: Parser ())) "" []