packages feed

regex-with-pcre 1.0.0.0 → 1.0.1.0

raw patch · 13 files changed

+1131/−61 lines, 13 filesdep +regex-pcre-textdep +textdep ~base-compatdep ~bytestringdep ~containersPVP ok

version bump matches the API change (PVP)

Dependencies added: regex-pcre-text, text

Dependency ranges changed: base-compat, bytestring, containers, regex, regex-base, regex-pcre-builtin, regex-tdfa, template-haskell, transformers, unordered-containers

API changes (from Hackage documentation)

+ Text.RE.PCRE.Text: (*=~) :: Text -> RE -> Matches Text
+ Text.RE.PCRE.Text: (*=~/) :: Text -> SearchReplace RE Text -> Text
+ Text.RE.PCRE.Text: (=~) :: (Typeable a, RegexContext Regex Text a) => Text -> RE -> a
+ Text.RE.PCRE.Text: (=~~) :: (Monad m, Functor m, Typeable a, RegexContext Regex Text a) => Text -> RE -> m a
+ Text.RE.PCRE.Text: (?=~) :: Text -> RE -> Match Text
+ Text.RE.PCRE.Text: (?=~/) :: Text -> SearchReplace RE Text -> Text
+ Text.RE.PCRE.Text: BlockInsensitive :: SimpleREOptions
+ Text.RE.PCRE.Text: BlockSensitive :: SimpleREOptions
+ Text.RE.PCRE.Text: MultilineInsensitive :: SimpleREOptions
+ Text.RE.PCRE.Text: MultilineSensitive :: SimpleREOptions
+ Text.RE.PCRE.Text: SearchReplace :: ~re -> ~s -> SearchReplace re s
+ Text.RE.PCRE.Text: [getSearch] :: SearchReplace re s -> ~re
+ Text.RE.PCRE.Text: [getTemplate] :: SearchReplace re s -> ~s
+ Text.RE.PCRE.Text: allMatches :: Matches a -> [Match a]
+ Text.RE.PCRE.Text: anyMatches :: Matches a -> Bool
+ Text.RE.PCRE.Text: compileRegex :: (Functor m, Monad m) => String -> m RE
+ Text.RE.PCRE.Text: compileRegexWith :: (Functor m, Monad m) => SimpleREOptions -> String -> m RE
+ Text.RE.PCRE.Text: compileSearchReplace :: (Monad m, Functor m, IsRegex RE s) => String -> String -> m (SearchReplace RE s)
+ Text.RE.PCRE.Text: compileSearchReplaceWith :: (Monad m, Functor m, IsRegex RE s) => SimpleREOptions -> String -> String -> m (SearchReplace RE s)
+ Text.RE.PCRE.Text: countMatches :: Matches a -> Int
+ Text.RE.PCRE.Text: cp :: QuasiQuoter
+ Text.RE.PCRE.Text: data Match a :: * -> *
+ Text.RE.PCRE.Text: data Matches a :: * -> *
+ Text.RE.PCRE.Text: data RE
+ Text.RE.PCRE.Text: data SearchReplace re s :: * -> * -> *
+ Text.RE.PCRE.Text: data SimpleREOptions :: *
+ Text.RE.PCRE.Text: ed :: QuasiQuoter
+ Text.RE.PCRE.Text: edBI :: QuasiQuoter
+ Text.RE.PCRE.Text: edBS :: QuasiQuoter
+ Text.RE.PCRE.Text: edBlockInsensitive :: QuasiQuoter
+ Text.RE.PCRE.Text: edBlockSensitive :: QuasiQuoter
+ Text.RE.PCRE.Text: edMI :: QuasiQuoter
+ Text.RE.PCRE.Text: edMS :: QuasiQuoter
+ Text.RE.PCRE.Text: edMultilineInsensitive :: QuasiQuoter
+ Text.RE.PCRE.Text: edMultilineSensitive :: QuasiQuoter
+ Text.RE.PCRE.Text: ed_ :: QuasiQuoter
+ Text.RE.PCRE.Text: escape :: (Functor m, Monad m) => (String -> String) -> String -> m RE
+ Text.RE.PCRE.Text: escapeREString :: String -> String
+ Text.RE.PCRE.Text: escapeWith :: (Functor m, Monad m) => SimpleREOptions -> (String -> String) -> String -> m RE
+ Text.RE.PCRE.Text: instance Text.RE.ZeInternals.Types.IsRegex.IsRegex Text.RE.ZeInternals.PCRE.RE Data.Text.Internal.Text
+ Text.RE.PCRE.Text: matchSource :: Match a -> a
+ Text.RE.PCRE.Text: matched :: Match a -> Bool
+ Text.RE.PCRE.Text: matchedText :: Match a -> Maybe a
+ Text.RE.PCRE.Text: matches :: Matches a -> [a]
+ Text.RE.PCRE.Text: matchesSource :: Matches a -> a
+ Text.RE.PCRE.Text: re :: QuasiQuoter
+ Text.RE.PCRE.Text: reBI :: QuasiQuoter
+ Text.RE.PCRE.Text: reBS :: QuasiQuoter
+ Text.RE.PCRE.Text: reBlockInsensitive :: QuasiQuoter
+ Text.RE.PCRE.Text: reBlockSensitive :: QuasiQuoter
+ Text.RE.PCRE.Text: reMI :: QuasiQuoter
+ Text.RE.PCRE.Text: reMS :: QuasiQuoter
+ Text.RE.PCRE.Text: reMultilineInsensitive :: QuasiQuoter
+ Text.RE.PCRE.Text: reMultilineSensitive :: QuasiQuoter
+ Text.RE.PCRE.Text: reSource :: RE -> String
+ Text.RE.PCRE.Text: re_ :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: (*=~) :: Text -> RE -> Matches Text
+ Text.RE.PCRE.Text.Lazy: (*=~/) :: Text -> SearchReplace RE Text -> Text
+ Text.RE.PCRE.Text.Lazy: (=~) :: (Typeable a, RegexContext Regex Text a) => Text -> RE -> a
+ Text.RE.PCRE.Text.Lazy: (=~~) :: (Monad m, Functor m, Typeable a, RegexContext Regex Text a) => Text -> RE -> m a
+ Text.RE.PCRE.Text.Lazy: (?=~) :: Text -> RE -> Match Text
+ Text.RE.PCRE.Text.Lazy: (?=~/) :: Text -> SearchReplace RE Text -> Text
+ Text.RE.PCRE.Text.Lazy: BlockInsensitive :: SimpleREOptions
+ Text.RE.PCRE.Text.Lazy: BlockSensitive :: SimpleREOptions
+ Text.RE.PCRE.Text.Lazy: MultilineInsensitive :: SimpleREOptions
+ Text.RE.PCRE.Text.Lazy: MultilineSensitive :: SimpleREOptions
+ Text.RE.PCRE.Text.Lazy: SearchReplace :: ~re -> ~s -> SearchReplace re s
+ Text.RE.PCRE.Text.Lazy: [getSearch] :: SearchReplace re s -> ~re
+ Text.RE.PCRE.Text.Lazy: [getTemplate] :: SearchReplace re s -> ~s
+ Text.RE.PCRE.Text.Lazy: allMatches :: Matches a -> [Match a]
+ Text.RE.PCRE.Text.Lazy: anyMatches :: Matches a -> Bool
+ Text.RE.PCRE.Text.Lazy: compileRegex :: (Functor m, Monad m) => String -> m RE
+ Text.RE.PCRE.Text.Lazy: compileRegexWith :: (Functor m, Monad m) => SimpleREOptions -> String -> m RE
+ Text.RE.PCRE.Text.Lazy: compileSearchReplace :: (Monad m, Functor m, IsRegex RE s) => String -> String -> m (SearchReplace RE s)
+ Text.RE.PCRE.Text.Lazy: compileSearchReplaceWith :: (Monad m, Functor m, IsRegex RE s) => SimpleREOptions -> String -> String -> m (SearchReplace RE s)
+ Text.RE.PCRE.Text.Lazy: countMatches :: Matches a -> Int
+ Text.RE.PCRE.Text.Lazy: cp :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: data Match a :: * -> *
+ Text.RE.PCRE.Text.Lazy: data Matches a :: * -> *
+ Text.RE.PCRE.Text.Lazy: data RE
+ Text.RE.PCRE.Text.Lazy: data SearchReplace re s :: * -> * -> *
+ Text.RE.PCRE.Text.Lazy: data SimpleREOptions :: *
+ Text.RE.PCRE.Text.Lazy: ed :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: edBI :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: edBS :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: edBlockInsensitive :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: edBlockSensitive :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: edMI :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: edMS :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: edMultilineInsensitive :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: edMultilineSensitive :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: ed_ :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: escape :: (Functor m, Monad m) => (String -> String) -> String -> m RE
+ Text.RE.PCRE.Text.Lazy: escapeREString :: String -> String
+ Text.RE.PCRE.Text.Lazy: escapeWith :: (Functor m, Monad m) => SimpleREOptions -> (String -> String) -> String -> m RE
+ Text.RE.PCRE.Text.Lazy: instance Text.RE.ZeInternals.Types.IsRegex.IsRegex Text.RE.ZeInternals.PCRE.RE Data.Text.Internal.Lazy.Text
+ Text.RE.PCRE.Text.Lazy: matchSource :: Match a -> a
+ Text.RE.PCRE.Text.Lazy: matched :: Match a -> Bool
+ Text.RE.PCRE.Text.Lazy: matchedText :: Match a -> Maybe a
+ Text.RE.PCRE.Text.Lazy: matches :: Matches a -> [a]
+ Text.RE.PCRE.Text.Lazy: matchesSource :: Matches a -> a
+ Text.RE.PCRE.Text.Lazy: re :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: reBI :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: reBS :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: reBlockInsensitive :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: reBlockSensitive :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: reMI :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: reMS :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: reMultilineInsensitive :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: reMultilineSensitive :: QuasiQuoter
+ Text.RE.PCRE.Text.Lazy: reSource :: RE -> String
+ Text.RE.PCRE.Text.Lazy: re_ :: QuasiQuoter

