packages feed

replace-megaparsec 1.4.2.0 → 1.4.3.0

raw patch · 6 files changed

+30/−7 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Replace.Megaparsec: splitCap :: forall e s a. (Ord e, Stream s, Tokens s ~ s) => Parsec e s a -> s -> [Either s a]
+ Replace.Megaparsec: splitCap :: forall e s a. (Ord e, Show e, Show (Token s), Stream s, Tokens s ~ s) => Parsec e s a -> s -> [Either s a]

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for replace-megaparsec +## 1.4.3.0 -- 2020-09-28++Bugfix sepCap backtracking when sep fails++See [#33](https://github.com/jamesdbrock/replace-megaparsec/issues/33)+ ## 1.4.1.0 -- 2020-05-07  anyTill use getInput instead of takeRest
replace-megaparsec.cabal view
@@ -1,5 +1,5 @@ name:                replace-megaparsec-version:             1.4.2.0+version:             1.4.3.0 cabal-version:       1.18 synopsis:            Find, replace, and split string patterns with Megaparsec parsers (instead of regex) homepage:            https://github.com/jamesdbrock/replace-megaparsec
src/Replace/Megaparsec.hs view
@@ -199,7 +199,7 @@ -- input == 'Data.Monoid.mconcat' ('Data.Bifunctor.second' 'Data.Tuple.fst' '<$>' output) -- @ splitCap-    :: forall e s a. (Ord e, Stream s, Tokens s ~ s)+    :: forall e s a. (Ord e, Show e, Show (Token s), Stream s, Tokens s ~ s)     => Parsec e s a         -- ^ The pattern matching parser @sep@     -> s@@ -208,7 +208,7 @@         -- ^ List of matching and non-matching input sections. splitCap sep input = do     case runParser (sepCap sep) "" input of-        (Left _) -> undefined -- sepCap can never fail+        (Left (ParseErrorBundle errs _)) -> error (show errs) -- undefined -- sepCap can never fail         (Right r) -> r {-# INLINABLE splitCap #-} 
src/Replace/Megaparsec/Internal/ByteString.hs view
@@ -49,7 +49,7 @@                 -- the Maybe then the benchmarks get dramatically worse.                 thisiter <- (<|>)                     ( do-                        x <- sep+                        x <- try sep                         restAfter <- getInput                         -- Don't allow a match of a zero-width pattern                         when (B.length restAfter >= B.length restThis) empty@@ -86,7 +86,7 @@   where     go = do       end <- getInput-      r <- optional sep+      r <- optional $ try sep       case r of         Nothing -> anySingle >> go         Just x -> pure (end, x)
src/Replace/Megaparsec/Internal/Text.hs view
@@ -50,7 +50,7 @@                 -- the Maybe then the benchmarks get dramatically worse.                 thisiter <- (<|>)                     ( do-                        x <- sep+                        x <- try sep                         restAfter@(Text _ _ afterLen) <- getInput                         -- Don't allow a match of a zero-width pattern                         when (afterLen >= thisLen) empty@@ -87,7 +87,7 @@   where     go = do       (Text _ _ thisLen) <- getInput-      r <- optional sep+      r <- optional $ try sep       case r of         Nothing -> anySingle >> go         Just x -> pure (thisLen, x)
tests/TestText.hs view
@@ -68,6 +68,10 @@     , Test $ breakCapTest "zero-width" (lookAhead (upperChar :: Parser Char)) "aAa" (Just ("a", 'A', "Aa"))     , Test $ breakCapTest "empty input" (upperChar :: Parser Char) "" Nothing     , Test $ breakCapTest "empty input zero-width" (return () :: Parser ()) "" (Just ("", (), ""))+    -- I was unable to write a failing test for+    -- https://github.com/jamesdbrock/replace-megaparsec/issues/33+    -- but adding this "sep backtrack" test anyway+    , Test $ splitCapTest "sep backtrack" (match $ between (string "{{") (string "}}") (T.pack <$> many (alphaNumChar <|> spaceChar) :: Parser T.Text)) "{{foo.}}" [Left "{{foo.}}"]     ]   where     runParserTest nam p input expected = TestInstance@@ -106,6 +110,19 @@                     else return (Finished $ TestSuite.Fail                                 $ "got " <> show output <> " expected " <> show expected)             , name = "breakCap " ++ nam+            , tags = []+            , options = []+            , setOption = \_ _ -> Left "no options supported"+            }++    splitCapTest nam sep input expected = TestInstance+            { run = do+                let output = splitCap sep input+                if (output == expected)+                    then return (Finished Pass)+                    else return (Finished $ TestSuite.Fail+                                $ "got " <> show output <> " expected " <> show expected)+            , name = "splitCap " ++ nam             , tags = []             , options = []             , setOption = \_ _ -> Left "no options supported"