packages feed

replace-megaparsec 1.4.4.0 → 1.4.5.0

raw patch · 3 files changed

+49/−4 lines, 3 files

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for replace-megaparsec +## 1.4.5.0 -- 2022-04-14++Minor documentation changes.++Confirmed tests pass for text v2.+ ## 1.4.4.0 -- 2020-12-04  Add `splitCapT` and `breakCapT`.
README.md view
@@ -74,9 +74,9 @@  * Regular expressions are only able to pattern-match   [regular](https://en.wikipedia.org/wiki/Chomsky_hierarchy#The_hierarchy)-  grammers.-  Megaparsec parsers are able pattern-match context-free grammers, and-  even context-sensitive grammers, if needed. See below for+  grammars.+  Megaparsec parsers are able pattern-match context-free grammars, and+  even context-sensitive grammars, if needed. See below for   an example of lifting a `Parser` into a `State` monad for context-sensitive   pattern-matching. @@ -246,6 +246,7 @@ "a a A a a" ``` + ### Pattern match, edit the matches, and count the edits with [`streamEditT`](https://hackage.haskell.org/package/replace-megaparsec/docs/Replace-Megaparsec.html#v:streamEditT)  Find and capitalize no more than three letters in a string, and return the @@ -273,6 +274,44 @@ ``` ```haskell ("A A A a a",3)+```+++### Non-greedy pattern repetition++This is not a feature of this library, but it’s+a useful technique to know.++How do we do non-greedy repetition of a pattern `p`, like we would in Regex+by writing `p*?`?++By using the+[`manyTill_`](https://hackage.haskell.org/package/parser-combinators/docs/Control-Monad-Combinators.html#v:manyTill_) combinator. To repeat pattern `p` non-greedily, write+`manyTill_ p q` where `q` is the entire rest of the parser.++For example, this parse fails because `many` repeats the pattern `letterChar`+greedily.++```haskell+flip parseMaybe "aab" $ do+  a <- many letterChar+  b <- single 'b'+  pure (a,b)+```+```haskell+Nothing+```++To repeat pattern `letterChar` non-greedily, use `manyTill_`.++```haskell+flip parseMaybe "aab" $ do+  (a,b) <- manyTill_ letterChar $ do+    single 'b'+  pure (a,b)+```+```haskell+Just ("aa",'b') ```  
replace-megaparsec.cabal view
@@ -1,5 +1,5 @@ name:                replace-megaparsec-version:             1.4.4.0+version:             1.4.5.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