packages feed

regexpr 0.2.5 → 0.2.6

raw patch · 5 files changed

+52/−21 lines, 5 files

Files

Hidden/ParseRegexStr.hs view
@@ -14,10 +14,10 @@ 			     setMode, isModeI, isModeM, isModeX ) import Hidden.ParseLib     ( runParse, spot, mplus, mzero, token, tokens,                              list, greedyList, optional, endOfInput )-import Hidden.Tools	   ( isSymbol, isBit7On, bifurcate, cat2funcL,-                             modifySnd, skipRet, (>..>) )+import Hidden.Tools	   ( isSymbol, isBit7On, -- bifurcate, cat2funcL,+                             modifySnd, skipRet, (>..>), ignoreCase ) import Data.Char	   ( isAlphaNum, isAlpha, isDigit, isSpace,-                             toUpper, toLower )+                             {- toUpper, toLower -} ) import Data.Ix             ( inRange ) import Hidden.SrcRegActList( plusesList, oneCharList, backSlashesList,                              parensesList, charClassList, selfList )@@ -100,7 +100,8 @@ parseAlphaNum = do   { i <- isModeI;     spot isAlpha >>= return . Select .-      if i then flip elem . bifurcate (cat2funcL toUpper toLower)+      if i then ignoreCase . (==)+                           -- flip elem . bifurcate (cat2funcL toUpper toLower)            else (==) }   `mplus` ( spot isDigit >>= return . Select . (==) ) @@ -135,12 +136,23 @@  parseCharList :: RegexSrcParser (Char -> Bool) parseCharList = do-  cl <- greedyList (parseChar `mplus` parseCharArea `mplus` parseCharClass);-  return $ or . zipWith ($) cl . repeat-  where parseChar = (spot isAlphaNum `mplus` (token '\\' >> spot isSymbol))-                      >>= return . (==)-        parseCharArea = (spot isAlphaNum >>= skipRet (token '-')) >..>-	                 spot isAlphaNum >>= return . inRange+  modei <- isModeI+  cl1 <- parseOne `mplus`+           (foldr mplus mzero $ map ((>>= return . (==)) . token) "[]")+  cl2 <- greedyList $ parseOne `mplus`+           (foldr mplus mzero $ map ((>>= return . (==)) . token) "^")+  return $ (if modei then ignoreCase else id) $ or . zipWith ($) (cl1 : cl2)+                                                   . repeat+  where parseOne       = (parseChar >>= return . (==)) `mplus` parseCharArea+                                                       `mplus` parseCharClass+        parseChar      = ( spot isAlphaNum )+                         `mplus`+		         ( token '\\' >> spot isSymbol )+	                 `mplus`+                         ( foldr mplus mzero $ map ((>>= return ) . token)+		                             $ filter (/='-') selfList )+        parseCharArea  = (parseChar >>= skipRet (token '-')) >..> parseChar >>=+			   return . inRange 	parseCharClass = foldr mplus mzero $ 	                   map (\(s, p) -> tokens ("[:"++s++":]") >> return p) 			       charClassList
Hidden/SrcRegActList.hs view
@@ -13,7 +13,7 @@ ) where  import Hidden.RegexPRTypes( RegexAction(..), reverseRegexAction )-import Hidden.Tools( (&&&), isSymbol )+import Hidden.Tools( (&&&), (|||), isSymbol ) import Data.Char( isAlphaNum, isAlpha, isUpper, isLower,                   isDigit, isHexDigit, isSpace, isPrint, isControl ) @@ -29,7 +29,7 @@  ]  selfList :: [ Char ]-selfList = ", <>-!:#@\n"+selfList = ", <>-!:#@\n_\f\r\t="  oneCharList :: [ (Char, RegexAction) ] oneCharList = [@@ -44,8 +44,8 @@  backSlashesList :: [ (Char, RegexAction) ] backSlashesList = [-   ( 'w', Select isAlphaNum                                          )- , ( 'W', Select (not . isAlphaNum)                                  )+   ( 'w', Select $ isAlphaNum ||| (=='_')                            )+ , ( 'W', Select $ (not . isAlphaNum) &&& (/='_')                    )  , ( 's', Select (flip elem " \t\n\r\f")                             )  , ( 'S', Select (flip notElem " \t\n\r\f")                          )  , ( 'd', Select isDigit                                             )
Hidden/TestMain.hs view
@@ -164,11 +164,22 @@  , Just ( ("FGH-12345", ("abcDE", "67")), [] )                                         ~=?      matchRegexPR "[A-Z]{3}-\\d{5}" "abcDEFGH-1234567"--- , Just ( ("ABc", ("", " de")), [] )    ~=? matchRegexPR "(?i)[A-Z]+" "ABcde"--- , Just ( ("?", ("", "!abc")), [] )     ~=? matchRegexPR "[\\--z]*" "?!abc"--- , Just ( ("?!abc-A", ("", " b")), [] ) ~=? matchRegexPR "[!-z]*" "?!abc-A b"+ , Just ( ("ABc", ("", " de")), [] )    ~=? matchRegexPR "(?i)[A-Z]+" "ABc de"+ , Just ( ("?", ("", "!abc")), [] )     ~=? matchRegexPR "[\\--z]*" "?!abc"+ , Just ( ("?!abc-A", ("", " b")), [] ) ~=? matchRegexPR "[!-z]*" "?!abc-A b"  , Just ( ("!!:!", ("!", "!!")), [] )   ~=?      matchRegexPR "(?<=!)!{1,3}:!(?=!)" "!!!:!!!"  , Nothing                              ~=? matchRegexPR "(?>a*)ab" "aaab"  , Just ( ("\n\n", ("abc", "def")), [] )~=? matchRegexPR "\n\n" "abc\n\ndef"+ , Just ( ("aBd", ("", "e")), [] )      ~=? matchRegexPR "(?i)[^e-\\}]*" "aBde"+ , Just ( ("_ac", ("!", " kk")), [] )   ~=?+     matchRegexPR "[a-zA-Z0-9_]+" "!_ac kk"+ , Just ( ("_ac", ("!", " kk")), [] )   ~=? matchRegexPR "\\w+" "!_ac kk"+ , Just ( ("!", ("", "_ac kk")), [] )   ~=? matchRegexPR "\\W+" "!_ac kk"+ , Just ( ("ab", (" \t\f", "\n\r ")), [] )+                                        ~=?+     matchRegexPR "[^ \f\n\r\t]+" " \t\fab\n\r "+ , Just ( ("a^[b]", ("c", "kk")), [] )  ~=? matchRegexPR "[[\\]^ab]+" "ca^[b]kk"+ , Just ( ("flag =\t1", ("", "")), [] ) ~=?+     matchRegexPR "flag[ \t]*=[ \t]*\\w" "flag =\t1"  ]
Hidden/Tools.hs view
@@ -17,13 +17,14 @@ , (|||) , (&&&) , isBit7On-, bifurcate-, cat2funcL+-- , bifurcate+-- , cat2funcL , skipRet , (>..>)+, ignoreCase ) where -import Data.Char          ( isAlphaNum, isSpace, isPrint, ord )+import Data.Char          ( isAlphaNum, isSpace, isPrint, ord, toUpper, toLower ) import Data.Bits          ( (.&.), shiftL ) import Control.Monad      ( MonadPlus, guard ) @@ -59,14 +60,19 @@ isBit7On :: Char -> Bool isBit7On c = ord c .&. (shiftL 1 7) /= 0 +{- bifurcate :: (a -> a -> b) -> a -> b bifurcate f x = f x x  cat2funcL :: (a -> c) -> (b -> c) -> a -> b -> [c] cat2funcL f g x y =  [f x, g y ]+-}  skipRet :: Monad m => m b -> a -> m a skipRet p x = p >> return x  (>..>) :: Monad m => m a -> m b -> m (a, b) m1 >..> m2 = do { x <- m1; y <- m2; return (x, y) }++ignoreCase :: (Char -> Bool) -> Char -> Bool+ignoreCase p c = p (toLower c) || p (toUpper c)
regexpr.cabal view
@@ -1,9 +1,11 @@ Name:		regexpr-Version:	0.2.5+Version:	0.2.6 License:	GPL License-File:	LICENSE Author:		Yoshikuni Jujo <PAF01143@nifty.ne.jp> Maintainer:	PAF01143@nifty.ne.jp+Stability:	experimental+Homepage:	http://homepage3.nifty.com/salamander/regexpr Synopsis:	regular expression like Perl/Ruby in Haskell Description:   Regular expression library like Perl/Ruby's regular expressions.