regex-examples 0.2.0.4 → 0.3.0.0
raw patch · 33 files changed
+674/−477 lines, 33 filesdep ~regex
Dependency ranges changed: regex
Files
- README.markdown +14/−3
- changelog +8/−1
- data/pp-result-doc.lhs +3/−5
- data/pp-result-gen.lhs +1/−2
- docs/pcre-macros.txt +2/−2
- docs/pcre-nginx-log-processor.txt +2/−2
- docs/tdfa-macros.txt +2/−2
- examples/TestKit.lhs +3/−3
- examples/re-gen-cabals.lhs +32/−15
- examples/re-gen-modules.lhs +7/−7
- examples/re-include.lhs +2/−2
- examples/re-nginx-log-processor.lhs +3/−3
- examples/re-prep.lhs +96/−135
- examples/re-tests.lhs +35/−27
- examples/re-tutorial.lhs +73/−106
- lib/cabal-masters/executables-incl.cabal +0/−40
- lib/cabal-masters/library-incl.cabal +0/−5
- lib/cabal-masters/mega-regex.cabal +1/−0
- lib/cabal-masters/regex-examples.cabal +1/−0
- lib/cabal-masters/regex.cabal +1/−0
- lib/mega-regex.cabal +54/−38
- lib/version.txt +1/−1
- regex-examples.cabal +53/−38
- src/Text/RE/PCRE/ByteString.hs +28/−4
- src/Text/RE/PCRE/ByteString/Lazy.hs +28/−4
- src/Text/RE/PCRE/Sequence.hs +28/−4
- src/Text/RE/PCRE/String.hs +28/−4
- src/Text/RE/TDFA/ByteString.hs +28/−4
- src/Text/RE/TDFA/ByteString/Lazy.hs +28/−4
- src/Text/RE/TDFA/Sequence.hs +28/−4
- src/Text/RE/TDFA/String.hs +28/−4
- src/Text/RE/TDFA/Text.hs +28/−4
- src/Text/RE/TDFA/Text/Lazy.hs +28/−4
README.markdown view
@@ -21,9 +21,12 @@ ## regex and regex-examples - * the `regex` package contains the regex library+The library and tutorial, tests and examples have been split across+two packages:++ * the `regex` package contains the regex library and * the `regex-examples` package contains the tutorial, tests- and example programs+ and example programs. ## Road Map@@ -44,8 +47,10 @@ ☒ 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, tutorials and examples finalized](https://github.com/iconnect/regex/milestone/2)+ ☒ 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: tutorials and examples finalized](https://github.com/iconnect/regex/milestone/6)+ ☐ 2017-03-20 v1.0.0.0 [First stable release](https://github.com/iconnect/regex/milestone/3) ☐ 2017-08-31 v2.0.0.0 [Fast text replacement with benchmarks](https://github.com/iconnect/regex/milestone/4)@@ -53,6 +58,12 @@ See the [Roadmap page](http://roadmap.regex.uk) for details.+++## The regex blog++Check out the [regex blog](http://blog.regex.uk) for news articles and+discussion concerning all things regex. ## Build Status
changelog view
@@ -1,9 +1,16 @@ -*-change-log-*- +0.3.0.0 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-02-26+ * Clean up API to use camelCase conventions+ * Use -Werror in development and testing, -Warn for Hackage+ * Integrate the regex blog+ * Better presentation of ghci tryouts in the Tutorial+ * Various minor README upgrades and fixes+ 0.2.0.4 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-02-22 * Repair re-gen-modules-test for Windows -0.2.0.4 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-02-21+0.2.0.3 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-02-21 * README/index layout tweak 0.2.0.2 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-02-21
data/pp-result-doc.lhs view
@@ -17,7 +17,6 @@ And here is an empty one. \begin{code} \end{code}-\begin{code} The top main stuff: @@ -41,18 +40,17 @@ A one-line evalme fragment.-<div class="replcodeblock"> \begin{code}+evalme_PPT_00 = checkThis "" 0 $ length [] \end{code}-</div> An evalme fragment spread over a couple of lines.-<div class="replcodeblock"> \begin{code}+ghci> +Just 0 length <$> Just [] \end{code}-</div> And the main bottom stuff.
data/pp-result-gen.lhs view
@@ -44,7 +44,7 @@ A one-line evalme fragment. \begin{code}-evalme_PPT_00 = checkThis "evalme_PPT_00" 0 $+evalme_PPT_00 = checkThis "" 0 $ length [] \end{code} @@ -60,7 +60,6 @@ main :: IO () main = runTests [ evalme_PPT_01- , evalme_PPT_00 ] \end{code}
docs/pcre-macros.txt view
@@ -49,8 +49,8 @@ | | | | |-.1 | | | |%hex |0 |[0-9a-fA-F]+ |0 | | |parseHex |a string of one or more hexadecimal digit\ | | | |12345678 |0x10 | | |\s -| | | |90abcdef |0z | | | -| | | |90ABCDEF |-1a | | | +| | | |0abcdef |0z | | | +| | | |0ABCDEF |-1a | | | | | | |00 | | | | | | | |010 | | | | |%id |0 |_*[a-zA-Z][a-zA-Z0-9_]* |a | | |- |a standard C-style alphanumeric identifie\
docs/pcre-nginx-log-processor.txt view
@@ -49,8 +49,8 @@ | | | | |-.1 | | | |%hex |0 |[0-9a-fA-F]+ |0 | | |parseHex |a string of one or more hexadecimal digit\ | | | |12345678 |0x10 | | |\s -| | | |90abcdef |0z | | | -| | | |90ABCDEF |-1a | | | +| | | |0abcdef |0z | | | +| | | |0ABCDEF |-1a | | | | | | |00 | | | | | | | |010 | | | | |%id |0 |_*[a-zA-Z][a-zA-Z0-9_]* |a | | |- |a standard C-style alphanumeric identifie\
docs/tdfa-macros.txt view
@@ -49,8 +49,8 @@ | | | | |-.1 | | | |%hex |0 |[0-9a-fA-F]+ |0 | | |parseHex |a string of one or more hexadecimal digit\ | | | |12345678 |0x10 | | |\s -| | | |90abcdef |0z | | | -| | | |90ABCDEF |-1a | | | +| | | |0abcdef |0z | | | +| | | |0ABCDEF |-1a | | | | | | |00 | | | | | | | |010 | | | | |%id |0 |_*[a-zA-Z][a-zA-Z0-9_]* |a | | |- |a standard C-style alphanumeric identifie\
examples/TestKit.lhs view
@@ -89,7 +89,7 @@ substVersion_ :: (IsRegex RE a,Replace a) => a -> IO a substVersion_ txt =- flip replaceAll ms . pack_ . presentVrn <$> readCurrentVersion+ flip replaceAll ms . packE . presentVrn <$> readCurrentVersion where ms = txt *=~ [re|<<\$version\$>>|] @@ -174,8 +174,8 @@ \begin{code} include :: LBS.ByteString -> IO LBS.ByteString include = sed' $ Select- [ (,) [re|^%include ${file}(@{%string})$|] $ EDIT_fun TOP incl- , (,) [re|^.*$|] $ EDIT_fun TOP $ \_ _ _ _->return Nothing+ [ (,) [re|^%include ${file}(@{%string})$|] $ Function TOP incl+ , (,) [re|^.*$|] $ Function TOP $ \_ _ _ _->return Nothing ] where incl _ mtch _ _ = Just <$> LBS.readFile (prs_s $ mtch !$$ [cp|file|])
examples/re-gen-cabals.lhs view
@@ -62,7 +62,8 @@ data Ctx = Ctx- { _ctx_package_constraints :: IORef (Map.Map LBS.ByteString LBS.ByteString)+ { _ctx_w_error :: IORef Bool+ , _ctx_package_constraints :: IORef (Map.Map LBS.ByteString LBS.ByteString) , _ctx_test_exe :: IORef (Maybe TestExe) } @@ -76,24 +77,29 @@ deriving (Show) setup :: IO Ctx-setup = Ctx <$> (newIORef Map.empty) <*> (newIORef Nothing)+setup = Ctx <$> (newIORef True) <*> (newIORef Map.empty) <*> (newIORef Nothing) gc_script :: Ctx -> SedScript RE gc_script ctx = Select- [ (,) [re|^%- +${pkg}(@{%id-}) +${cond}(.*)$|] $ EDIT_gen $ cond_gen ctx- , (,) [re|^%build-depends +${list}(@{%id-}( +@{%id-})+)$|] $ EDIT_gen $ build_depends_gen ctx- , (,) [re|^%test +${i}(@{%id-})$|] $ EDIT_gen $ test_exe_gen True False ctx- , (,) [re|^%exe +${i}(@{%id-})$|] $ EDIT_gen $ test_exe_gen False True ctx- , (,) [re|^%test-exe +${i}(@{%id-})$|] $ EDIT_gen $ test_exe_gen True True ctx- , (,) [re|^.*$|] $ EDIT_gen $ default_gen ctx+ [ (,) [re|^%Werror$|] $ LineEdit $ w_error_gen ctx+ , (,) [re|^%Wwarn$|] $ LineEdit $ w_warn_gen ctx+ , (,) [re|^%- +${pkg}(@{%id-}) +${cond}(.*)$|] $ LineEdit $ cond_gen ctx+ , (,) [re|^%build-depends +${list}(@{%id-}( +@{%id-})+)$|] $ LineEdit $ build_depends_gen ctx+ , (,) [re|^%test +${i}(@{%id-})$|] $ LineEdit $ test_exe_gen True False ctx+ , (,) [re|^%exe +${i}(@{%id-})$|] $ LineEdit $ test_exe_gen False True ctx+ , (,) [re|^%test-exe +${i}(@{%id-})$|] $ LineEdit $ test_exe_gen True True ctx+ , (,) [re|^.*$|] $ LineEdit $ default_gen ctx ] -cond_gen, build_depends_gen,+w_error_gen, w_warn_gen, cond_gen, build_depends_gen, default_gen :: Ctx -> LineNo -> Matches LBS.ByteString -> IO (LineEdit LBS.ByteString) +w_error_gen Ctx{..} _ _ = writeIORef _ctx_w_error True >> return Delete+w_warn_gen Ctx{..} _ _ = writeIORef _ctx_w_error False >> return Delete+ cond_gen Ctx{..} _ mtchs = do modifyIORef _ctx_package_constraints $ Map.insert pkg cond return Delete@@ -104,8 +110,9 @@ mtch = allMatches mtchs !! 0 build_depends_gen ctx@Ctx{..} _ mtchs = do+ we <- readIORef _ctx_w_error mp <- readIORef _ctx_package_constraints- put ctx $ mk_build_depends mp lst+ put ctx $ mk_build_depends we mp lst where lst = LBS.words $ captureText [cp|list|] mtch mtch = allMatches mtchs !! 0@@ -170,14 +177,24 @@ True -> LBS.unpack $ _te_name te <> "-test" False -> LBS.unpack $ _te_name te -mk_build_depends :: Map.Map LBS.ByteString LBS.ByteString+mk_build_depends :: Bool+ -> Map.Map LBS.ByteString LBS.ByteString -> [LBS.ByteString] -> LBS.ByteString-mk_build_depends mp pks = LBS.unlines $- (:) " Build-depends:" $- map fmt $ zip (True : repeat False) $- L.sortBy comp pks+mk_build_depends we mp pks = LBS.unlines $+ [ " Default-Language: Haskell2010"+ , " GHC-Options:"+ , " -Wall"+ , " -fwarn-tabs"+ , " " <> w_error_or_warn+ , ""+ , " Build-depends:"+ ] ++ (map fmt $ zip (True : repeat False) $ L.sortBy comp pks) where+ w_error_or_warn = case we of+ True -> "-Werror"+ False -> "-Wwarn"+ fmt (isf,pk) = LBS.pack $ printf " %c %-20s %s" (if isf then ' ' else ',')
examples/re-gen-modules.lhs view
@@ -82,9 +82,9 @@ -> (ModPath,SedScript RE) tdfa_edit mp bs_lbs import_lbs = (,) mp $ Pipe- [ (,) module_re $ EDIT_tpl $ LBS.pack mp- , (,) import_re $ EDIT_tpl import_lbs- , (,) bs_re $ EDIT_tpl bs_lbs+ [ (,) module_re $ Template $ LBS.pack mp+ , (,) import_re $ Template import_lbs+ , (,) bs_re $ Template bs_lbs ] pcre_edit :: ModPath@@ -93,10 +93,10 @@ -> (ModPath,SedScript RE) pcre_edit mp bs_lbs import_lbs = (,) mp $ Pipe- [ (,) tdfa_re $ EDIT_tpl "PCRE"- , (,) module_re $ EDIT_tpl $ LBS.pack mp- , (,) import_re $ EDIT_tpl import_lbs- , (,) bs_re $ EDIT_tpl bs_lbs+ [ (,) tdfa_re $ Template "PCRE"+ , (,) module_re $ Template $ LBS.pack mp+ , (,) import_re $ Template import_lbs+ , (,) bs_re $ Template bs_lbs ] type ModPath = String
examples/re-include.lhs view
@@ -50,8 +50,8 @@ loop :: FilePath -> FilePath -> IO () loop = sed $ Select- [ (,) [re|^%include ${file}(@{%string}) ${rex}(@{%string})$|] $ EDIT_fun TOP include_file- , (,) [re|^.*$|] $ EDIT_fun TOP $ \_ _ _ _->return Nothing+ [ (,) [re|^%include ${file}(@{%string}) ${rex}(@{%string})$|] $ Function TOP include_file+ , (,) [re|^.*$|] $ Function TOP $ \_ _ _ _->return Nothing ] \end{code}
examples/re-nginx-log-processor.lhs view
@@ -121,7 +121,7 @@ ] where on rex src prs =- (,) (rex lpo) $ EDIT_fun TOP $ process_line ctx src prs+ (,) (rex lpo) $ Function TOP $ process_line ctx src prs parse_def = fmap capturedText . matchCapture \end{code}@@ -556,7 +556,7 @@ deriving (IsString,Ord,Eq,Show) parse_user :: Replace a => a -> Maybe User-parse_user = Just . User . LBS.pack . unpack_+parse_user = Just . User . LBS.pack . unpackE --@@ -564,7 +564,7 @@ -- parse_pid_tid :: Replace a => a -> Maybe (Int,Int)-parse_pid_tid x = case allMatches $ unpack_ x S.*=~ [re|@{%nat}|] of+parse_pid_tid x = case allMatches $ unpackE x S.*=~ [re|@{%nat}|] of [cs,cs'] -> (,) <$> p cs <*> p cs' _ -> Nothing where
examples/re-prep.lhs view
@@ -12,7 +12,6 @@ ) where import Control.Applicative-import qualified Control.Monad as M import qualified Data.ByteString.Lazy.Char8 as LBS import Data.IORef import Data.Maybe@@ -26,7 +25,6 @@ import System.Environment import TestKit import Text.Heredoc-import Text.Printf import Text.RE.Edit import Text.RE.TDFA.ByteString.Lazy import qualified Text.RE.TDFA.Text as TT@@ -49,8 +47,8 @@ where is_file = not . (== "--") . take 2 - doc fn fn' = docMode >>= \dm -> loop dm fn fn'- gen fn fn' = genMode >>= \gm -> loop gm fn fn'+ doc fn fn' = prep_tut Doc fn fn'+ gen fn fn' = genMode >>= \gm -> prep_tut gm fn fn' usage = do pnm <- getProgName@@ -77,86 +75,61 @@ -- or a Haskell testsuite and includes any IO-accessible state -- needed by the relevant processor data MODE- = Doc DocState -- ^ document-generation state+ = Doc -- ^ generating mardown+lhs input for pandoc | Gen GenState -- ^ adjusting-the-program-for-testing state \end{code} The `DocState` is initialised to `Outside` and flips though the different states as it traverses a code block, so that we can wrap code-blocks in special <div class="replcodeblock"> blocks when their+blocks in special `<div class="replcodeblock">` blocks when their first line indicates that it contains a REPL calculation, which the style sheet can pick up and present accordingly. \begin{code}-data DocMode- = Outside -- not inside a begin{code} ... \end{code} block- | Beginning -- at the start of a begin{code} ... \end{code} block- | InsideRepl -- inside a REPL code block- | InsideProg -- inside a non-REPL code block- deriving (Eq,Show)--type DocState = IORef DocMode--genMode :: IO MODE-genMode = Gen <$> newIORef []-\end{code}--\begin{code} -- | the state is the accumulated test function identifiers for -- generating the list of them gets added to the end of the programme type GenState = IORef [String] -docMode :: IO MODE-docMode = Doc <$> newIORef Outside+genMode :: IO MODE+genMode = Gen <$> newIORef [] \end{code} \begin{code}-loop :: MODE -> FilePath -> FilePath -> IO ()-loop mode =+prep_tut :: MODE -> FilePath -> FilePath -> IO ()+prep_tut mode = sed $ Select- [ (,) [re|^%include ${file}(@{%string}) ${rex}(@{%string})$|] $ EDIT_fun TOP $ inclde mode- , (,) [re|^%main ${arg}(top|bottom)$|] $ EDIT_gen $ main_ mode- , (,) [re|^\\begin\{code\}$|] $ EDIT_gen $ begin mode- , (,) [re|^${fn}(evalme@{%id}) = checkThis ${arg}(@{%string}).*$|] $ EDIT_fun TOP $ evalme mode- , (,) [re|^\\end\{code\}$|] $ EDIT_fun TOP $ end mode- , (,) [re|^.*$|] $ EDIT_fun TOP $ other mode+ [ (,) [re|^%include ${file}(@{%string}) ${rex}(@{%string})$|] $ Function TOP $ inclde mode+ , (,) [re|^%main ${arg}(top|bottom)$|] $ LineEdit $ main_ mode+ , (,) [re|^${fn}(evalme@{%id}) = checkThis ${arg}(@{%string}) \(${ans}([^)]+)\) \$ *${exp}(.*)$|]+ $ Function TOP $ evalme mode+ , (,) [re|^.*$|] $ Function TOP $ passthru ] \end{code} \begin{code}-inclde, evalme, end,- other :: MODE- -> LineNo- -> Match LBS.ByteString- -> Location- -> Capture LBS.ByteString- -> IO (Maybe LBS.ByteString)+inclde,+ evalme :: MODE+ -> LineNo+ -> Match LBS.ByteString+ -> Location+ -> Capture LBS.ByteString+ -> IO (Maybe LBS.ByteString) -main_,- begin :: MODE- -> LineNo- -> Matches LBS.ByteString- -> IO (LineEdit LBS.ByteString)+main_ :: MODE+ -> LineNo+ -> Matches LBS.ByteString+ -> IO (LineEdit LBS.ByteString) -inclde (Doc _ ) = includeDoc+inclde Doc = includeDoc inclde (Gen _ ) = passthru -main_ (Doc _ ) = mainDoc+main_ Doc = delete main_ (Gen gs) = mainGen gs -begin (Doc ds) = beginDoc ds-begin (Gen _ ) = passthru_g--evalme (Doc ds) = evalmeDoc ds+evalme Doc = evalmeDoc evalme (Gen gs) = evalmeGen gs -end (Doc ds) = endDoc ds-end (Gen _ ) = passthru--other (Doc ds) = otherDoc ds-other (Gen _ ) = passthru- passthru :: LineNo -> Match LBS.ByteString -> Location@@ -164,10 +137,10 @@ -> IO (Maybe LBS.ByteString) passthru _ _ _ _ = return Nothing -passthru_g :: LineNo- -> Matches LBS.ByteString- -> IO (LineEdit LBS.ByteString)-passthru_g _ _ = return NoEdit+delete :: LineNo+ -> Matches LBS.ByteString+ -> IO (LineEdit LBS.ByteString)+delete _ _ = return Delete \end{code} @@ -196,8 +169,7 @@ pd "RE/Tools/Sed" pd "RE/Internal/NamedCaptures" -- render the tutorial in HTML- dm <- docMode- loop dm "examples/re-tutorial-master.lhs" "tmp/re-tutorial.lhs"+ prep_tut Doc "examples/re-tutorial-master.lhs" "tmp/re-tutorial.lhs" createDirectoryIfMissing False "tmp" pandoc_lhs' "re-tutorial.lhs"@@ -206,7 +178,7 @@ "docs/re-tutorial.html" -- generate the tutorial-based tests gm <- genMode- loop gm "examples/re-tutorial-master.lhs" "examples/re-tutorial.lhs"+ prep_tut gm "examples/re-tutorial-master.lhs" "examples/re-tutorial.lhs" putStrLn ">> examples/re-tutorial.lhs" pages where@@ -238,54 +210,15 @@ \end{code} \begin{code}-mainDoc :: LineNo- -> Matches LBS.ByteString- -> IO (LineEdit LBS.ByteString)-mainDoc _ _ = return Delete-\end{code}--\begin{code}-beginDoc :: DocState- -> LineNo- -> Matches LBS.ByteString- -> IO (LineEdit LBS.ByteString)-beginDoc ds _ _ = writeIORef ds Beginning >> return Delete-\end{code}--\begin{code}-evalmeDoc, endDoc, otherDoc :: DocState- -> LineNo- -> Match LBS.ByteString- -> Location- -> Capture LBS.ByteString- -> IO (Maybe LBS.ByteString)--evalmeDoc ds lno _ _ _ = do- dm <- readIORef ds- M.when (dm/=Beginning) $- bad_state "evalme" lno dm- writeIORef ds InsideRepl- return $ Just $ "<div class=\"replcodeblock\">\n"<>begin_code--endDoc ds lno _ _ _ = do- dm <- readIORef ds- case dm of- Outside -> bad_state "end" lno dm- Beginning -> return $ Just $ begin_code <> "\n" <> end_code- InsideRepl -> return $ Just $ end_code <> "\n</div>"- InsideProg -> return Nothing--otherDoc ds _ mtch _ _ = do- dm <- readIORef ds- case dm of- Beginning -> do- writeIORef ds InsideProg- return $ Just $ begin_code <> "\n" <> matchSource mtch- _ -> return Nothing--bad_state :: String -> LineNo -> DocMode -> IO a-bad_state lab lno dm = error $- printf "Bad document syntax: %s: %d: %s" lab (getLineNo lno) $ show dm+evalmeDoc :: LineNo+ -> Match LBS.ByteString+ -> Location+ -> Capture LBS.ByteString+ -> IO (Maybe LBS.ByteString)+evalmeDoc _ mtch _ _ = return $ Just $ replace mtch $ LBS.intercalate "\n"+ [ "ghci> ${exp}"+ , "${ans}"+ ] \end{code} @@ -300,9 +233,9 @@ -> Capture LBS.ByteString -> IO (Maybe LBS.ByteString) evalmeGen gs _ mtch0 _ _ = Just <$>- replaceCapturesM replace_ ALL f mtch0+ replaceCapturesM replaceMethods ALL f mtch0 where- f mtch loc cap = case _loc_capture loc of+ f mtch loc cap = case locationCapture loc of 2 -> do modifyIORef gs (ide:) return $ Just $ LBS.pack $ show ide@@ -354,8 +287,6 @@ end_code = "\\"<>"end{code}" \end{code} -- \begin{code} mk_list :: [String] -> [LBS.ByteString] mk_list [] = ["[]"]@@ -462,6 +393,7 @@ data Page = PG_index | PG_about+ | PG_reblog | PG_contact | PG_build_status | PG_installation@@ -490,6 +422,7 @@ page_title pg = case pg of PG_index -> "Home" PG_about -> "About"+ PG_reblog -> "Blog" PG_contact -> "Contact" PG_build_status -> "Build Status" PG_installation -> "Installation"@@ -557,7 +490,7 @@ set_title :: LBS.ByteString -> LBS.ByteString -> LBS.ByteString set_title ttl lbs = fromMaybe oops $ flip sed' lbs $ Pipe- [ (,) [re|<<\$title\$>>|] $ EDIT_fun TOP $ \_ _ _ _->return $ Just ttl+ [ (,) [re|<<\$title\$>>|] $ Function TOP $ \_ _ _ _->return $ Just ttl ] where -- runIdentity added to base in 4.9 only@@ -573,10 +506,10 @@ return (hdgs,lbs1<>lbs2) where scr rf_h rf_t = Select- [ (,) [re|^%heading#${ide}(@{%id}) +${ttl}([^ ].*)$|] $ EDIT_fun TOP $ heading mmd rf_t rf_h- , (,) [re|^- \[ \] +${itm}(.*)$|] $ EDIT_fun TOP $ task_list mmd rf_t False- , (,) [re|^- \[[Xx]\] +${itm}(.*)$|] $ EDIT_fun TOP $ task_list mmd rf_t True- , (,) [re|^.*$|] $ EDIT_fun TOP $ fin_task_list mmd rf_t+ [ (,) [re|^%heading#${ide}(@{%id}) +${ttl}([^ ].*)$|] $ Function TOP $ heading mmd rf_t rf_h+ , (,) [re|^- \[ \] +${itm}(.*)$|] $ Function TOP $ task_list mmd rf_t False+ , (,) [re|^- \[[Xx]\] +${itm}(.*)$|] $ Function TOP $ task_list mmd rf_t True+ , (,) [re|^.*$|] $ Function TOP $ fin_task_list mmd rf_t ] heading :: MarkdownMode@@ -639,30 +572,35 @@ ftr = [here| </ul> </div> <div class="supplementary widget" id="github">- <a href="https://github.com/iconnect/regex"><img src="images/code.svg" alt="github code" /> Code</a>+ <a href="http://code.regex.uk"><img src="images/code.svg" alt="github code" /> Code</a> </div> <div class="supplementary widget" id="github-issues">- <a href="https://github.com/iconnect/regex/issues"><img src="images/issue-opened.svg" alt="github code" /> Issues</a>+ <a href="http://issues.regex.uk"><img src="images/issue-opened.svg" alt="github issues" /> Issues</a> </div> <div class="widget-divider"> </div>- <div class="supplementary widget" id="build-status">+ <div class="supplementary widget" id="blog-badge">+ <a href="http://blog.regex.uk">+ <img src="badges/blog.svg" alt="regex blog" />+ </a>+ </div>+ <div class="supplementary widget" id="hackage-badge"> <a href="https://hackage.haskell.org/package/regex"> <img src="badges/hackage.svg" alt="hackage version" /> </a> </div>- <div class="supplementary widget" id="build-status">+ <div class="supplementary widget" id="build-status-badge"> <a href="build-status"> <img src="badges/build-status.svg" alt="build status" /> </a> </div> <div class="supplementary widget" id="maintainers-contact"> <a href="mailto:maintainers@regex.uk">- <img src="badges/maintainers-contact.svg" alt="build status" />+ <img src="badges/maintainers-contact.svg" alt="maintainers contact" /> </a> </div> <div class="supplementary widget" id="feedback-contact"> <a href="mailto:feedback@regex.uk">- <img src="badges/feedback-contact.svg" alt="build status" />+ <img src="badges/feedback-contact.svg" alt="deedback contact" /> </a> </div> <div class="supplementary widget twitter">@@ -676,7 +614,7 @@ pst_body_html :: LBS.ByteString pst_body_html = [here| </div> </div>-|]+|] <> tracking \end{code} @@ -793,7 +731,7 @@ ft = LBS.concat [ "</div>"- ]+ ] <> tracking repo_url = LBS.concat [ "https://github.com/iconnect/regex/blob/master/"@@ -807,12 +745,17 @@ \begin{code} tweak_md :: MarkdownMode -> LBS.ByteString -> LBS.ByteString-tweak_md MM_github lbs = lbs-tweak_md MM_pandoc lbs = lbs-tweak_md MM_hackage lbs = fromMaybe oops $ flip sed' lbs $ Pipe- [ (,) [re|<br/>$|] $ EDIT_fun TOP $ \_ _ _ _->return $ Just "\n"- ]+tweak_md mm lbs = case mm of+ MM_github -> lbs+ MM_pandoc -> awk+ [ (,) [re|<https?://${rest}([^)]+)>|] $ Template "[${rest}]($0)"+ ]+ MM_hackage -> awk+ [ (,) [re|<br/>$|] $ Template "\n"+ ] where+ awk = fromMaybe oops . flip sed' lbs . Pipe+ -- runIdentity added to base in 4.9 only oops = error "tweak_md" \end{code}@@ -823,19 +766,37 @@ \begin{code} branding :: LBS.ByteString-branding = [here|<a href="." style="Arial, 'Helvetica Neue', Helvetica, sans-serif;" id="branding">[<span style='color:red;'>re</span>|${<span style='color:red;'>gex</span>}(.*)|<span></span>]</a>|]+branding = [here|<a href="." style="font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;" id="branding">[<span style='color:red;'>re</span>|${<span style='color:red;'>gex</span>}(.*)|<span></span>]</a>|] \end{code} +tracking+--------++\begin{code}+tracking :: LBS.ByteString+tracking = [here| <script>+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)+ })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');++ ga('create', 'UA-92650418-1', 'auto');+ ga('send', 'pageview');++ </script>+|]+\end{code}++ testing ------- \begin{code} test :: IO () test = do- dm <- docMode- test_pp "pp-doc" (loop dm) "data/pp-test.lhs" "data/pp-result-doc.lhs"+ test_pp "pp-doc" (prep_tut Doc) "data/pp-test.lhs" "data/pp-result-doc.lhs" gm <- genMode- test_pp "pp-gen" (loop gm) "data/pp-test.lhs" "data/pp-result-gen.lhs"+ test_pp "pp-gen" (prep_tut gm ) "data/pp-test.lhs" "data/pp-result-gen.lhs" putStrLn "tests passed" \end{code}
examples/re-tests.lhs view
@@ -59,7 +59,7 @@ [ prelude_tests , parsing_tests , core_tests- , replace_tests+ , replaceMethodstests , options_tests , namedCapturesTestTree , many_tests@@ -202,55 +202,55 @@ assertEqual "not.anyMatches" False $ anyMatches mtchs ] -replace_tests :: TestTree-replace_tests = testGroup "Replace"+replaceMethodstests :: TestTree+replaceMethodstests = testGroup "Replace" [ testCase "String/single" $ do let m = str_ =~ regex_ :: Match String- r = replaceCaptures' ALL fmt m- assertEqual "replaceCaptures'" r "(0:0:(0:1:a) (0:2:bbbb)) aa b"+ r = replaceCaptures ALL fmt m+ assertEqual "replaceCaptures" r "(0:0:(0:1:a) (0:2:bbbb)) aa b" , testCase "String/alt" $ do let ms = str_ =~ regex_ :: Matches String- r = replaceAllCaptures' ALL fmt ms+ r = replaceAllCaptures ALL fmt ms chk r , testCase "String" $ do let ms = str_ =~ regex_ :: Matches String- r = replaceAllCaptures' ALL fmt ms+ r = replaceAllCaptures ALL fmt ms chk r , testCase "ByteString" $ do let ms = B.pack str_ =~ regex_ :: Matches B.ByteString- r = replaceAllCaptures' ALL fmt ms+ r = replaceAllCaptures ALL fmt ms chk r , testCase "LBS.ByteString" $ do let ms = LBS.pack str_ =~ regex_ :: Matches LBS.ByteString- r = replaceAllCaptures' ALL fmt ms+ r = replaceAllCaptures ALL fmt ms chk r , testCase "Seq Char" $ do let ms = S.fromList str_ =~ regex_ :: Matches (S.Seq Char) f = \_ (Location i j) Capture{..} -> Just $ S.fromList $ "(" <> show i <> ":" <> show_co j <> ":" <> F.toList capturedText <> ")"- r = replaceAllCaptures' ALL f ms- assertEqual "replaceAllCaptures'" r $+ r = replaceAllCaptures ALL f ms+ assertEqual "replaceAllCaptures" r $ S.fromList "(0:0:(0:1:a) (0:2:bbbb)) (1:0:(1:1:aa) (1:2:b))" , testCase "Text" $ do let ms = T.pack str_ =~ regex_ :: Matches T.Text- r = replaceAllCaptures' ALL fmt ms+ r = replaceAllCaptures ALL fmt ms chk r , testCase "LT.Text" $ do let ms = LT.pack str_ =~ regex_ :: Matches LT.Text- r = replaceAllCaptures' ALL fmt ms+ r = replaceAllCaptures ALL fmt ms chk r ] where chk r = assertEqual- "replaceAllCaptures'"+ "replaceAllCaptures" r "(0:0:(0:1:a) (0:2:bbbb)) (1:0:(1:1:aa) (1:2:b))" fmt :: (IsString s,Replace s) => a -> Location -> Capture s -> Maybe s- fmt _ (Location i j) Capture{..} = Just $ "(" <> pack_ (show i) <> ":" <>- pack_ (show_co j) <> ":" <> capturedText <> ")"+ fmt _ (Location i j) Capture{..} = Just $ "(" <> packE (show i) <> ":" <>+ packE (show_co j) <> ":" <> capturedText <> ")" show_co (CaptureOrdinal j) = show j @@ -360,10 +360,10 @@ , TDFA.reBlockInsensitive , TDFA.re_ ]- , testCase "TDFA.regexType" $ TDFA @=? TDFA.regexType- , testCase "TDFA.reOptions" $ Simple @=? _options_mode (TDFA.reOptions tdfa_re)- , testCase "TDFA.makeOptions md" $ Block @=? _options_mode (makeOptions Block :: Options_ TDFA.RE TDFA_.CompOption TDFA_.ExecOption)- , testCase "TDFA.preludeTestsFailing" $ [] @=? TDFA.preludeTestsFailing+ , testCase "TDFA.regexType" $ TDFA @=? TDFA.regexType+ , testCase "TDFA.reOptions" $ assert_empty_macs $ optionsMacs (TDFA.reOptions tdfa_re)+ , testCase "TDFA.makeOptions md" $ assert_empty_macs $ optionsMacs tdfa_opts+ , testCase "TDFA.preludeTestsFailing" $ [] @=? TDFA.preludeTestsFailing , ne_string "TDFA.preludeTable" TDFA.preludeTable , ne_string "TDFA.preludeSources" TDFA.preludeSources , testGroup "TDFA.preludeSummary"@@ -386,10 +386,10 @@ , PCRE.reBlockInsensitive , PCRE.re_ ]- , testCase "PCRE.regexType" $ PCRE @=? PCRE.regexType- , testCase "PCRE.reOptions" $ Simple @=? _options_mode (PCRE.reOptions pcre_re)- , testCase "PCRE.makeOptions md" $ Block @=? _options_mode (makeOptions Block :: Options_ PCRE.RE PCRE_.CompOption PCRE_.ExecOption)- , testCase "PCRE.preludeTestsFailing" $ [] @=? PCRE.preludeTestsFailing+ , testCase "PCRE.regexType" $ PCRE @=? PCRE.regexType+ , testCase "PCRE.reOptions" $ assert_empty_macs $ optionsMacs (PCRE.reOptions pcre_re)+ , testCase "PCRE.makeOptions md" $ assert_empty_macs $ optionsMacs pcre_opts+ , testCase "PCRE.preludeTestsFailing" $ [] @=? PCRE.preludeTestsFailing , ne_string "PCRE.preludeTable" PCRE.preludeTable , ne_string "PCRE.preludeTable" PCRE.preludeSources , testGroup "PCRE.preludeSummary"@@ -403,10 +403,18 @@ ] ] where- tdfa_re = fromMaybe oops $ TDFA.compileRegex () ".*"- pcre_re = fromMaybe oops $ PCRE.compileRegex () ".*"+ tdfa_re = fromMaybe oops $ TDFA.compileRegex tdfa_opts ".*"+ pcre_re = fromMaybe oops $ PCRE.compileRegex pcre_opts ".*" - oops = error "misc_tests"+ tdfa_opts = makeOptions no_macs_t :: Options_ TDFA.RE TDFA_.CompOption TDFA_.ExecOption+ pcre_opts = makeOptions no_macs_p :: Options_ PCRE.RE PCRE_.CompOption PCRE_.ExecOption++ no_macs_t = HM.fromList [] :: Macros TDFA.RE+ no_macs_p = HM.fromList [] :: Macros PCRE.RE++ oops = error "misc_tests"++ assert_empty_macs = assertBool "macros not empty" . HM.null qq_tc :: String -> (QuasiQuoter->String->a) -> TestTree qq_tc sc prj = testCase sc $
examples/re-tutorial.lhs view
@@ -119,10 +119,9 @@ in the source program, presented as calculations when rendered in HTML and tested that they have the expected result. \begin{code}-evalme_LOA_00 = checkThis "evalme_LOA_00" 0 $- length []+evalme_LOA_00 = checkThis "evalme_LOA_00" (0) $ length [] \end{code}-This trivial example calculation will be tested for equality to 0.+This trivial example calculation will be tested for zero-ness. Matching with the regex-base Operators@@ -132,8 +131,7 @@ `Bool` context `=~` will evaluate to True iff the string on the left matches the RE on the right. \begin{code}-evalme_TRD_00 = checkThis "evalme_TRD_00" True $- ("2016-01-09 2015-12-5 2015-10-05" =~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] :: Bool)+evalme_TRD_00 = checkThis "evalme_TRD_00" (True) $ ("2016-01-09 2015-12-5 2015-10-05" =~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] :: Bool) \end{code} Note that we enclose the RE itself in `[re|` ... `|]` quasi quote brackets, allowing the compiler to run some regex code at compile time to verify that@@ -143,24 +141,19 @@ Used in an `Int` context `=~` will count the number of matches in the target string. \begin{code}-evalme_TRD_01 = checkThis "evalme_TRD_01" 2 $- ("2016-01-09 2015-12-5 2015-10-05" =~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] :: Int)+evalme_TRD_01 = checkThis "evalme_TRD_01" (2) $ ("2016-01-09 2015-12-5 2015-10-05" =~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] :: Int) \end{code} To determine the string that has matched the modaic `=~~` operator can be used in a `Maybe` context. \begin{code}-evalme_TRD_02 = checkThis "evalme_TRD_02" (Just "2016-01-09") $- ("2016-01-09 2015-12-5 2015-10-05" =~~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] :: Maybe String)+evalme_TRD_02 = checkThis "evalme_TRD_02" (Just "2016-01-09") $ ("2016-01-09 2015-12-5 2015-10-05" =~~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] :: Maybe String) \end{code}-This should evaluate to `Just "2016-01-09"`. A `=~` in a `[[String]]` extracts all of the matched substrings: \begin{code}-evalme_TRD_04 = checkThis "evalme_TRD_04" [["2016-01-09"],["2015-10-05"]] $- ("2016-01-09 2015-12-5 2015-10-05" =~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] :: [[String]])+evalme_TRD_04 = checkThis "evalme_TRD_04" ([["2016-01-09"],["2015-10-05"]]) $ ("2016-01-09 2015-12-5 2015-10-05" =~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] :: [[String]]) \end{code}-yields `[["2016-01-09"],["2015-10-05"]]`. regex provides special operators and types for extracting the first match or all of the non-overlapping substrings matching a regular expression@@ -177,18 +170,14 @@ match. (It's result type will be explained below.) The boolean `matched` function can be used to test whether a match was found. \begin{code}-evalme_SGL_01 = checkThis "evalme_SGL_01" True $- matched $ "2016-01-09 2015-12-5 2015-10-05" ?=~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|]+evalme_SGL_01 = checkThis "evalme_SGL_01" (True) $ matched $ "2016-01-09 2015-12-5 2015-10-05" ?=~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] \end{code}-This should yield `True`. To get the matched text use `matchText`, which returns `Nothing` if no match was found in the search string. \begin{code}-evalme_SGL_02 = checkThis "evalme_SGL_02" (Just "2016-01-09") $- matchedText $ "2016-01-09 2015-12-5 2015-10-05" ?=~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|]+evalme_SGL_02 = checkThis "evalme_SGL_02" (Just "2016-01-09") $ matchedText $ "2016-01-09 2015-12-5 2015-10-05" ?=~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] \end{code}-This should yield `Just "2016-01-09"`. Multiple Matches with `*=~`@@ -197,22 +186,18 @@ Use `*=~` to locate all of the non-overlapping substrings that matches a RE. `anyMatches` will return `True` iff any matches are found (and they will be). \begin{code}-evalme_MLT_01 = checkThis "evalme_MLT_01" True $- anyMatches $ "2016-01-09 2015-12-5 2015-10-05" *=~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|]+evalme_MLT_01 = checkThis "evalme_MLT_01" (True) $ anyMatches $ "2016-01-09 2015-12-5 2015-10-05" *=~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] \end{code} `countMatches` will tell us how many sub-strings matched (2). \begin{code}-evalme_MLT_02 = checkThis "evalme_MLT_02" 2 $- countMatches $ "2016-01-09 2015-12-5 2015-10-05" *=~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|]+evalme_MLT_02 = checkThis "evalme_MLT_02" (2) $ countMatches $ "2016-01-09 2015-12-5 2015-10-05" *=~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] \end{code} `matches` will return all of the matches. \begin{code}-evalme_MLT_03 = checkThis "evalme_MLT_03" ["2016-01-09","2015-10-05"] $- matches $ "2016-01-09 2015-12-5 2015-10-05" *=~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|]+evalme_MLT_03 = checkThis "evalme_MLT_03" (["2016-01-09","2015-10-05"]) $ matches $ "2016-01-09 2015-12-5 2015-10-05" *=~ [re|[0-9]{4}-[0-9]{2}-[0-9]{2}|] \end{code}-This should yield `["2016-01-09","2015-10-05"]`. Simple Text Replacement@@ -243,10 +228,8 @@ \end{code} with \begin{code}-evalme_RPL_01 = checkThis "evalme_RPL_01" "09/01/2016 2015-12-5 05/10/2015" $- uk_dates "2016-01-09 2015-12-5 2015-10-05"+evalme_RPL_01 = checkThis "evalme_RPL_01" ("09/01/2016 2015-12-5 05/10/2015") $ uk_dates "2016-01-09 2015-12-5 2015-10-05" \end{code}-yielding `"09/01/2016 2015-12-5 05/10/2015"`. The same function written with numbered captures: \begin{code}@@ -256,8 +239,7 @@ \end{code} with \begin{code}-evalme_RPL_02 = checkThis "evalme_RPL_02" "09/01/2016 2015-12-5 05/10/2015" $- uk_dates' "2016-01-09 2015-12-5 2015-10-05"+evalme_RPL_02 = checkThis "evalme_RPL_02" ("09/01/2016 2015-12-5 05/10/2015") $ uk_dates' "2016-01-09 2015-12-5 2015-10-05" \end{code} yielding the same result. @@ -333,8 +315,7 @@ By default regular expressions are of the multi-line case-sensitive variety so this query \begin{code}-evalme_SOP_01 = checkThis "evalme_SOP_01" 2 $- countMatches $ "0a\nbb\nFe\nA5" *=~ [re|[0-9a-f]{2}$|]+evalme_SOP_01 = checkThis "evalme_SOP_01" (2) $ countMatches $ "0a\nbb\nFe\nA5" *=~ [re|[0-9a-f]{2}$|] \end{code} finds 2 matches, the '$' anchor matching each of the newlines, but only the first two lowercase hex numbers matching the RE. The case sensitivity@@ -354,30 +335,25 @@ So while the default setup \begin{code}-evalme_SOP_02 = checkThis "evalme_SOP_02" 2 $- countMatches $ "0a\nbb\nFe\nA5" *=~ [reMultilineSensitive|[0-9a-f]{2}$|]+evalme_SOP_02 = checkThis "evalme_SOP_02" (2) $ countMatches $ "0a\nbb\nFe\nA5" *=~ [reMultilineSensitive|[0-9a-f]{2}$|] \end{code} finds 2 matches, a case-insensitive RE \begin{code}-evalme_SOP_03 = checkThis "evalme_SOP_03" 4 $- countMatches $ "0a\nbb\nFe\nA5" *=~ [reMultilineInsensitive|[0-9a-f]{2}$|]+evalme_SOP_03 = checkThis "evalme_SOP_03" (4) $ countMatches $ "0a\nbb\nFe\nA5" *=~ [reMultilineInsensitive|[0-9a-f]{2}$|] \end{code} finds 4 matches, while a non-multiline RE \begin{code}-evalme_SOP_04 = checkThis "evalme_SOP_04" 0 $- countMatches $ "0a\nbb\nFe\nA5" *=~ [reBlockSensitive|[0-9a-f]{2}$|]+evalme_SOP_04 = checkThis "evalme_SOP_04" (0) $ countMatches $ "0a\nbb\nFe\nA5" *=~ [reBlockSensitive|[0-9a-f]{2}$|] \end{code} finds no matches but a non-multiline, case-insensitive match \begin{code}-evalme_SOP_05 = checkThis "evalme_SOP_05" 1 $- countMatches $ "0a\nbb\nFe\nA5" *=~ [reBlockInsensitive|[0-9a-f]{2}$|]+evalme_SOP_05 = checkThis "evalme_SOP_05" (1) $ countMatches $ "0a\nbb\nFe\nA5" *=~ [reBlockInsensitive|[0-9a-f]{2}$|] \end{code} finds the final match. For the hard of typing the shortforms are available. \begin{code}-evalme_SOP_06 = checkThis "evalme_SOP_06" True $- matched $ "SuperCaliFragilisticExpialidocious" ?=~ [reMI|supercalifragilisticexpialidocious|]+evalme_SOP_06 = checkThis "evalme_SOP_06" (True) $ matched $ "SuperCaliFragilisticExpialidocious" ?=~ [reMI|supercalifragilisticexpialidocious|] \end{code} @@ -385,55 +361,61 @@ ------------------------------- Sometimes you will need to process each string captured by an RE with a-function. `replaceAllCaptures` takes a `Phi` and a `Matches` and-applies the function to each captured substring according to the-`Context` specified in `Phi`, as we can see in the following example function-to clean up all of the mis-formatted dates in the argument string,+function. `replaceAllCaptures` takes a `Context`, a substitution+function and a `Matches` and applies the function to each captured+substring according to the `Context`, as we can see in the following+example function to clean up all of the mis-formatted dates in the+argument string, \begin{code} fixup_dates :: String -> String fixup_dates src =- replaceAllCaptures phi $ src *=~ [re|([0-9]+)-([0-9]+)-([0-9]+)|]+ replaceAllCaptures SUB phi $ src *=~ [re|([0-9]+)-([0-9]+)-([0-9]+)|] where- phi = Phi SUB $ \loc s -> case _loc_capture loc of- 1 -> printf "%04d" (read s :: Int)- 2 -> printf "%02d" (read s :: Int)- 3 -> printf "%02d" (read s :: Int)- _ -> error "fixup_date"+ phi _ loc cap = Just $ case locationCapture loc of+ 1 -> printf "%04d" (read s :: Int)+ 2 -> printf "%02d" (read s :: Int)+ 3 -> printf "%02d" (read s :: Int)+ _ -> error "fixup_dates"+ where+ s = capturedText cap \end{code} which will fix up our running example \begin{code}-evalme_RPF_01 = checkThis "evalme_RPF_01" "2016-01-09 2015-12-05 2015-10-05" $- fixup_dates "2016-01-09 2015-12-5 2015-10-05"+evalme_RPF_01 = checkThis "evalme_RPF_01" ("2016-01-09 2015-12-05 2015-10-05") $ fixup_dates "2016-01-09 2015-12-5 2015-10-05" \end{code}-returning `"2016-01-09 2015-12-05 2015-10-05"`. -The `Phi`, `Context` and `Location` types are defined in-`Text.RE.Replace` as follows.+The `replaceAllCaptures` function is of type -%include "Text/RE/Replace.lhs" "^data Phi"+%include "Text/RE/Replace.lhs" "replaceAllCaptures ::" +and the `Context` and `Location` types are defined in+`Text.RE.Replace` as follows,++%include "Text/RE/Replace.lhs" "^data Context"+ The processing function gets applied to the captures specified by the `Context`, which can be directed to process `ALL` of the captures, including the substring captured by the whole RE and all of the subsidiary capture, or just the `TOP`, `0` capture that the whole RE matches, or just the `SUB` (subsidiary) captures, as was the case above. -If this doesn't provide enough flexibility, the `replaceAllCaptures'`-function accepts a processing function that takes the full `Match`-context for each capture along with the `Location` and the `Capture`-itself.+The substitution function takes the `Match` corresponding to the current+redex being processed, the `Location` information specifying redex _n_+redex and capure _i_, and the `Capure` being substituted. Our substitution+function didn't need the `Match` context so it ignored it. -%include "Text/RE/Replace.lhs" "replaceAllCaptures' ::"+The substition function either return `Nothing` to indicate that no+substitution should be made or the replacement text. -The above fixup function can be extended to enclose whole date in-square brackets and rewritten with the above more general replacement-function.+The above fixup function could be extended to enclose whole date in+square brackets by specifing an `ALL` context and a `0` case for the+substitution function. \begin{code} fixup_and_reformat_dates :: String -> String fixup_and_reformat_dates src =- replaceAllCaptures' ALL f $ src *=~ [re|([0-9]+)-([0-9]+)-([0-9]+)|]+ replaceAllCaptures ALL f $ src *=~ [re|([0-9]+)-([0-9]+)-([0-9]+)|] where- f _ loc cap = Just $ case _loc_capture loc of+ f _ loc cap = Just $ case locationCapture loc of 0 -> printf "[%s]" txt 1 -> printf "%04d" (read txt :: Int) 2 -> printf "%02d" (read txt :: Int)@@ -444,10 +426,8 @@ \end{code} The `fixup_and_reformat_dates` applied to our running example, \begin{code}-evalme_RPF_02 = checkThis "evalme_RPF_02" "[2016-01-09] [2015-12-05] [2015-10-05]" $- fixup_and_reformat_dates "2016-01-09 2015-12-5 2015-10-05"+evalme_RPF_02 = checkThis "evalme_RPF_02" ("[2016-01-09] [2015-12-05] [2015-10-05]") $ fixup_and_reformat_dates "2016-01-09 2015-12-5 2015-10-05" \end{code}-yields `"[2016-01-09] [2015-12-05] [2015-10-05]"`. `Text.RE.Replace` provides analagous functions for replacing the test of a single `Match` returned from `?=~`.@@ -463,8 +443,7 @@ the standard environment start with a '%'. `@{%date}` will match an ISO 8601 date, this \begin{code}-evalme_MAC_00 = checkThis "evalme_MAC_00" 2 $- countMatches $ "2016-01-09 2015-12-5 2015-10-05" *=~ [re|@{%date}|]+evalme_MAC_00 = checkThis "evalme_MAC_00" (2) $ countMatches $ "2016-01-09 2015-12-5 2015-10-05" *=~ [re|@{%date}|] \end{code} picking out the two dates. @@ -501,15 +480,15 @@ %include "Text/RE/Options.lhs" "data Options_" - * `_options_mode` is an experimental feature that controls the RE+ * `optionsMode` is an experimental feature that controls the RE parser. - * `_options_macs` contains the macro definitions used to compile+ * `optionsMacs` contains the macro definitions used to compile the REs (see above Macros section); - * `_options_comp` contains the back end compile-time options;+ * `optionsComp` contains the back end compile-time options; - * `_options_exec` contains the back end execution-time options.+ * `optionsExec` contains the back end execution-time options. (For more information on the options provided by the back ends see the decumentation for `regex-tdfa` and `regex-pcre` as apropriate.)@@ -560,18 +539,10 @@ \end{code} \begin{code}-evalme_OPT_00 = checkThis "evalme_OPT_00" 2 $- countMatches $- "2016-01-09 2015-12-5 2015-10-05" *=~- check_for_failure- (compileRegex () "@{%date}")+evalme_OPT_00 = checkThis "evalme_OPT_00" (2) $ countMatches $ "2016-01-09 2015-12-5 2015-10-05" *=~ check_for_failure (compileRegex () "@{%date}") \end{code} \begin{code}-evalme_OPT_01 = checkThis "evalme_OPT_01" 1 $- countMatches $- "0a\nbb\nFe\nA5" *=~- check_for_failure- (compileRegex BlockInsensitive "[0-9a-f]{2}$")+evalme_OPT_01 = checkThis "evalme_OPT_01" (1) $ countMatches $ "0a\nbb\nFe\nA5" *=~ check_for_failure (compileRegex BlockInsensitive "[0-9a-f]{2}$") \end{code} This will allow you to compile regular expressions when the either the@@ -585,9 +556,7 @@ checking the validity of the RE (with the default options) then you can use the `re_` parser: \begin{code}-evalme_REU_01 = checkThis "evalme_REU_01" 1 $- countMatches $- "0a\nbb\nFe\nA5" *=~ [re_|[0-9a-f]{2}$|] BlockInsensitive+evalme_REU_01 = checkThis "evalme_REU_01" (1) $ countMatches $ "0a\nbb\nFe\nA5" *=~ [re_|[0-9a-f]{2}$|] BlockInsensitive \end{code} Any option `o` such that `IsOption o RE CompOption ExecOption` (i.e., any option type accepted by `compileRegex` above) can be used with@@ -712,7 +681,7 @@ expandMacros_ lu = fixpoint e_m where e_m re_s =- replaceAllCaptures' TOP phi $ re_s *=~ [re|@$(@|\{${name}([^{}]+)\})|]+ replaceAllCaptures TOP phi $ re_s *=~ [re|@$(@|\{${name}([^{}]+)\})|] phi mtch _ cap = case txt == "@@" of True -> Just "@"@@ -730,8 +699,7 @@ For example: \begin{code}-evalme_PMC_00 = checkThis "evalme_PMC_00" "foo MacroID {_MacroID = \"bar\"} baz" $- expandMacros_ (Just . show) "foo @{bar} baz"+evalme_PMC_00 = checkThis "evalme_PMC_00" ("foo MacroID {getMacroID = \"bar\"} baz") $ expandMacros_ (Just . show) "foo @{bar} baz" \end{code} See [Text.RE.Replace](Replace.html) for details.@@ -745,29 +713,29 @@ \begin{code} type Template = String -parse_tpl_ :: Template- -> Match String- -> Location- -> Capture String- -> Maybe String-parse_tpl_ tpl mtch _ _ =- Just $ replaceAllCaptures' TOP phi $+parseTemplateE' :: Template+ -> Match String+ -> Location+ -> Capture String+ -> Maybe String+parseTemplateE' tpl mtch _ _ =+ Just $ replaceAllCaptures TOP phi $ tpl *=~ [re|\$${arg}(\$|[0-9]+|\{${name}([^{}]+)\})|] where phi t_mtch _ _ = case t_mtch !$? [cp|name|] of- Just cap -> this $ CID_name $ CaptureName txt+ Just cap -> this $ IsCaptureName $ CaptureName txt where txt = T.pack $ capturedText cap Nothing -> case t == "$" of True -> Just t- False -> this $ CID_ordinal $ CaptureOrdinal $ read t+ False -> this $ IsCaptureOrdinal $ CaptureOrdinal $ read t where t = capturedText $ capture [cp|arg|] t_mtch this cid = capturedText <$> mtch !$? cid my_replace :: RE -> Template-> String -> String-my_replace rex tpl src = replaceAllCaptures' TOP (parse_tpl_ tpl) $ src *=~ rex+my_replace rex tpl src = replaceAllCaptures TOP (parseTemplateE' tpl) $ src *=~ rex \end{code} It can be tested with our date-reformater example.@@ -780,8 +748,7 @@ This should yield `"2016/01/11"`: \begin{code}-evalme_TPL_00 = checkThis "evalme_TPL_00" "2016/01/11" $- date_reformat "2016-01-11"+evalme_TPL_00 = checkThis "evalme_TPL_00" ("2016/01/11") $ date_reformat "2016-01-11" \end{code} See [Text.RE.Replace](Replace.html)
lib/cabal-masters/executables-incl.cabal view
@@ -6,11 +6,6 @@ Other-Modules: TestKit - Default-Language: Haskell2010- GHC-Options:- -Wall- -fwarn-tabs- %build-depends regex array base base-compat containers bytestring directory regex-base regex-tdfa shelly text %test-exe re-gen-modules@@ -18,11 +13,6 @@ Main-Is: re-gen-modules.lhs - Default-Language: Haskell2010- GHC-Options:- -Wall- -fwarn-tabs- %build-depends regex array base base-compat bytestring directory regex-base regex-tdfa shelly text %test-exe re-include@@ -30,11 +20,6 @@ Main-Is: re-include.lhs - Default-Language: Haskell2010- GHC-Options:- -Wall- -fwarn-tabs- Other-Modules: TestKit @@ -45,11 +30,6 @@ Main-Is: re-nginx-log-processor.lhs - Default-Language: Haskell2010- GHC-Options:- -Wall- -fwarn-tabs- %build-depends regex array base base-compat bytestring directory regex-base regex-tdfa shelly text time time-locale-compat transformers unordered-containers %test-exe re-prep@@ -57,11 +37,6 @@ Main-Is: re-prep.lhs - Default-Language: Haskell2010- GHC-Options:- -Wall- -fwarn-tabs- Other-Modules: TestKit @@ -72,11 +47,6 @@ Main-Is: re-tests.lhs - Default-Language: Haskell2010- GHC-Options:- -Wall- -fwarn-tabs- Other-Modules: TestKit @@ -90,12 +60,7 @@ Other-Modules: TestKit - Default-Language: Haskell2010 Default-Extensions: QuasiQuotes- GHC-Options:- -Wall- -fwarn-tabs- %build-depends regex array base base-compat bytestring containers directory hashable heredoc regex-base regex-tdfa regex-tdfa-text regex-pcre-builtin shelly smallcheck tasty tasty-hunit tasty-smallcheck template-haskell transformers text time time-locale-compat unordered-containers %test re-tutorial-os@@ -106,11 +71,6 @@ Other-Modules: TestKit - Default-Language: Haskell2010 Extensions: OverloadedStrings Default-Extensions: QuasiQuotes- GHC-Options:- -Wall- -fwarn-tabs- %build-depends regex array base base-compat bytestring containers directory hashable heredoc regex-base regex-tdfa regex-tdfa-text regex-pcre-builtin shelly smallcheck tasty tasty-hunit tasty-smallcheck template-haskell transformers text time time-locale-compat unordered-containers
lib/cabal-masters/library-incl.cabal view
@@ -35,9 +35,4 @@ Other-Modules: Text.RE.Internal.AddCaptureNames - Default-Language: Haskell2010- GHC-Options:- -Wall- -fwarn-tabs- %build-depends array bytestring base base-compat containers hashable heredoc regex-base regex-tdfa regex-tdfa-text regex-pcre-builtin template-haskell text time time-locale-compat transformers unordered-containers
lib/cabal-masters/mega-regex.cabal view
@@ -31,6 +31,7 @@ Location: https://github.com/iconnect/regex.git Tag: <<$version$>> +%Werror %include "lib/cabal-masters/constraints-incl.cabal" %include "lib/cabal-masters/library-incl.cabal"
lib/cabal-masters/regex-examples.cabal view
@@ -32,6 +32,7 @@ Location: https://github.com/iconnect/regex.git Tag: <<$version$>> +%Wwarn %include "lib/cabal-masters/constraints-incl.cabal" %include "lib/cabal-masters/executables-incl.cabal"
lib/cabal-masters/regex.cabal view
@@ -33,6 +33,7 @@ Location: https://github.com/iconnect/regex.git Tag: <<$version$>> +%Wwarn %include "lib/cabal-masters/constraints-incl.cabal" %include "lib/cabal-masters/library-incl.cabal"
lib/mega-regex.cabal view
@@ -1,5 +1,5 @@ Name: regex-Version: 0.2.0.4+Version: 0.3.0.0 Synopsis: Toolkit for regex-base Description: A Regular Expression Toolkit for regex-base with Compile-time checking of RE syntax, data types for@@ -62,7 +62,7 @@ Source-Repository this Type: git Location: https://github.com/iconnect/regex.git- Tag: 0.2.0.4+ Tag: 0.3.0.0 @@ -107,6 +107,7 @@ GHC-Options: -Wall -fwarn-tabs+ -Werror Build-depends: array >= 0.4@@ -141,9 +142,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -169,9 +171,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -194,9 +197,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -218,9 +222,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -238,16 +243,17 @@ Main-Is: re-include.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , base >= 4 && < 5 , base-compat >= 0.6.0 , bytestring >= 0.10.2.0@@ -262,16 +268,17 @@ Main-Is: re-include.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , base >= 4 && < 5 , base-compat >= 0.6.0 , bytestring >= 0.10.2.0@@ -290,9 +297,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -318,9 +326,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -342,16 +351,17 @@ Main-Is: re-prep.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , base >= 4 && < 5 , base-compat >= 0.6.0 , bytestring >= 0.10.2.0@@ -368,16 +378,17 @@ Main-Is: re-prep.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , base >= 4 && < 5 , base-compat >= 0.6.0 , bytestring >= 0.10.2.0@@ -394,16 +405,17 @@ Main-Is: re-tests.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -430,16 +442,17 @@ Main-Is: re-tests.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -469,14 +482,15 @@ Other-Modules: TestKit - Default-Language: Haskell2010 Default-Extensions: QuasiQuotes+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -511,14 +525,15 @@ Other-Modules: TestKit - Default-Language: Haskell2010 Default-Extensions: QuasiQuotes+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -554,15 +569,16 @@ Other-Modules: TestKit - Default-Language: Haskell2010 Extensions: OverloadedStrings Default-Extensions: QuasiQuotes+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs+ -Werror Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0
lib/version.txt view
@@ -1,1 +1,1 @@-0.2.0.4+0.3.0.0
regex-examples.cabal view
@@ -1,5 +1,5 @@ Name: regex-examples-Version: 0.2.0.4+Version: 0.3.0.0 Synopsis: Tutorial, tests and example programs for regex Description: Tutorial, tests and example programs for regex, a Regular Expression Toolkit for regex-base with@@ -63,7 +63,7 @@ Source-Repository this Type: git Location: https://github.com/iconnect/regex.git- Tag: 0.2.0.4+ Tag: 0.3.0.0 @@ -79,9 +79,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -107,9 +108,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -132,9 +134,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -156,9 +159,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -176,16 +180,17 @@ Main-Is: re-include.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , base >= 4 && < 5 , base-compat >= 0.6.0 , bytestring >= 0.10.2.0@@ -200,16 +205,17 @@ Main-Is: re-include.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , base >= 4 && < 5 , base-compat >= 0.6.0 , bytestring >= 0.10.2.0@@ -228,9 +234,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -256,9 +263,10 @@ GHC-Options: -Wall -fwarn-tabs+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -280,16 +288,17 @@ Main-Is: re-prep.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , base >= 4 && < 5 , base-compat >= 0.6.0 , bytestring >= 0.10.2.0@@ -306,16 +315,17 @@ Main-Is: re-prep.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , base >= 4 && < 5 , base-compat >= 0.6.0 , bytestring >= 0.10.2.0@@ -332,16 +342,17 @@ Main-Is: re-tests.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -368,16 +379,17 @@ Main-Is: re-tests.lhs + Other-Modules:+ TestKit+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs-- Other-Modules:- TestKit+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -407,14 +419,15 @@ Other-Modules: TestKit - Default-Language: Haskell2010 Default-Extensions: QuasiQuotes+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -449,14 +462,15 @@ Other-Modules: TestKit - Default-Language: Haskell2010 Default-Extensions: QuasiQuotes+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0@@ -492,15 +506,16 @@ Other-Modules: TestKit - Default-Language: Haskell2010 Extensions: OverloadedStrings Default-Extensions: QuasiQuotes+ Default-Language: Haskell2010 GHC-Options: -Wall -fwarn-tabs+ -Wwarn Build-depends:- regex == 0.2.0.4+ regex == 0.3.0.0 , array >= 0.4 , base >= 4 && < 5 , base-compat >= 0.6.0
src/Text/RE/PCRE/ByteString.hs view
@@ -8,11 +8,20 @@ #endif module Text.RE.PCRE.ByteString- ( (*=~)+ (+ -- * Tutorial+ -- $tutorial++ -- * The Match Operators+ (*=~) , (?=~) , (=~) , (=~~)+ -- * The Toolkit+ -- $toolkit , module Text.RE+ -- * The 'RE' Type+ -- $re , module Text.RE.PCRE.RE ) where @@ -30,13 +39,13 @@ -> Matches B.ByteString (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs --- | find first matches in text+-- | find first match in text (?=~) :: B.ByteString -> RE -> Match B.ByteString (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs --- | regex-base polymorphic match operator+-- | the regex-base polymorphic match operator (=~) :: ( RegexContext PCRE.Regex B.ByteString a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String )@@ -45,7 +54,7 @@ -> a (=~) bs rex = match (reRegex rex) bs --- | regex-base monadic, polymorphic match operator+-- | the regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext PCRE.Regex B.ByteString a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String@@ -59,3 +68,18 @@ matchOnce = flip (?=~) matchMany = flip (*=~) regexSource = reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>. These API+-- docs are mainly for reference.++-- $toolkit+--+-- Beyond the above match operators and the regular expression type+-- below, "Text.RE" contains the toolkit for replacing captures,+-- specifying options, etc.++-- $re+--+-- "Text.RE.PCRE.RE" contains the toolkit specific to the 'RE' type,+-- the type generated by the gegex compiler.
src/Text/RE/PCRE/ByteString/Lazy.hs view
@@ -8,11 +8,20 @@ #endif module Text.RE.PCRE.ByteString.Lazy- ( (*=~)+ (+ -- * Tutorial+ -- $tutorial++ -- * The Match Operators+ (*=~) , (?=~) , (=~) , (=~~)+ -- * The Toolkit+ -- $toolkit , module Text.RE+ -- * The 'RE' Type+ -- $re , module Text.RE.PCRE.RE ) where @@ -30,13 +39,13 @@ -> Matches LBS.ByteString (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs --- | find first matches in text+-- | find first match in text (?=~) :: LBS.ByteString -> RE -> Match LBS.ByteString (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs --- | regex-base polymorphic match operator+-- | the regex-base polymorphic match operator (=~) :: ( RegexContext PCRE.Regex LBS.ByteString a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String )@@ -45,7 +54,7 @@ -> a (=~) bs rex = match (reRegex rex) bs --- | regex-base monadic, polymorphic match operator+-- | the regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext PCRE.Regex LBS.ByteString a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String@@ -59,3 +68,18 @@ matchOnce = flip (?=~) matchMany = flip (*=~) regexSource = reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>. These API+-- docs are mainly for reference.++-- $toolkit+--+-- Beyond the above match operators and the regular expression type+-- below, "Text.RE" contains the toolkit for replacing captures,+-- specifying options, etc.++-- $re+--+-- "Text.RE.PCRE.RE" contains the toolkit specific to the 'RE' type,+-- the type generated by the gegex compiler.
src/Text/RE/PCRE/Sequence.hs view
@@ -8,11 +8,20 @@ #endif module Text.RE.PCRE.Sequence- ( (*=~)+ (+ -- * Tutorial+ -- $tutorial++ -- * The Match Operators+ (*=~) , (?=~) , (=~) , (=~~)+ -- * The Toolkit+ -- $toolkit , module Text.RE+ -- * The 'RE' Type+ -- $re , module Text.RE.PCRE.RE ) where @@ -30,13 +39,13 @@ -> Matches (S.Seq Char) (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs --- | find first matches in text+-- | find first match in text (?=~) :: (S.Seq Char) -> RE -> Match (S.Seq Char) (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs --- | regex-base polymorphic match operator+-- | the regex-base polymorphic match operator (=~) :: ( RegexContext PCRE.Regex (S.Seq Char) a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String )@@ -45,7 +54,7 @@ -> a (=~) bs rex = match (reRegex rex) bs --- | regex-base monadic, polymorphic match operator+-- | the regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext PCRE.Regex (S.Seq Char) a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String@@ -59,3 +68,18 @@ matchOnce = flip (?=~) matchMany = flip (*=~) regexSource = reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>. These API+-- docs are mainly for reference.++-- $toolkit+--+-- Beyond the above match operators and the regular expression type+-- below, "Text.RE" contains the toolkit for replacing captures,+-- specifying options, etc.++-- $re+--+-- "Text.RE.PCRE.RE" contains the toolkit specific to the 'RE' type,+-- the type generated by the gegex compiler.
src/Text/RE/PCRE/String.hs view
@@ -8,11 +8,20 @@ #endif module Text.RE.PCRE.String- ( (*=~)+ (+ -- * Tutorial+ -- $tutorial++ -- * The Match Operators+ (*=~) , (?=~) , (=~) , (=~~)+ -- * The Toolkit+ -- $toolkit , module Text.RE+ -- * The 'RE' Type+ -- $re , module Text.RE.PCRE.RE ) where @@ -30,13 +39,13 @@ -> Matches String (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs --- | find first matches in text+-- | find first match in text (?=~) :: String -> RE -> Match String (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs --- | regex-base polymorphic match operator+-- | the regex-base polymorphic match operator (=~) :: ( RegexContext PCRE.Regex String a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String )@@ -45,7 +54,7 @@ -> a (=~) bs rex = match (reRegex rex) bs --- | regex-base monadic, polymorphic match operator+-- | the regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext PCRE.Regex String a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String@@ -59,3 +68,18 @@ matchOnce = flip (?=~) matchMany = flip (*=~) regexSource = reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>. These API+-- docs are mainly for reference.++-- $toolkit+--+-- Beyond the above match operators and the regular expression type+-- below, "Text.RE" contains the toolkit for replacing captures,+-- specifying options, etc.++-- $re+--+-- "Text.RE.PCRE.RE" contains the toolkit specific to the 'RE' type,+-- the type generated by the gegex compiler.
src/Text/RE/TDFA/ByteString.hs view
@@ -8,11 +8,20 @@ #endif module Text.RE.TDFA.ByteString- ( (*=~)+ (+ -- * Tutorial+ -- $tutorial++ -- * The Match Operators+ (*=~) , (?=~) , (=~) , (=~~)+ -- * The Toolkit+ -- $toolkit , module Text.RE+ -- * The 'RE' Type+ -- $re , module Text.RE.TDFA.RE ) where @@ -30,13 +39,13 @@ -> Matches B.ByteString (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs --- | find first matches in text+-- | find first match in text (?=~) :: B.ByteString -> RE -> Match B.ByteString (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs --- | regex-base polymorphic match operator+-- | the regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex B.ByteString a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -45,7 +54,7 @@ -> a (=~) bs rex = match (reRegex rex) bs --- | regex-base monadic, polymorphic match operator+-- | the regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex B.ByteString a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String@@ -59,3 +68,18 @@ matchOnce = flip (?=~) matchMany = flip (*=~) regexSource = reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>. These API+-- docs are mainly for reference.++-- $toolkit+--+-- Beyond the above match operators and the regular expression type+-- below, "Text.RE" contains the toolkit for replacing captures,+-- specifying options, etc.++-- $re+--+-- "Text.RE.TDFA.RE" contains the toolkit specific to the 'RE' type,+-- the type generated by the gegex compiler.
src/Text/RE/TDFA/ByteString/Lazy.hs view
@@ -8,11 +8,20 @@ #endif module Text.RE.TDFA.ByteString.Lazy- ( (*=~)+ (+ -- * Tutorial+ -- $tutorial++ -- * The Match Operators+ (*=~) , (?=~) , (=~) , (=~~)+ -- * The Toolkit+ -- $toolkit , module Text.RE+ -- * The 'RE' Type+ -- $re , module Text.RE.TDFA.RE ) where @@ -30,13 +39,13 @@ -> Matches LBS.ByteString (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs --- | find first matches in text+-- | find first match in text (?=~) :: LBS.ByteString -> RE -> Match LBS.ByteString (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs --- | regex-base polymorphic match operator+-- | the regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex LBS.ByteString a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -45,7 +54,7 @@ -> a (=~) bs rex = match (reRegex rex) bs --- | regex-base monadic, polymorphic match operator+-- | the regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex LBS.ByteString a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String@@ -59,3 +68,18 @@ matchOnce = flip (?=~) matchMany = flip (*=~) regexSource = reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>. These API+-- docs are mainly for reference.++-- $toolkit+--+-- Beyond the above match operators and the regular expression type+-- below, "Text.RE" contains the toolkit for replacing captures,+-- specifying options, etc.++-- $re+--+-- "Text.RE.TDFA.RE" contains the toolkit specific to the 'RE' type,+-- the type generated by the gegex compiler.
src/Text/RE/TDFA/Sequence.hs view
@@ -8,11 +8,20 @@ #endif module Text.RE.TDFA.Sequence- ( (*=~)+ (+ -- * Tutorial+ -- $tutorial++ -- * The Match Operators+ (*=~) , (?=~) , (=~) , (=~~)+ -- * The Toolkit+ -- $toolkit , module Text.RE+ -- * The 'RE' Type+ -- $re , module Text.RE.TDFA.RE ) where @@ -30,13 +39,13 @@ -> Matches (S.Seq Char) (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs --- | find first matches in text+-- | find first match in text (?=~) :: (S.Seq Char) -> RE -> Match (S.Seq Char) (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs --- | regex-base polymorphic match operator+-- | the regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex (S.Seq Char) a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -45,7 +54,7 @@ -> a (=~) bs rex = match (reRegex rex) bs --- | regex-base monadic, polymorphic match operator+-- | the regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex (S.Seq Char) a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String@@ -59,3 +68,18 @@ matchOnce = flip (?=~) matchMany = flip (*=~) regexSource = reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>. These API+-- docs are mainly for reference.++-- $toolkit+--+-- Beyond the above match operators and the regular expression type+-- below, "Text.RE" contains the toolkit for replacing captures,+-- specifying options, etc.++-- $re+--+-- "Text.RE.TDFA.RE" contains the toolkit specific to the 'RE' type,+-- the type generated by the gegex compiler.
src/Text/RE/TDFA/String.hs view
@@ -8,11 +8,20 @@ #endif module Text.RE.TDFA.String- ( (*=~)+ (+ -- * Tutorial+ -- $tutorial++ -- * The Match Operators+ (*=~) , (?=~) , (=~) , (=~~)+ -- * The Toolkit+ -- $toolkit , module Text.RE+ -- * The 'RE' Type+ -- $re , module Text.RE.TDFA.RE ) where @@ -30,13 +39,13 @@ -> Matches String (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs --- | find first matches in text+-- | find first match in text (?=~) :: String -> RE -> Match String (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs --- | regex-base polymorphic match operator+-- | the regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex String a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -45,7 +54,7 @@ -> a (=~) bs rex = match (reRegex rex) bs --- | regex-base monadic, polymorphic match operator+-- | the regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex String a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String@@ -59,3 +68,18 @@ matchOnce = flip (?=~) matchMany = flip (*=~) regexSource = reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>. These API+-- docs are mainly for reference.++-- $toolkit+--+-- Beyond the above match operators and the regular expression type+-- below, "Text.RE" contains the toolkit for replacing captures,+-- specifying options, etc.++-- $re+--+-- "Text.RE.TDFA.RE" contains the toolkit specific to the 'RE' type,+-- the type generated by the gegex compiler.
src/Text/RE/TDFA/Text.hs view
@@ -8,11 +8,20 @@ #endif module Text.RE.TDFA.Text- ( (*=~)+ (+ -- * Tutorial+ -- $tutorial++ -- * The Match Operators+ (*=~) , (?=~) , (=~) , (=~~)+ -- * The Toolkit+ -- $toolkit , module Text.RE+ -- * The 'RE' Type+ -- $re , module Text.RE.TDFA.RE ) where @@ -30,13 +39,13 @@ -> Matches T.Text (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs --- | find first matches in text+-- | find first match in text (?=~) :: T.Text -> RE -> Match T.Text (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs --- | regex-base polymorphic match operator+-- | the regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex T.Text a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -45,7 +54,7 @@ -> a (=~) bs rex = match (reRegex rex) bs --- | regex-base monadic, polymorphic match operator+-- | the regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex T.Text a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String@@ -59,3 +68,18 @@ matchOnce = flip (?=~) matchMany = flip (*=~) regexSource = reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>. These API+-- docs are mainly for reference.++-- $toolkit+--+-- Beyond the above match operators and the regular expression type+-- below, "Text.RE" contains the toolkit for replacing captures,+-- specifying options, etc.++-- $re+--+-- "Text.RE.TDFA.RE" contains the toolkit specific to the 'RE' type,+-- the type generated by the gegex compiler.
src/Text/RE/TDFA/Text/Lazy.hs view
@@ -8,11 +8,20 @@ #endif module Text.RE.TDFA.Text.Lazy- ( (*=~)+ (+ -- * Tutorial+ -- $tutorial++ -- * The Match Operators+ (*=~) , (?=~) , (=~) , (=~~)+ -- * The Toolkit+ -- $toolkit , module Text.RE+ -- * The 'RE' Type+ -- $re , module Text.RE.TDFA.RE ) where @@ -30,13 +39,13 @@ -> Matches TL.Text (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs --- | find first matches in text+-- | find first match in text (?=~) :: TL.Text -> RE -> Match TL.Text (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs --- | regex-base polymorphic match operator+-- | the regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex TL.Text a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -45,7 +54,7 @@ -> a (=~) bs rex = match (reRegex rex) bs --- | regex-base monadic, polymorphic match operator+-- | the regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex TL.Text a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String@@ -59,3 +68,18 @@ matchOnce = flip (?=~) matchMany = flip (*=~) regexSource = reSource++-- $tutorial+-- We have a regex tutorial at <http://tutorial.regex.uk>. These API+-- docs are mainly for reference.++-- $toolkit+--+-- Beyond the above match operators and the regular expression type+-- below, "Text.RE" contains the toolkit for replacing captures,+-- specifying options, etc.++-- $re+--+-- "Text.RE.TDFA.RE" contains the toolkit specific to the 'RE' type,+-- the type generated by the gegex compiler.