packages feed

regexpr 0.4 → 0.5

raw patch · 4 files changed

+57/−21 lines, 4 files

Files

Hidden/RegexPRCore.hs view
@@ -5,20 +5,21 @@  module Hidden.RegexPRCore (   matchRegexPRVerbose+, multiMatchRegexPRVerbose ) where -import Hidden.RegexPRTypes        ( RegexParser, MatchList, runRegexParser )+import Hidden.RegexPRTypes  ( RegexParser, MatchList, runRegexParser ) import Text.ParserCombinators.MTLParse-                                 ( spot, spotBack, still, noBacktrack, parseNot,-                                    build, tokens, tokensBack,-                                    repeatParse, greedyRepeatParse,-                                    beginningOfInput, endOfInput,-                                    MonadPlus(..), (>++>) )-import Hidden.ParseRegexStr       ( RegexAction(..), parseRegexStr )-import Control.Monad.State ( StateT, runStateT, gets, modify, lift, liftM )-import Control.Monad.Reader( ask )-import Hidden.Tools               ( guardEqual )-import Control.Monad       ( when )+                            ( spot, spotBack, still, noBacktrack, parseNot,+                              build, tokens, tokensBack,+                              repeatParse, greedyRepeatParse,+                              beginningOfInput, endOfInput,+                              MonadPlus(..), (>++>) )+import Hidden.ParseRegexStr ( RegexAction(..), parseRegexStr )+import Control.Monad.State  ( StateT, runStateT, gets, modify, lift, liftM )+import Control.Monad.Reader ( ask )+import Hidden.Tools         ( guardEqual )+import Control.Monad        ( when )  matchRegexPRVerbose ::   String -> (String, String)@@ -27,6 +28,13 @@   = case (runRegexParserTrials . mkRegexParserTrials . parseRegexStr) reg str of          []                       -> Nothing          (((ret, pre), ml), sp):_ -> Just ( (reverse pre, ret, sp), ml )++multiMatchRegexPRVerbose ::+  String -> (String, String)+         -> [ ( (String, String, (String, String)), MatchList ) ]+multiMatchRegexPRVerbose reg str+  = map (\(((ret, pre), ml), sp) -> ((reverse pre, ret, sp), ml)) $+        (runRegexParserTrials . mkRegexParserTrials . parseRegexStr) reg str  runRegexParserTrials ::   StateT String RegexParser a ->
Hidden/TestMain.hs view
@@ -6,7 +6,7 @@ module Hidden.TestMain where  import Test.HUnit-import Text.RegexPR ( matchRegexPR, gsubRegexPR, subRegexPR )+import Text.RegexPR ( matchRegexPR, multiMatchRegexPR, gsubRegexPR, subRegexPR )  main :: IO Counts main = runTestTT $ test suite@@ -209,4 +209,10 @@  , Just ( ("", ("abc", "")), [] )       ~=? matchRegexPR "(?<=abc)" "abc"  , Just ( ("{}", ("", "")), []  )       ~=? matchRegexPR "{}" "{}"  , Just ( ("3{}4", ("", "")), [] )      ~=? matchRegexPR "3{}4" "3{}4"+ , [(("o", ("Hell", ", world, and good bye!")),[]),+    (("o", ("Hello, w", "rld, and good bye!")),[]),+    (("oo", ("Hello, world, and g", "d bye!")),[]),+    (("o", ("Hello, world, and g", "od bye!")),[]),+    (("o", ("Hello, world, and go", "d bye!")),[])]+                                        ~=? multiMatchRegexPR "o+" "Hello, world, and good bye!"  ]
Text/RegexPR.hs view
@@ -4,23 +4,39 @@ --  module Text.RegexPR (-  matchRegexPR+  getbrsRegexPR+, matchRegexPR+, multiMatchRegexPR , gmatchRegexPR		-- EXPERIMENTAL , subRegexPR+, subRegexPRBy , gsubRegexPR , gsubRegexPRBy , splitRegexPR ) where -import Hidden.RegexPRCore ( matchRegexPRVerbose )-import Hidden.RegexPRTypes( RegexResult, MatchList )-import Data.Char   ( isDigit )+import Hidden.RegexPRCore  ( matchRegexPRVerbose, multiMatchRegexPRVerbose )+import Hidden.RegexPRTypes ( RegexResult, MatchList )+import Data.Char           ( isDigit )+import Data.List           ( sort, nubBy )+import Data.Function       ( on ) +getbrsRegexPR :: String -> String -> [ String ]+getbrsRegexPR reg str+  = case matchRegexPR reg str of+         Nothing                    -> []+	 Just ( (ret, (_, _)), ml ) -> ret : map snd (sort $ nubBy (on (==) fst) ml)+ matchRegexPR :: String -> String -> Maybe ( RegexResult, MatchList ) matchRegexPR reg str   = fmap ( \( (pre, ret, (_, rest)), ml ) -> ( (ret, (pre, rest)), ml ) ) $          matchRegexPRVerbose reg ("", str) +multiMatchRegexPR :: String -> String -> [ ( RegexResult, MatchList ) ]+multiMatchRegexPR reg str+  = fmap ( \( (pre, ret, (_, rest)), ml ) -> ( (ret, (pre, rest)), ml ) ) $+         multiMatchRegexPRVerbose reg ("", str)+ gmatchRegexPR :: String -> String -> [ ( RegexResult, MatchList ) ] gmatchRegexPR reg str = gmatchRegexPRGen Nothing reg ("", str) @@ -38,9 +54,12 @@       Nothing -> []  subRegexPR :: String -> String -> String -> String-subRegexPR reg sub src+subRegexPR reg sub src = subRegexPRBy reg (const sub) src++subRegexPRBy :: String -> (String -> String) -> String -> String+subRegexPRBy reg subf src   = case matchRegexPRVerbose reg ("",src) of-         Just al@((pre, _, sp), _) -> pre ++ subBackRef al sub ++ snd sp+         Just al@((pre, m, sp), _) -> pre ++ subBackRef al (subf m) ++ snd sp          Nothing                   -> src  gsubRegexPR :: String -> String -> String -> String
regexpr.cabal view
@@ -1,5 +1,5 @@ Name:		regexpr-Version:	0.4+Version:	0.5 License:	LGPL License-File:	LICENSE Author:		Yoshikuni Jujo <PAF01143@nifty.ne.jp>@@ -12,9 +12,12 @@   This package has a module RegexPR.   And RegexPR export functions matchRegexPR and gsubRegexPR.   .-  > matchRegexPR :: String -> Maybe ((String, (String, String)), [(Int, String)])-  > gmatchRegexPR :: String -> [((String, (String, String)), [(Int, String)])]+  > getbrsRegexPR :: String -> String -> [ String ]+  > matchRegexPR :: String -> String -> Maybe ((String, (String, String)), [(Int, String)])+  > gmatchRegexPR :: String -> String -> [((String, (String, String)), [(Int, String)])]+  > multiMatchRegexPR :: String -> String -> [ ((String, (String, String)), [(Int, String)]) ]   > subRegexPR :: String -> String -> String -> String+  > subRegexPRBy :: String -> (String -> String) -> String -> String   > gsubRegexPR :: String -> String -> String -> String   > gsubRegexPRBy :: String -> (String -> String) -> String -> String   > splitRegexPR :: String -> String -> [String]