packages feed

regex-genex 0.3.2 → 0.5.0

raw patch · 4 files changed

+33/−28 lines, 4 filesdep ~sbv

Dependency ranges changed: sbv

Files

regex-genex.cabal view
@@ -1,5 +1,5 @@ Name            : regex-genex-Version         : 0.3.2+Version         : 0.5.0 license         : OtherLicense license-file    : LICENSE cabal-version   : >= 1.6@@ -12,7 +12,7 @@ synopsis        : From a regex, generate all possible strings it can match description     : From a regex, generate all possible strings it can match author          : Audrey Tang <audreyt@audreyt.org>-Tested-With:    GHC==7.0.2+Tested-With:    GHC==7.0.2 GHC==7.4.1  library     hs-source-dirs:     . src@@ -20,14 +20,14 @@     other-modules:    Regex.Genex.Pure     extensions      : ImplicitParams, NamedFieldPuns, ParallelListComp, PatternGuards, RecordWildCards     build-depends:-        base >= 3 && < 5, mtl, containers, sbv >= 0.9.22, regex-tdfa, stream-monad, text, logict+        base >= 3 && < 5, mtl, containers, sbv == 2.3, regex-tdfa, stream-monad, text, logict  executable genex     main-is:            Main.hs     hs-source-dirs:     . src     extensions      : ImplicitParams, NamedFieldPuns, ParallelListComp, PatternGuards, RecordWildCards     build-depends:-        base >= 3 && < 5, mtl, containers, sbv, regex-tdfa+        base >= 3 && < 5, mtl, containers, sbv == 2.3, regex-tdfa  source-repository head   type:     git
src/Regex/Genex.hs view
@@ -349,7 +349,7 @@ displayString :: [SatResult] -> Hits -> (Hits -> IO ()) -> IO () displayString [] a next = next a displayString (r:rs) a next = do-    let Right (chars, rank) = getModel r+    let Right (_, (chars, rank)) = getModel r     putStr $ show (length (chars :: [Word8])) ++ "."     let n = show (rank :: Word64)     putStr (replicate (8 - length n) '0')@@ -385,7 +385,7 @@ getStringWith :: (Model -> a) -> [SatResult] -> Hits -> (Hits -> IO [a]) -> IO [a] getStringWith _ [] a next = next a getStringWith f (r:rs) a next = do-    let Right (chars, rank) = getModel r+    let Right (_, (chars, rank)) = getModel r     rest <- if (a+1 >= maxHits) then return [] else         unsafeInterleaveIO $ getStringWith f rs (a+1) next     return (f (Model chars rank):rest)
src/Regex/Genex/Normalize.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE ImplicitParams, NamedFieldPuns #-}+{-# LANGUAGE ImplicitParams, NamedFieldPuns, PatternGuards #-} module Regex.Genex.Normalize (normalize) where import Data.Set (toList, Set) import Text.Regex.TDFA.Pattern@@ -14,6 +14,7 @@ normalize :: BackReferences -> Pattern -> Pattern normalize refs p = black $ let ?refs = refs in simplify p +nullable :: Pattern -> Bool nullable pat = case pat of     PGroup _ p -> nullable p     PQuest{} -> True@@ -25,6 +26,7 @@     PEmpty -> True     _ -> False +white :: Pattern -> Pattern white pat = case pat of     PQuest p -> white p     PStar _ p -> white p@@ -38,6 +40,7 @@         else pat     _ -> pat +black :: Pattern -> Pattern black pat = case pat of     POr ps -> POr (map black ps)     PConcat ps -> PConcat (map black ps)@@ -52,8 +55,8 @@         else PQuest $ black p     _ -> pat -parse :: String -> Pattern-parse r = case parseRegex r of+_parse :: String -> Pattern+_parse r = case parseRegex r of     Right (pattern, _) -> pattern     Left x -> error $ show x 
src/Regex/Genex/Pure.hs view
@@ -1,12 +1,12 @@ {-# LANGUAGE RecordWildCards, NamedFieldPuns #-} module Regex.Genex.Pure (genexPure) where-import Control.Monad.Logic.Class (MonadLogic(..)) import qualified Data.Text as T import qualified Data.IntSet as IntSet import qualified Data.Set as Set import Data.List (intersect, (\\)) import Control.Monad import Control.Monad.Stream+import qualified Control.Monad.Stream as Stream import Regex.Genex.Normalize (normalize) import Debug.Trace import Text.Regex.TDFA.Pattern@@ -20,10 +20,10 @@     Left x -> error $ show x  genexPure :: [String] -> [String]-genexPure = map T.unpack . foldl1 intersect . map (toList . run . normalize IntSet.empty . parse)+genexPure = map T.unpack . foldl1 intersect . map (Stream.toList . run . normalize IntSet.empty . parse)  maxRepeat :: Int-maxRepeat = 3+maxRepeat = 10  each = foldl1 (<|>) . map return @@ -32,6 +32,7 @@     PEmpty -> pure T.empty     PChar{..} -> isChar getPatternChar     PAny {getPatternSet = PatternSet (Just cset) _ _ _} -> each $ map T.singleton $ Set.toList cset+    PAnyNot {getPatternSet = PatternSet (Just cset) _ _ _} -> chars $ notChars $ concatMap expandEscape $ Set.toList cset     PQuest p -> pure T.empty <|> run p     PPlus p -> run $ PBound 1 Nothing p     PStar _ p -> run $ PBound 0 Nothing p@@ -40,23 +41,24 @@         fmap T.concat . sequence $ replicate n (run p)      PConcat ps -> fmap T.concat . suspended . sequence $ map run ps     POr xs -> foldl1 mplus $ map run xs-    PDot{} -> notChars []-    PEscape {..} -> case getPatternChar of-        'n' -> isChar '\n'-        't' -> isChar '\t'-        'r' -> isChar '\r'-        'f' -> isChar '\f'-        'a' -> isChar '\a'-        'e' -> isChar '\ESC'-        'd' -> chars $ ['0'..'9']-        'w' -> chars $ ['0'..'9'] ++ '_' : ['a'..'z'] ++ ['A'..'Z']-        's' -> chars "\9\10\12\13\32"-        'W' -> notChars $ ['0'..'9']-        'S' -> notChars $ ['0'..'9'] ++ '_' : ['a'..'z'] ++ ['A'..'Z']-        'D' -> notChars "\9\10\12\13\32"-        ch  -> isChar ch+    PDot{} -> chars $ notChars []+    PEscape {..} -> chars $ expandEscape getPatternChar     _      -> error $ show p     where     isChar = return . T.singleton     chars = each . map T.singleton-    notChars = chars . ([' '..'~'] \\)+    notChars = ([' '..'~'] \\)+    expandEscape ch = case ch of+        'n' -> "\n"+        't' -> "\t"+        'r' -> "\r"+        'f' -> "\f"+        'a' -> "\a"+        'e' -> "\ESC"+        'd' -> ['0'..'9']+        'w' -> ['0'..'9'] ++ '_' : ['a'..'z'] ++ ['A'..'Z']+        's' -> "\9\32"+        'D' -> notChars $ ['0'..'9']+        'W' -> notChars $ ['0'..'9'] ++ '_' : ['a'..'z'] ++ ['A'..'Z']+        'S' -> notChars "\9\32"+        ch  -> [ch]