Files

README.markdown view
@@ -34,51 +34,9 @@  ## Road Map -    ☒  2017-01-26  v0.0.0.1  Pre-release (I)--    ☒  2017-01-30  v0.0.0.2  Pre-release (II)--    ☒  2017-02-18  v0.1.0.0  [Proposed core API with presentable Haddocks](https://github.com/iconnect/regex/milestone/1)--    ☒  2017-02-19  v0.2.0.0  [Package split into regex and regex-examples](https://github.com/iconnect/regex/milestone/5)--    ☒  2017-02-20  v0.2.0.1  [Remove library from regex-examples](https://github.com/iconnect/regex/issues/43)--    ☒  2017-02-21  v0.2.0.2  [Fix tests for Hackage](https://github.com/iconnect/regex/issues/45)--    ☒  2017-02-21  v0.2.0.3  Tweak README/index layout--    ☒  2017-02-22  v0.2.0.4  [Repair re-gen-modules-test for Windows](https://github.com/iconnect/regex/issues/47)--    ☒  2017-02-26  v0.3.0.0  [API adjustments](https://github.com/iconnect/regex/milestone/2)--    ☒  2017-03-05  v0.5.0.0  [Ready for review: API, tutorials and examples finalized](https://github.com/iconnect/regex/issues/67)--    ☒  2017-03-13  v0.6.0.0  [Split out PCRE](https://github.com/iconnect/regex/milestone/7)--    ☒  2017-03-13  v0.6.0.1  [Fix .travis.yml release-stack script](https://github.com/iconnect/regex/issues/67)--    ☒  2017-03-15  v0.7.0.0  [Better organization of API](https://github.com/iconnect/regex/milestone/8)--    ☒  2017-03-16  v0.8.0.0  [Tidy up the API](https://github.com/iconnect/regex/milestone/10)--    ☒  2017-03-24  v0.9.0.0  [Finish tidying up the API, Add type-safe replacement templates and exploit TemplateHaskellQuotes](https://github.com/iconnect/regex/milestone/9)--    ☒  2017-03-27  v0.10.0.2 [Tweak Templates, Fix release scripts and update Haddocks commentary](https://github.com/iconnect/regex/milestone/12)--    ☒  2017-03-28  v0.10.0.3 [Upgrade to LTS 8.6 and Improve Haddocks for Text.RE.{TDFA,PCRE}](https://github.com/iconnect/regex/milestone/13)--    ☒  2017-03-29  v0.11.0.0 [Simplify the API](https://github.com/iconnect/regex/milestone/14)--    ☒  2017-03-30  v0.11.1.0 [Fix the Haddocks](https://github.com/iconnect/regex/milestone/15)--    ☒  2017-03-31  v0.12.0.0 [Move IsRegex into Text.RE](https://github.com/iconnect/regex/milestone/16)--    ☒  2017-04-03  v0.13.0.0 [Protect findCaptureID and add Find, re-sort-imports](https://github.com/iconnect/regex/milestone/17)--    ☒  2017-04-04  v0.14.0.0 [Move IsOption, rename Find functions](https://github.com/iconnect/regex/milestone/18)-     ☒  2017-04-10  v1.0.0.0  [First stable release](https://github.com/iconnect/regex/milestone/3)++    ☒  2017-06-03  v1.0.1.0  [PCRE.Text, strict PVP, Update Stackage vrns, add re-top](https://github.com/iconnect/regex/milestone/19)      ☐  2017-08-31  v2.0.0.0  [Fast text replacement with benchmarks](https://github.com/iconnect/regex/milestone/4) 
Text/RE/PCRE/ByteString.hs view
@@ -96,7 +96,7 @@ import           Text.RE.ZeInternals.SearchReplace.PCRE.ByteString import           Text.Regex.Base import qualified Text.Regex.PCRE               as PCRE-+-- NB regex-base instance imports maybe be needed for for some API modules  -- | find all the matches in the argument text; e.g., to count the number -- of naturals in s:
Text/RE/PCRE/ByteString/Lazy.hs view
@@ -96,7 +96,7 @@ import           Text.RE.ZeInternals.SearchReplace.PCRE.ByteString.Lazy import           Text.Regex.Base import qualified Text.Regex.PCRE               as PCRE-+-- NB regex-base instance imports maybe be needed for for some API modules  -- | find all the matches in the argument text; e.g., to count the number -- of naturals in s:
Text/RE/PCRE/Sequence.hs view
@@ -96,7 +96,7 @@ import           Text.RE.ZeInternals.SearchReplace.PCRE.Sequence import           Text.Regex.Base import qualified Text.Regex.PCRE               as PCRE-+-- NB regex-base instance imports maybe be needed for for some API modules  -- | find all the matches in the argument text; e.g., to count the number -- of naturals in s:
Text/RE/PCRE/String.hs view
@@ -96,7 +96,7 @@ import           Text.RE.ZeInternals.SearchReplace.PCRE.String import           Text.Regex.Base import qualified Text.Regex.PCRE               as PCRE-+-- NB regex-base instance imports maybe be needed for for some API modules  -- | find all the matches in the argument text; e.g., to count the number -- of naturals in s:
+ Text/RE/PCRE/Text.hs view
@@ -0,0 +1,217 @@+{-# LANGUAGE NoImplicitPrelude              #-}+{-# LANGUAGE MultiParamTypeClasses          #-}+{-# LANGUAGE FlexibleContexts               #-}+{-# LANGUAGE FlexibleInstances              #-}+{-# OPTIONS_GHC -fno-warn-orphans           #-}+{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}+{-# LANGUAGE CPP                            #-}+#if __GLASGOW_HASKELL__ >= 800+{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}+#endif++module Text.RE.PCRE.Text+  (+  -- * Tutorial+  -- $tutorial++  -- * The 'Matches' and 'Match' Operators+    (*=~)+  , (?=~)+  -- * The 'SearchReplace' Operators+  , (*=~/)+  , (?=~/)+  -- * The 'Matches' Type+  , Matches+  , matchesSource+  , allMatches+  , anyMatches+  , countMatches+  , matches+  -- * The 'Match' Type+  , Match+  , matchSource+  , matched+  , matchedText+  -- * The Macros and Parsers+  -- $macros+  , module Text.RE.TestBench.Parsers+  -- * The 'RE' Type+  , RE+  , reSource+  -- * Options+  -- $options+  , SimpleREOptions(..)+  -- * Compiling and Escaping REs+  , SearchReplace(..)+  , compileRegex+  , compileRegexWith+  , compileSearchReplace+  , compileSearchReplaceWith+  , escape+  , escapeWith+  , escapeREString+  -- * The Classic regex-base Match Operators+  , (=~)+  , (=~~)+  -- * The re Quasi Quoters+  -- $re+  , re+  , reMultilineSensitive+  , reMultilineInsensitive+  , reBlockSensitive+  , reBlockInsensitive+  , reMS+  , reMI+  , reBS+  , reBI+  , re_+  -- * The Ed Quasi Quoters+  -- $ed+  , edMultilineSensitive+  , edMultilineInsensitive+  , edBlockSensitive+  , edBlockInsensitive+  , ed+  , edMS+  , edMI+  , edBS+  , edBI+  , ed_+  -- * The cp Quasi Quoters+  , cp+  -- * IsRegex+  -- $isregex+  , module Text.RE.Tools.IsRegex+  ) where++import qualified Data.Text                     as T+import           Data.Typeable+import           Prelude.Compat+import           Text.RE.REOptions+import           Text.RE.Replace+import           Text.RE.TestBench.Parsers+import           Text.RE.Tools.IsRegex+import           Text.RE.ZeInternals+import           Text.RE.ZeInternals.PCRE+import           Text.RE.ZeInternals.SearchReplace.PCRE.Text+import           Text.Regex.Base+import qualified Text.Regex.PCRE               as PCRE+import           Text.Regex.PCRE.Text()++-- | find all the matches in the argument text; e.g., to count the number+-- of naturals in s:+--+--   @countMatches $ s *=~ [re|[0-9]+|]@+--+(*=~) :: T.Text+      -> RE+      -> Matches T.Text+(*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs++-- | find the first match in the argument text; e.g., to test if there+-- is a natural number in the input text:+--+--   @matched $ s ?=~ [re|[0-9]+|]@+--+(?=~) :: T.Text+      -> RE+      -> Match T.Text+(?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs++-- | search and replace all matches in the argument text; e.g., this section+-- will convert every YYYY-MM-DD format date in its argument text into a+-- DD\/MM\/YYYY date:+--+--   @(*=~\/ [ed|${y}([0-9]{4})-0*${m}([0-9]{2})-0*${d}([0-9]{2})\/\/\/${d}\/${m}\/${y}|])@+--+(*=~/) :: T.Text -> SearchReplace RE T.Text -> T.Text+(*=~/) = flip searchReplaceAll++-- | search and replace the first occurrence only (if any) in the input text+-- e.g., to prefix the first string of four hex digits in the input text,+-- if any, with @0x@:+--+--  @(?=~\/ [ed|[0-9A-Fa-f]{4}\/\/\/0x$0|])@+--+(?=~/) :: T.Text -> SearchReplace RE T.Text -> T.Text+(?=~/) = flip searchReplaceFirst++-- | the `regex-base` polymorphic match operator+(=~) :: ( Typeable a+        , RegexContext PCRE.Regex T.Text a+        )+     => T.Text+     -> RE+     -> a+(=~) bs rex = addCaptureNames (reCaptureNames rex) $ match (reRegex rex) bs++-- | the `regex-base` monadic, polymorphic match operator+(=~~) :: ( Monad m+         , Functor m+         , Typeable a+         , RegexContext PCRE.Regex T.Text a+         )+      => T.Text+      -> RE+      -> m a+(=~~) bs rex = addCaptureNames (reCaptureNames rex) <$> matchM (reRegex rex) bs++instance IsRegex RE T.Text where+  matchOnce             = flip (?=~)+  matchMany             = flip (*=~)+  makeRegexWith         = \o -> compileRegexWith o . unpackR+  makeSearchReplaceWith = \o r t -> compileSearchReplaceWith o (unpackR r) (unpackR t)+  regexSource           = packR . reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>.++-- $macros+-- There are a number of RE macros and corresponding Haskell parsers+-- for parsing the matched text into appropriate Haskell types. See+-- the [Macros Tables](http://regex.uk/macros) for details.++-- $options+-- You can specify different compilation options by appending a+-- to the name of an [re| ... |] or [ed| ... \/\/\/ ... |] quasi quoter+-- to select the corresponding compilation option. For example, the+-- section,+--+--  @(?=~/ [edBlockInsensitive|foo$\/\/\/bar|])@+--+-- will replace a @foo@ suffix of the argument text, of any+-- capitalisation, with a (lower case) @bar@. If you need to specify the+-- options dynamically, use the @[re_| ... |]@ and @[ed_| ... \/\/\/ ... |]@+-- quasi quoters, which generate functions that take an 'IsOption' option+-- (e.g., a 'SimpleReOptions' value) and yields a 'RE' or 'SearchReplace'+-- as apropriate. For example if you have a 'SimpleReOptions' value in+-- @sro@ then+--+--  @(?=~/ [ed_|foo$\/\/\/bar|] sro)@+--+-- will compile the @foo$@ RE according to the value of @sro@. For more+-- on specifying RE options see "Text.RE.REOptions".++-- $re+-- The @[re|.*|]@ quasi quoters, with variants for specifing different+-- options to the RE compiler (see "Text.RE.REOptions"), and the+-- specialised back-end types and functions.++-- $ed+-- The @[ed|.*\/\/\/foo|]@ quasi quoters, with variants for specifing different+-- options to the RE compiler (see "Text.RE.REOptions").++-- $ed+-- The -- | the @[ed| ... \/\/\/ ... |]@ quasi quoters; for example,+--+--  @[ed|${y}([0-9]{4})-0*${m}([0-9]{2})-0*${d}([0-9]{2})\/\/\/${d}\/${m}\/${y}|])@+--+-- represents a @SearchReplace@ that will convert a YYYY-MM-DD format date+-- into a DD\/MM\/YYYY format date.+--+-- The only difference betweem these quasi quoters is the RE options that are set,+-- using the same conventions as the @[re| ... |]@ quasi quoters.++-- $isregex+-- The 'IsRegex' class is used to abstact over the different regex back ends and+-- the text types they work with -- see "Text.RE.Tools.IsRegex" for details.
+ Text/RE/PCRE/Text/Lazy.hs view
@@ -0,0 +1,217 @@+{-# LANGUAGE NoImplicitPrelude              #-}+{-# LANGUAGE MultiParamTypeClasses          #-}+{-# LANGUAGE FlexibleContexts               #-}+{-# LANGUAGE FlexibleInstances              #-}+{-# OPTIONS_GHC -fno-warn-orphans           #-}+{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}+{-# LANGUAGE CPP                            #-}+#if __GLASGOW_HASKELL__ >= 800+{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}+#endif++module Text.RE.PCRE.Text.Lazy+  (+  -- * Tutorial+  -- $tutorial++  -- * The 'Matches' and 'Match' Operators+    (*=~)+  , (?=~)+  -- * The 'SearchReplace' Operators+  , (*=~/)+  , (?=~/)+  -- * The 'Matches' Type+  , Matches+  , matchesSource+  , allMatches+  , anyMatches+  , countMatches+  , matches+  -- * The 'Match' Type+  , Match+  , matchSource+  , matched+  , matchedText+  -- * The Macros and Parsers+  -- $macros+  , module Text.RE.TestBench.Parsers+  -- * The 'RE' Type+  , RE+  , reSource+  -- * Options+  -- $options+  , SimpleREOptions(..)+  -- * Compiling and Escaping REs+  , SearchReplace(..)+  , compileRegex+  , compileRegexWith+  , compileSearchReplace+  , compileSearchReplaceWith+  , escape+  , escapeWith+  , escapeREString+  -- * The Classic regex-base Match Operators+  , (=~)+  , (=~~)+  -- * The re Quasi Quoters+  -- $re+  , re+  , reMultilineSensitive+  , reMultilineInsensitive+  , reBlockSensitive+  , reBlockInsensitive+  , reMS+  , reMI+  , reBS+  , reBI+  , re_+  -- * The Ed Quasi Quoters+  -- $ed+  , edMultilineSensitive+  , edMultilineInsensitive+  , edBlockSensitive+  , edBlockInsensitive+  , ed+  , edMS+  , edMI+  , edBS+  , edBI+  , ed_+  -- * The cp Quasi Quoters+  , cp+  -- * IsRegex+  -- $isregex+  , module Text.RE.Tools.IsRegex+  ) where++import qualified Data.Text.Lazy                as TL+import           Data.Typeable+import           Prelude.Compat+import           Text.RE.REOptions+import           Text.RE.Replace+import           Text.RE.TestBench.Parsers+import           Text.RE.Tools.IsRegex+import           Text.RE.ZeInternals+import           Text.RE.ZeInternals.PCRE+import           Text.RE.ZeInternals.SearchReplace.PCRE.Text.Lazy+import           Text.Regex.Base+import qualified Text.Regex.PCRE               as PCRE+import           Text.Regex.PCRE.Text.Lazy()++-- | find all the matches in the argument text; e.g., to count the number+-- of naturals in s:+--+--   @countMatches $ s *=~ [re|[0-9]+|]@+--+(*=~) :: TL.Text+      -> RE+      -> Matches TL.Text+(*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs++-- | find the first match in the argument text; e.g., to test if there+-- is a natural number in the input text:+--+--   @matched $ s ?=~ [re|[0-9]+|]@+--+(?=~) :: TL.Text+      -> RE+      -> Match TL.Text+(?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs++-- | search and replace all matches in the argument text; e.g., this section+-- will convert every YYYY-MM-DD format date in its argument text into a+-- DD\/MM\/YYYY date:+--+--   @(*=~\/ [ed|${y}([0-9]{4})-0*${m}([0-9]{2})-0*${d}([0-9]{2})\/\/\/${d}\/${m}\/${y}|])@+--+(*=~/) :: TL.Text -> SearchReplace RE TL.Text -> TL.Text+(*=~/) = flip searchReplaceAll++-- | search and replace the first occurrence only (if any) in the input text+-- e.g., to prefix the first string of four hex digits in the input text,+-- if any, with @0x@:+--+--  @(?=~\/ [ed|[0-9A-Fa-f]{4}\/\/\/0x$0|])@+--+(?=~/) :: TL.Text -> SearchReplace RE TL.Text -> TL.Text+(?=~/) = flip searchReplaceFirst++-- | the `regex-base` polymorphic match operator+(=~) :: ( Typeable a+        , RegexContext PCRE.Regex TL.Text a+        )+     => TL.Text+     -> RE+     -> a+(=~) bs rex = addCaptureNames (reCaptureNames rex) $ match (reRegex rex) bs++-- | the `regex-base` monadic, polymorphic match operator+(=~~) :: ( Monad m+         , Functor m+         , Typeable a+         , RegexContext PCRE.Regex TL.Text a+         )+      => TL.Text+      -> RE+      -> m a+(=~~) bs rex = addCaptureNames (reCaptureNames rex) <$> matchM (reRegex rex) bs++instance IsRegex RE TL.Text where+  matchOnce             = flip (?=~)+  matchMany             = flip (*=~)+  makeRegexWith         = \o -> compileRegexWith o . unpackR+  makeSearchReplaceWith = \o r t -> compileSearchReplaceWith o (unpackR r) (unpackR t)+  regexSource           = packR . reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>.++-- $macros+-- There are a number of RE macros and corresponding Haskell parsers+-- for parsing the matched text into appropriate Haskell types. See+-- the [Macros Tables](http://regex.uk/macros) for details.++-- $options+-- You can specify different compilation options by appending a+-- to the name of an [re| ... |] or [ed| ... \/\/\/ ... |] quasi quoter+-- to select the corresponding compilation option. For example, the+-- section,+--+--  @(?=~/ [edBlockInsensitive|foo$\/\/\/bar|])@+--+-- will replace a @foo@ suffix of the argument text, of any+-- capitalisation, with a (lower case) @bar@. If you need to specify the+-- options dynamically, use the @[re_| ... |]@ and @[ed_| ... \/\/\/ ... |]@+-- quasi quoters, which generate functions that take an 'IsOption' option+-- (e.g., a 'SimpleReOptions' value) and yields a 'RE' or 'SearchReplace'+-- as apropriate. For example if you have a 'SimpleReOptions' value in+-- @sro@ then+--+--  @(?=~/ [ed_|foo$\/\/\/bar|] sro)@+--+-- will compile the @foo$@ RE according to the value of @sro@. For more+-- on specifying RE options see "Text.RE.REOptions".++-- $re+-- The @[re|.*|]@ quasi quoters, with variants for specifing different+-- options to the RE compiler (see "Text.RE.REOptions"), and the+-- specialised back-end types and functions.++-- $ed+-- The @[ed|.*\/\/\/foo|]@ quasi quoters, with variants for specifing different+-- options to the RE compiler (see "Text.RE.REOptions").++-- $ed+-- The -- | the @[ed| ... \/\/\/ ... |]@ quasi quoters; for example,+--+--  @[ed|${y}([0-9]{4})-0*${m}([0-9]{2})-0*${d}([0-9]{2})\/\/\/${d}\/${m}\/${y}|])@+--+-- represents a @SearchReplace@ that will convert a YYYY-MM-DD format date+-- into a DD\/MM\/YYYY format date.+--+-- The only difference betweem these quasi quoters is the RE options that are set,+-- using the same conventions as the @[re| ... |]@ quasi quoters.++-- $isregex+-- The 'IsRegex' class is used to abstact over the different regex back ends and+-- the text types they work with -- see "Text.RE.Tools.IsRegex" for details.
+ Text/RE/ZeInternals/SearchReplace/PCRE/Text.hs view
@@ -0,0 +1,83 @@+{-# LANGUAGE CPP                        #-}+#if __GLASGOW_HASKELL__ >= 800+{-# LANGUAGE TemplateHaskellQuotes      #-}+#else+{-# LANGUAGE QuasiQuotes                #-}+{-# LANGUAGE TemplateHaskell            #-}+#endif++module Text.RE.ZeInternals.SearchReplace.PCRE.Text+  ( ed+  , edMultilineSensitive+  , edMultilineInsensitive+  , edBlockSensitive+  , edBlockInsensitive+  , edMS+  , edMI+  , edBS+  , edBI+  , ed_+  ) where++import qualified Data.Text                     as T+import           Language.Haskell.TH+import           Language.Haskell.TH.Quote+import           Text.RE.REOptions+import           Text.RE.Tools.IsRegex+import           Text.RE.ZeInternals.SearchReplace.TDFAEdPrime+import           Text.RE.ZeInternals.TDFA++-- | @[ed| ... \/\/\/ ... |]@, is equivalent to @[edMultilineSensitive| ... \/\/\/ ... |]@,+-- compiling a case-sensitive, multi-line 'SearchReplace'+ed                      :: QuasiQuoter+ed                       = ed' sr_cast $ Just minBound++-- | @[edMultilineSensitive| ... \/\/\/ ... |]@ compiles a case-sensitive, multi-line 'SearchReplace' template+edMultilineSensitive    :: QuasiQuoter+edMultilineSensitive     = ed' sr_cast $ Just  MultilineSensitive++-- | @[edMultilineInsensitive| ... \/\/\/ ... |]@ compiles a case-insensitive, multi-line 'SearchReplace' template+edMultilineInsensitive  :: QuasiQuoter+edMultilineInsensitive   = ed' sr_cast $ Just  MultilineInsensitive++-- | @[edBlockSensitive| ... \/\/\/ ... |]@ compiles a case-sensitive, non-multi-line 'SearchReplace' template+edBlockSensitive        :: QuasiQuoter+edBlockSensitive         = ed' sr_cast $ Just  BlockSensitive++-- | @[edBlockInsensitive| ... \/\/\/ ... |]@ compiles a case-insensitive, non-multi-line 'SearchReplace' template+edBlockInsensitive      :: QuasiQuoter+edBlockInsensitive       = ed' sr_cast $ Just  BlockInsensitive++-- | @[edMS| ... \/\/\/ ... |]@ is a shorthand for @[edMultilineSensitive| ... \/\/\/ ... |]@+edMS                    :: QuasiQuoter+edMS                     = edMultilineSensitive++-- | @[edMI| ... \/\/\/ ... |]@ is a shorthand for @[edMultilineInsensitive| ... \/\/\/ ... |]@+edMI                    :: QuasiQuoter+edMI                     = edMultilineInsensitive++-- | @[edBS| ... \/\/\/ ... |]@ is a shorthand for @[edBlockSensitive| ... \/\/\/ ... |]@+edBS                    :: QuasiQuoter+edBS                     = edBlockSensitive++-- | @[edBI| ... \/\/\/ ... |]@ is a shorthand for @[edBlockInsensitive| ... \/\/\/ ... |]@+edBI                    :: QuasiQuoter+edBI                     = edBlockInsensitive++-- | @[ed_| ... \/\/\/ ... |]@ compiles a 'SearchReplace' template to produce a function that+-- takes the RE options (e.g., a 'SimpleREOptions' value) and yields the+-- 'SearchReplace' template compiled with those options. For example,+--+--   @s *=~/ [ed_|${hex}([0-9a-f]+)\/\/\/0x${hex}|] MultilineInsensitive@+--+-- prefixes the hexadecimal digit strings in s with @0x@, allowing for+-- upper- or lower-case hex didgits (which is entirely equivalent+-- in this example to just using @[edMultilineInsensitive|[0-9a-f]+|]@).+ed_                     :: QuasiQuoter+ed_                      = ed' fn_cast   Nothing++sr_cast :: Q Exp+sr_cast = [|\x -> x :: SearchReplace RE T.Text|]++fn_cast :: Q Exp+fn_cast = [|\f x -> f x :: SearchReplace RE T.Text|]
+ Text/RE/ZeInternals/SearchReplace/PCRE/Text/Lazy.hs view
@@ -0,0 +1,83 @@+{-# LANGUAGE CPP                        #-}+#if __GLASGOW_HASKELL__ >= 800+{-# LANGUAGE TemplateHaskellQuotes      #-}+#else+{-# LANGUAGE QuasiQuotes                #-}+{-# LANGUAGE TemplateHaskell            #-}+#endif++module Text.RE.ZeInternals.SearchReplace.PCRE.Text.Lazy+  ( ed+  , edMultilineSensitive+  , edMultilineInsensitive+  , edBlockSensitive+  , edBlockInsensitive+  , edMS+  , edMI+  , edBS+  , edBI+  , ed_+  ) where++import qualified Data.Text.Lazy                as TL+import           Language.Haskell.TH+import           Language.Haskell.TH.Quote+import           Text.RE.REOptions+import           Text.RE.Tools.IsRegex+import           Text.RE.ZeInternals.SearchReplace.TDFAEdPrime+import           Text.RE.ZeInternals.TDFA++-- | @[ed| ... \/\/\/ ... |]@, is equivalent to @[edMultilineSensitive| ... \/\/\/ ... |]@,+-- compiling a case-sensitive, multi-line 'SearchReplace'+ed                      :: QuasiQuoter+ed                       = ed' sr_cast $ Just minBound++-- | @[edMultilineSensitive| ... \/\/\/ ... |]@ compiles a case-sensitive, multi-line 'SearchReplace' template+edMultilineSensitive    :: QuasiQuoter+edMultilineSensitive     = ed' sr_cast $ Just  MultilineSensitive++-- | @[edMultilineInsensitive| ... \/\/\/ ... |]@ compiles a case-insensitive, multi-line 'SearchReplace' template+edMultilineInsensitive  :: QuasiQuoter+edMultilineInsensitive   = ed' sr_cast $ Just  MultilineInsensitive++-- | @[edBlockSensitive| ... \/\/\/ ... |]@ compiles a case-sensitive, non-multi-line 'SearchReplace' template+edBlockSensitive        :: QuasiQuoter+edBlockSensitive         = ed' sr_cast $ Just  BlockSensitive++-- | @[edBlockInsensitive| ... \/\/\/ ... |]@ compiles a case-insensitive, non-multi-line 'SearchReplace' template+edBlockInsensitive      :: QuasiQuoter+edBlockInsensitive       = ed' sr_cast $ Just  BlockInsensitive++-- | @[edMS| ... \/\/\/ ... |]@ is a shorthand for @[edMultilineSensitive| ... \/\/\/ ... |]@+edMS                    :: QuasiQuoter+edMS                     = edMultilineSensitive++-- | @[edMI| ... \/\/\/ ... |]@ is a shorthand for @[edMultilineInsensitive| ... \/\/\/ ... |]@+edMI                    :: QuasiQuoter+edMI                     = edMultilineInsensitive++-- | @[edBS| ... \/\/\/ ... |]@ is a shorthand for @[edBlockSensitive| ... \/\/\/ ... |]@+edBS                    :: QuasiQuoter+edBS                     = edBlockSensitive++-- | @[edBI| ... \/\/\/ ... |]@ is a shorthand for @[edBlockInsensitive| ... \/\/\/ ... |]@+edBI                    :: QuasiQuoter+edBI                     = edBlockInsensitive++-- | @[ed_| ... \/\/\/ ... |]@ compiles a 'SearchReplace' template to produce a function that+-- takes the RE options (e.g., a 'SimpleREOptions' value) and yields the+-- 'SearchReplace' template compiled with those options. For example,+--+--   @s *=~/ [ed_|${hex}([0-9a-f]+)\/\/\/0x${hex}|] MultilineInsensitive@+--+-- prefixes the hexadecimal digit strings in s with @0x@, allowing for+-- upper- or lower-case hex didgits (which is entirely equivalent+-- in this example to just using @[edMultilineInsensitive|[0-9a-f]+|]@).+ed_                     :: QuasiQuoter+ed_                      = ed' fn_cast   Nothing++sr_cast :: Q Exp+sr_cast = [|\x -> x :: SearchReplace RE TL.Text|]++fn_cast :: Q Exp+fn_cast = [|\f x -> f x :: SearchReplace RE TL.Text|]
+ Text/RE/ZeInternals/SearchReplace/TDFAEdPrime.hs view
@@ -0,0 +1,58 @@+{-# LANGUAGE NoImplicitPrelude          #-}+{-# LANGUAGE FlexibleContexts           #-}+{-# LANGUAGE CPP                        #-}+#if __GLASGOW_HASKELL__ >= 800+{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}+{-# LANGUAGE TemplateHaskellQuotes      #-}+#else+{-# LANGUAGE QuasiQuotes                #-}+{-# LANGUAGE TemplateHaskell            #-}+#endif++module Text.RE.ZeInternals.SearchReplace.TDFAEdPrime+  ( ed'+  ) where++import           Language.Haskell.TH+import           Language.Haskell.TH.Quote+import           Prelude.Compat+import           Text.RE.REOptions+import           Text.RE.Replace+import           Text.RE.Tools.IsRegex+import           Text.RE.ZeInternals+import           Text.RE.ZeInternals.TDFA+++-- | construct a quasi quoter from a casting function and @Just sro@+-- if the options are known, otherwise a function take takes the+-- 'SimpleREOptions' and constructs the 'SearchReplace' template+ed' :: Q Exp -> Maybe SimpleREOptions -> QuasiQuoter+ed' qe mb = case mb of+  Nothing  ->+    (qq0 "ed'")+      { quoteExp = parse minBound $ \rs -> AppE <$> qe <*> [|flip unsafe_compile_sr rs|]+      }+  Just sro ->+    (qq0 "ed'")+      { quoteExp = parse sro $ \rs -> AppE <$> qe <*> [|unsafe_compile_sr_simple sro rs|]+      }+  where+    parse :: SimpleREOptions -> (String->Q Exp) -> String -> Q Exp+    parse sro mk ts = either error (\_->mk ts) ei+      where+        ei :: Either String (SearchReplace RE String)+        ei = compileSearchReplace_ id (compileRegexWith sro) ts++unsafe_compile_sr_simple :: IsRegex RE s+                         => SimpleREOptions+                         -> String+                         -> SearchReplace RE s+unsafe_compile_sr_simple sro =+    unsafe_compile_sr $ unpackSimpleREOptions sro++unsafe_compile_sr :: (IsOption o, IsRegex RE s)+                  => o+                  -> String+                  -> SearchReplace RE s+unsafe_compile_sr os =+    unsafeCompileSearchReplace_ packR $ compileRegexWithOptions os
+ Text/RE/ZeInternals/TDFA.hs view
@@ -0,0 +1,440 @@+{-# LANGUAGE NoImplicitPrelude          #-}+{-# LANGUAGE RecordWildCards            #-}+{-# LANGUAGE MultiParamTypeClasses      #-}+{-# LANGUAGE TypeSynonymInstances       #-}+{-# LANGUAGE FlexibleInstances          #-}+{-# LANGUAGE FlexibleContexts           #-}+{-# LANGUAGE CPP                        #-}+#if __GLASGOW_HASKELL__ >= 800+{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}+{-# LANGUAGE TemplateHaskellQuotes      #-}+#else+{-# LANGUAGE QuasiQuotes                #-}+{-# LANGUAGE TemplateHaskell            #-}+#endif+{-# OPTIONS_GHC -fno-warn-orphans       #-}++module Text.RE.ZeInternals.TDFA+  ( -- * About+    -- $about++    -- * RE Type+    RE+  , regexType+  , reOptions+  , reSource+  , reCaptureNames+  , reRegex+  -- * IsOptions Class and REOptions Type+  , IsOption(..)+  , REOptions+  , defaultREOptions+  , noPreludeREOptions+  , unpackSimpleREOptions+  -- * Compiling Regular Expressions+  , compileRegex+  , compileRegexWith+  , compileRegexWithOptions+  -- * Compiling Search-Replace Templates+  , compileSearchReplace+  , compileSearchReplaceWith+  , compileSearchReplaceWithOptions+  -- * Escaping String+  , escape+  , escapeWith+  , escapeWithOptions+  , escapeREString+  -- * Macros Standard Environment+  , prelude+  , preludeEnv+  , preludeTestsFailing+  , preludeTable+  , preludeSummary+  , preludeSources+  , preludeSource+  -- * The Quasi Quoters+  , re+  , reMS+  , reMI+  , reBS+  , reBI+  , reMultilineSensitive+  , reMultilineInsensitive+  , reBlockSensitive+  , reBlockInsensitive+  , re_+  , cp+  ) where++import           Data.Functor.Identity+import           Language.Haskell.TH+import           Language.Haskell.TH.Quote+import           Prelude.Compat+import           Text.RE.REOptions+import           Text.RE.Replace+import           Text.RE.TestBench+import           Text.RE.Tools+import           Text.RE.ZeInternals+import           Text.Regex.TDFA+++-- | the RE type for this back end representing a well-formed, compiled+-- RE+data RE =+  RE+    { _re_options :: !REOptions+    , _re_source  :: !String+    , _re_cnames  :: !CaptureNames+    , _re_regex   :: !Regex+    }++-- | some functions in the "Text.RE.TestBench" need the back end to+-- be passed dynamically as a 'RegexType' parameters: use 'regexType'+-- for this+regexType :: RegexType+regexType =+  mkTDFA $ \txt env md -> txt =~ mdRegexSource regexType ExclCaptures env md++-- | extract the 'REOptions' from the @RE@+reOptions :: RE -> REOptions+reOptions = _re_options++-- | extract the RE source string from the @RE@+reSource :: RE -> String+reSource = _re_source++-- | extract the 'CaptureNames' from the @RE@+reCaptureNames :: RE -> CaptureNames+reCaptureNames = _re_cnames++-- | extract the back end compiled 'Regex' type from the @RE@+reRegex :: RE -> Regex+reRegex = _re_regex+++------------------------------------------------------------------------+-- IsOption & REOptions+------------------------------------------------------------------------++-- | a number of types can be used to encode 'REOptions_', each of which+-- is made a member of this class+class IsOption o where+  -- | convert the @o@ type into an @REOptions@+  makeREOptions :: o -> REOptions++-- | and the REOptions for this back end (see "Text.RE.REOptions"+-- for details)+type REOptions = REOptions_ RE CompOption ExecOption++instance IsOption SimpleREOptions where+  makeREOptions    = unpackSimpleREOptions++instance IsOption (Macros RE) where+  makeREOptions ms = REOptions ms def_comp_option def_exec_option++instance IsOption CompOption where+  makeREOptions co = REOptions prelude co def_exec_option++instance IsOption ExecOption where+  makeREOptions eo = REOptions prelude def_comp_option eo++instance IsOption REOptions where+  makeREOptions    = id++instance IsOption () where+  makeREOptions _  = unpackSimpleREOptions minBound++-- | the default 'REOptions'+defaultREOptions :: REOptions+defaultREOptions = makeREOptions (minBound::SimpleREOptions)++-- | the default 'REOptions' but with no RE macros defined+noPreludeREOptions :: REOptions+noPreludeREOptions = defaultREOptions { optionsMacs = emptyMacros }++-- | convert a universal 'SimpleReOptions' into the 'REOptions' used+-- by this back end+unpackSimpleREOptions :: SimpleREOptions -> REOptions+unpackSimpleREOptions sro =+  REOptions+    { optionsMacs = prelude+    , optionsComp = comp+    , optionsExec = defaultExecOpt+    }+  where+    comp = defaultCompOpt+      { caseSensitive = cs+      , multiline     = ml+      }++    (ml,cs) = case sro of+        MultilineSensitive    -> (,) True  True+        MultilineInsensitive  -> (,) True  False+        BlockSensitive        -> (,) False True+        BlockInsensitive      -> (,) False False+++------------------------------------------------------------------------+-- Compiling Regular Expressions+------------------------------------------------------------------------++-- | compile a 'String' into a 'RE' with the default options,+-- generating an error if the RE is not well formed+compileRegex :: (Functor m,Monad m) => String -> m RE+compileRegex = compileRegexWith minBound++-- | compile a 'String' into a 'RE' using the given @SimpleREOptions@,+-- generating an error if the RE is not well formed+compileRegexWith :: (Functor m,Monad m) => SimpleREOptions -> String -> m RE+compileRegexWith = compileRegexWithOptions++-- | compile a 'String' into a 'RE' using the given @SimpleREOptions@,+-- generating an error if the RE is not well formed+compileRegexWithOptions :: (IsOption o, Functor m, Monad   m)+                        => o+                        -> String+                        -> m RE+compileRegexWithOptions = compileRegex_ . makeREOptions+++------------------------------------------------------------------------+-- Compiling Search Replace Templates+------------------------------------------------------------------------++-- | compile a SearchReplace template generating errors if the RE or+-- the template are not well formed, all capture references being checked+compileSearchReplace :: (Monad m,Functor m,IsRegex RE s)+                     => String+                     -> String+                     -> m (SearchReplace RE s)+compileSearchReplace = compileSearchReplaceWith minBound++-- | compile a SearchReplace template, with simple options, generating+-- errors if the RE or the template are not well formed, all capture+-- references being checked+compileSearchReplaceWith :: (Monad m,Functor m,IsRegex RE s)+                         => SimpleREOptions+                         -> String+                         -> String+                         -> m (SearchReplace RE s)+compileSearchReplaceWith sro = compileSearchAndReplace_ packR $ compileRegexWith sro++-- | compile a SearchReplace template, with general options, generating+-- errors if the RE or the template are not well formed, all capture+-- references being checked+compileSearchReplaceWithOptions :: (Monad m,Functor m,IsRegex RE s)+                                => REOptions+                                -> String+                                -> String+                                -> m (SearchReplace RE s)+compileSearchReplaceWithOptions os = compileSearchAndReplace_ packR $ compileRegexWithOptions os+++------------------------------------------------------------------------+-- Escaping Strings+------------------------------------------------------------------------++-- | convert a string into a RE that matches that string, and apply it+-- to an argument continuation function to make up the RE string to be+-- compiled; e.g., to compile a RE that will only match the string:+--+--  @maybe undefined id . escape ((\"^\"++) . (++\"$\"))@+--+escape :: (Functor m,Monad m)+       => (String->String)+       -> String+       -> m RE+escape = escapeWith minBound++-- | a variant of 'escape' where the 'SimpleREOptions' are specified+escapeWith :: (Functor m,Monad m)+           => SimpleREOptions+           -> (String->String)+           -> String+           -> m RE+escapeWith = escapeWithOptions++-- | a variant of 'escapeWith' that allows an 'IsOption' RE option+-- to be specified+escapeWithOptions :: ( IsOption o, Functor m, Monad m)+                  => o+                  -> (String->String)+                  -> String+                  -> m RE+escapeWithOptions o f = compileRegexWithOptions o . f . escapeREString+++------------------------------------------------------------------------+-- Macro Standard Environment+------------------------------------------------------------------------++-- | the standard table of 'Macros' used to compile REs (which can be+-- extended or replace: see "Text.RE.TestBench")+prelude :: Macros RE+prelude = runIdentity $ preludeMacros mk regexType ExclCaptures+  where+    mk = Identity . unsafeCompileRegex_ noPreludeREOptions++-- | the standard 'MacroEnv' for this back end (see "Text.RE.TestBench")+preludeEnv :: MacroEnv+preludeEnv = preludeMacroEnv regexType++-- | the macros in the standard environment that are failing their tests+-- (checked by the test suite to be empty)+preludeTestsFailing :: [MacroID]+preludeTestsFailing = badMacros $ preludeMacroEnv regexType++-- | a table the standard macros in markdown format+preludeTable :: String+preludeTable = preludeMacroTable regexType++-- | a summary of the macros in the standard environment for this back+-- end in plain text+preludeSummary :: PreludeMacro -> String+preludeSummary = preludeMacroSummary regexType++-- | a listing of the RE text for each macro in the standard environment+-- with all macros expanded to normal form+preludeSources :: String+preludeSources = preludeMacroSources regexType++-- | the prolude source of a given macro in the standard environment+preludeSource :: PreludeMacro -> String+preludeSource = preludeMacroSource regexType+++------------------------------------------------------------------------+-- Quasi Quoters+------------------------------------------------------------------------++-- | @[re| ... |]@, is equivalent to @[reMultilineSensitive| ... |]@,+-- compiling a case-sensitive, multi-line RE+re                      :: QuasiQuoter+re                       = re' $ Just minBound++-- | @[reMultilineSensitive| ... |]@, compiles a case-sensitive, multi-line RE+reMultilineSensitive    :: QuasiQuoter+reMultilineSensitive     = re' $ Just  MultilineSensitive++-- | @[reMultilineInsensitive| ... |]@, compiles a case-insensitive, multi-line RE+reMultilineInsensitive  :: QuasiQuoter+reMultilineInsensitive   = re' $ Just  MultilineInsensitive++-- | @[reMultilineInsensitive| ... |]@, compiles a case-sensitive, non-multi-line RE+reBlockSensitive        :: QuasiQuoter+reBlockSensitive         = re' $ Just  BlockSensitive++-- | @[reMultilineInsensitive| ... |]@, compiles a case-insensitive, non-multi-line RE+reBlockInsensitive      :: QuasiQuoter+reBlockInsensitive       = re' $ Just  BlockInsensitive++-- | @[reMS| ... |]@ is a shorthand for @[reMultilineSensitive| ... |]@+reMS                     :: QuasiQuoter+reMS                     = reMultilineSensitive++-- | @[reMI| ... |]@ is a shorthand for @[reMultilineInsensitive| ... |]@+reMI                    :: QuasiQuoter+reMI                     = reMultilineInsensitive++-- | @[reBS| ... |]@ is a shorthand for @[reBlockSensitive| ... |]@+reBS                    :: QuasiQuoter+reBS                     = reBlockSensitive++-- | @[reBI| ... |]@ is a shorthand for @[reBlockInsensitive| ... |]@+reBI                    :: QuasiQuoter+reBI                     = reBlockInsensitive++-- | @[re_| ... |]@ compiles a RE to produce a function that takes+-- the RE options (e.g., a 'SimpleREOptions' value) and yields the+-- RE compiled with those options. For example,+--+--   @countMatches $ s *=~ [re_|[0-9a-f]+|] MultilineInsensitive@+--+-- counts the number of hexadecimal digit strings in 's', allowing+-- for upper- or lower-case hex didgits (which is entirely equivalent+-- in this example to just using @[reMultilineInsensitive|[0-9a-f]+|]@).+re_                     :: QuasiQuoter+re_                      = re'   Nothing+++------------------------------------------------------------------------+-- re Helpers+------------------------------------------------------------------------++re' :: Maybe SimpleREOptions -> QuasiQuoter+re' mb = case mb of+  Nothing  ->+    (qq0 "re'")+      { quoteExp = parse minBound (\rs->[|flip unsafeCompileRegex rs|])+      }+  Just sro ->+    (qq0 "re'")+      { quoteExp = parse sro (\rs->[|unsafeCompileRegexSimple sro rs|])+      }+  where+    parse :: SimpleREOptions -> (String->Q Exp) -> String -> Q Exp+    parse sro mk rs = either error (\_->mk rs) $ compileRegex_ os rs+      where+        os = unpackSimpleREOptions sro++unsafeCompileRegexSimple :: SimpleREOptions -> String -> RE+unsafeCompileRegexSimple sro re_s = unsafeCompileRegex_ os re_s+  where+    os = unpackSimpleREOptions sro++unsafeCompileRegex :: IsOption o+                   => o+                   -> String+                   -> RE+unsafeCompileRegex = unsafeCompileRegex_ . makeREOptions++unsafeCompileRegex_ :: REOptions -> String -> RE+unsafeCompileRegex_ os = either oops id . compileRegex_ os+  where+    oops = error . ("unsafeCompileRegex: " ++)++compileRegex' :: (Functor m,Monad m)+              => REOptions+              -> String+              -> m (CaptureNames,Regex)+compileRegex' REOptions{..} s0 = do+    ((_,cnms),s2) <- either fail return $ extractNamedCaptures s1+    (,) cnms <$> makeRegexOptsM optionsComp optionsExec s2+  where+    s1 = expandMacros reSource optionsMacs s0++compileRegex_ :: (Functor m,Monad m)+              => REOptions+              -> String+              -> m RE+compileRegex_ os re_s = uncurry mk <$> compileRegex' os re_s+  where+    mk cnms rx =+      RE+        { _re_options = os+        , _re_source  = re_s+        , _re_cnames  = cnms+        , _re_regex   = rx+        }+++------------------------------------------------------------------------+-- Options Helpers+------------------------------------------------------------------------++def_comp_option :: CompOption+def_comp_option = optionsComp defaultREOptions++def_exec_option :: ExecOption+def_exec_option = optionsExec defaultREOptions+++------------------------------------------------------------------------+-- Haddock Sections+------------------------------------------------------------------------++-- $about+--+-- This module provides the regex PCRE back end. Most of the functions that+-- you will need for day to day use are provided by the primary API modules+-- (e.g., "Text.RE.TDFA.Text").
changelog view
@@ -1,5 +1,11 @@ -*-change-log-*- +1.0.1.0 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-06-05+  * Text.RE.PCRE.Text[.Lazy] (#58)+  * Update LSTHaskell versions (#136)+  * Add re-top example (#137)+  * Regex library to conform with strict PVP (#138)+ 1.0.0.0 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-04-10   * Rewrite tutorials (#113)   * Add Text.RE.Tools.IsRegex (#122)
regex-with-pcre.cabal view
@@ -1,5 +1,5 @@ Name:                   regex-with-pcre-Version:                1.0.0.0+Version:                1.0.1.0 Synopsis:               Toolkit for regex-base Description:            A regular expression toolkit for regex-base with                         compile-time checking of RE syntax, data types for@@ -32,7 +32,7 @@ Source-Repository this     Type:               git     Location:           https://github.com/iconnect/regex.git-    Tag:                1.0.0.0+    Tag:                1.0.1.0   @@ -45,6 +45,8 @@       Text.RE.PCRE.ByteString.Lazy       Text.RE.PCRE.Sequence       Text.RE.PCRE.String+      Text.RE.PCRE.Text+      Text.RE.PCRE.Text.Lazy      Other-Modules:       Text.RE.ZeInternals.PCRE@@ -53,7 +55,11 @@       Text.RE.ZeInternals.SearchReplace.PCRE.ByteString.Lazy       Text.RE.ZeInternals.SearchReplace.PCRE.Sequence       Text.RE.ZeInternals.SearchReplace.PCRE.String+      Text.RE.ZeInternals.SearchReplace.PCRE.Text+      Text.RE.ZeInternals.SearchReplace.PCRE.Text.Lazy       Text.RE.ZeInternals.SearchReplace.PCREEdPrime+      Text.RE.ZeInternals.SearchReplace.TDFAEdPrime+      Text.RE.ZeInternals.TDFA      Default-Language:   Haskell2010 @@ -88,17 +94,19 @@       -Wwarn      Build-depends:-        regex                == 1.0.0.0-      , base                 >= 4 && < 5-      , base-compat          >= 0.6.0-      , bytestring           >= 0.10.2.0-      , containers           >= 0.4-      , regex-base           >= 0.93.2-      , regex-pcre-builtin   >= 0.94.4.8.8.35-      , regex-tdfa           >= 1.2.0-      , template-haskell     >= 2.7-      , transformers         >= 0.2.2-      , unordered-containers >= 0.2.5.1+        regex                == 1.0.1.0+      , base                 >= 4        && < 5+      , base-compat          >= 0.6      && < 0.10+      , bytestring           == 0.10.*+      , containers           >= 0.4      && < 0.6+      , regex-base           == 0.93.*+      , regex-pcre-builtin   == 0.94.*+      , regex-pcre-text      == 0.94.*+      , regex-tdfa           == 1.2.*+      , template-haskell     >= 2.7      && < 2.12+      , text                 == 1.2.*+      , transformers         >= 0.2.2    && < 0.6+      , unordered-containers == 0.2.*   -- Generated with re-gen-cabals