packages feed

matchers 0.6.0.0 → 0.8.0.0

raw patch · 2 files changed

+13/−84 lines, 2 filesdep −explicit-exceptiondep −regex-basedep −regex-tdfaPVP ok

version bump matches the API change (PVP)

Dependencies removed: explicit-exception, regex-base, regex-tdfa

API changes (from Hackage documentation)

- Text.Matchers: instance Eq a => Eq (StrErr a)
- Text.Matchers: instance Monad StrErr
- Text.Matchers: instance Show a => Show (StrErr a)
- Text.Matchers: tdfa :: CaseSensitive -> Text -> Exceptional Text Matcher
- Text.Matchers: pcre :: CaseSensitive -> Text -> Exceptional Text Matcher
+ Text.Matchers: pcre :: CaseSensitive -> Text -> Either Text Matcher

Files

Text/Matchers.hs view
@@ -1,7 +1,6 @@ module Text.Matchers   ( Matcher(..)   , CaseSensitive(..)-  , tdfa   , pcre   , within   , exact@@ -13,15 +12,11 @@  import Control.Applicative ((<$>), (<*>), (<*), (<$), optional, (<|>)) import Control.Monad (replicateM, mzero)-import Control.Monad.Exception.Synchronous-  ( Exceptional (Exception, Success)) import qualified Data.ByteString as BS import Data.Fixed (Pico)-import Data.Maybe (fromMaybe)+import Data.Maybe (fromMaybe, isJust) import Data.Text (Text, pack, unpack, toCaseFold, isInfixOf) import Data.Text.Encoding (encodeUtf8)-import qualified Text.Regex.TDFA as TDFA-import qualified Text.Regex.Base.RegexLike as RL import qualified Text.Regex.PCRE.Light as PCRE import Text.Parsec (many, satisfy) import qualified Text.Parsec as P@@ -43,29 +38,6 @@     -- ^ Function to carry out the match     } --- | Uses the regular expression matcher from the regex-tdfa--- package. This is a POSIX extended regular expression. It should--- work correctly with Unicode.-tdfa-  :: CaseSensitive--  -> Text-  -- ^ The pattern--  -> Exceptional Text Matcher-  -- ^ The Matcher if the pattern is good; if the pattern is bad,-  -- returns an error message. The error message has a trailing-  -- newline.--tdfa c t = case tdfaPrim c (unpack t) of-  Exception e -> Exception $ pack e-  Success f ->-    let sDesc = pack "POSIX-like regular expression (TDFA)"-        mrDesc = pack $ "matches the POSIX regular expression \""-          ++ unpack t ++ "\"" ++ descSensitive c-        mr = f . unpack-    in return $ Matcher sDesc mrDesc mr- descSensitive :: CaseSensitive -> String descSensitive c = case c of   Sensitive -> " (case sensitive)"@@ -80,13 +52,13 @@   -> Text   -- ^ Pattern -  -> Exceptional Text Matcher+  -> Either Text Matcher   -- ^ The Matcher if the pattern is good; if the pattern is bad,   -- returns an error message.  pcre c t = case pcrePrim c (encodeUtf8 t) of-  Exception e -> Exception $ pack e-  Success f ->+  Left e -> Left $ pack e+  Right f ->     let sDesc = pack "Perl-compatible regular expression"         mrDesc = pack $ "matches the PCRE pattern \""           ++ unpack t ++ "\"" ++ descSensitive c@@ -156,59 +128,19 @@           in return $ subjDT `cmp` t  --------------------------------------------------------------- StrErr monad----------------------------------------------------------------- | This monad exists because using the mtl Monad instance of (Either--- String) causes problems due to orphan instances.------ See http://www.haskell.org/pipermail/haskell-cafe/2011-December/098079.html--data StrErr a = Good a-              | Bad String-              deriving (Show, Eq)--instance Monad StrErr where-  return = Good-  (Good a) >>= f = f a-  (Bad s) >>= _ = Bad s-  fail s = Bad s----------------------------------------------------------------- TDFA primitives---------------------------------------------------------------tdfaPrim-  :: CaseSensitive -> String -> Exceptional String (String -> Bool)-tdfaPrim c regexStr = case RL.makeRegexOptsM comp exec regexStr of-  (Bad s) -> Exception s-  (Good rx) -> return (RL.matchTest rx)-  where-    comp = RL.defaultCompOpt { TDFA.caseSensitive = case c of-                                  Sensitive -> True-                                  Insensitive -> False-                             , TDFA.newSyntax = True-                             , TDFA.lastStarGreedy = True }-    exec = RL.defaultExecOpt { TDFA.captureGroups = False }-------------------------------------------------------------- -- PCRE primitives ------------------------------------------------------------  pcrePrim :: CaseSensitive         -> BS.ByteString-        -> Exceptional String (BS.ByteString -> Bool)-pcrePrim c bs = let-  u8 = [PCRE.utf8]-  opts = case c of-    Sensitive -> u8-    Insensitive -> PCRE.caseless:u8 in-  case PCRE.compileM bs opts of-    (Left err) -> Exception err-    (Right rx) -> Success $ \s ->-      case PCRE.match rx s [] of-        (Just _) -> True-        Nothing -> False+        -> Either String (BS.ByteString -> Bool)+pcrePrim c bs =+  let u8 = [PCRE.utf8]+      opts = case c of+        Sensitive -> u8+        Insensitive -> PCRE.caseless:u8+      doMatch rx s = isJust $ PCRE.match rx s []+  in fmap doMatch $ PCRE.compileM bs opts  ------------------------------------------------------------ -- Date parsers
matchers.cabal view
@@ -1,5 +1,5 @@ Name: matchers-Version: 0.6.0.0+Version: 0.8.0.0 Cabal-version: >=1.8 Build-Type: Simple License: BSD3@@ -23,11 +23,8 @@     Build-depends:           base ==4.*         , bytestring ==0.10.*-        , explicit-exception ==0.1.*         , parsec >= 3.1.2 && < 3.2         , pcre-light ==0.4.*-        , regex-base ==0.93.*-        , regex-tdfa ==1.1.*         , text ==0.11.*         , time ==1.4.*