[Pleac-commits] CVS: pleac/pleac pleac_haskell.data,1.68,1.69
Status: Alpha
Brought to you by:
ggc
From: Pixel <pi...@us...> - 2008-11-04 20:37:31
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9477 Modified Files: pleac_haskell.data Log Message: 6.10, 6.11 Index: pleac_haskell.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_haskell.data,v retrieving revision 1.68 retrieving revision 1.69 diff -u -r1.68 -r1.69 --- pleac_haskell.data 4 Nov 2008 09:58:43 -0000 1.68 +++ pleac_haskell.data 4 Nov 2008 20:37:23 -0000 1.69 @@ -2119,6 +2119,45 @@ pat = glob2pat "*File.*" -- ".*File\\..*" +-- @@PLEAC@@_6.10 +import Data.List +import Data.Maybe +import Text.Regex + +popstates = ["CO","ON","MI","WI","MN"] + +is_state = isJust . matchRegex re + where re = mkRegex $ "\\<(" ++ intercalate "|" popstates ++ ")\\>" + +l = filter is_state [ "xxx", "xx CO xx", "WI", "WIxx" ] +-- ["xx CO xx","WI"] + +-- this is less efficient: +is_state' line = any (\re -> isJust $ matchRegex re line) (map to_regexp popstates) + where to_regexp c = mkRegex $ "\\<" ++ c ++ "\\>" + +-- @@PLEAC@@_6.11 +import Data.Maybe +import Data.List +import Text.Regex.Base +import Text.Regex.Posix + +-- one can not catch invalid patterns using Text.Regex + +-- recent versions of Text.Regex.Base have makeRegexM: +is_valid_pattern :: String -> Bool +is_valid_pattern re = isJust (makeRegexM re :: Maybe Regex) +-- nb: the type Regex must be specified since matchRegexM uses abstract +-- classes and haskell can't guess which instance to use + +-- or can use compile from Text.Regex.Posix.String: +t = let regexp = "(" in + compile defaultCompOpt defaultExecOpt regexp >>= + (\re -> case re of + Left (_, err) -> error ("bad regexp \"" ++ regexp ++ "\": " ++ err) + Right re -> return re) +-- *** Exception: bad regexp "(": Unmatched ( or \( + -- @@PLEAC@@_APPENDIX import List |