diff options
Diffstat (limited to 'Logstat/Eval.hs')
-rw-r--r-- | Logstat/Eval.hs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Logstat/Eval.hs b/Logstat/Eval.hs index 603a5a6..6a92c60 100644 --- a/Logstat/Eval.hs +++ b/Logstat/Eval.hs @@ -5,14 +5,14 @@ import Control.Monad.Except import Control.Monad.State.Strict import Data.Fixed (mod') import Data.Foldable (foldl',toList) -import Data.Maybe (catMaybes,isJust) -import Text.Regex.PCRE.Light +import Data.Maybe (catMaybes) import qualified Data.ByteString as B import qualified Data.Heap as Heap import qualified Data.Map.Strict as Map import Logstat.Types import Logstat.Value +import Logstat.Regex except :: MonadError e m => Either e a -> m a @@ -43,7 +43,16 @@ evalExpr st expr = case expr of EMatch r e -> do v <- evalExpr st e - return $ bool $ isJust $ match r (asBS v) [] + return $ bool $ reMatch r (asBS v) + + EExtract e r -> do + v <- asBS <$> evalExpr st e + ma <- maybe (throwError (NoExtract v)) return $ match r v + return $ bs $ ma !! 1 + + EReplace e r n -> + -- TODO: Support subpattern substitution + bs . gsub r (const n) . asBS <$> evalExpr st e EOp op a' b' -> case op of @@ -113,7 +122,7 @@ step ev = get >>= \stmt -> case stmt of SRegex f r p -> do val <- asBS <$> getField ev f - ma <- maybe (throwError (NoMatch f val)) return $ match r val [] + ma <- maybe (throwError (NoMatch f val)) return $ match r val return $ foldl' ins ev $ zip ma p where ins s (_, Nothing) = s |