cgrep 6.6.14 → 6.6.15
raw patch · 11 files changed
+38/−43 lines, 11 files
Files
- README.md +2/−2
- cgrep.cabal +1/−1
- src/CGrep/Common.hs +11/−13
- src/CGrep/Output.hs +2/−1
- src/CGrep/Strategy/BoyerMoore.hs +10/−8
- src/CGrep/Strategy/Cpp/Semantic.hs +3/−7
- src/CGrep/Strategy/Cpp/Tokenizer.hs +3/−2
- src/CGrep/Strategy/Generic/Semantic.hs +3/−6
- src/CmdOptions.hs +1/−1
- src/Main.hs +1/−1
- src/Options.hs +1/−1
README.md view
@@ -7,7 +7,7 @@ Usage ----- -Cgrep 6.6.14. Usage: cgrep [OPTION] [PATTERN] files...+Cgrep 6.6.15. Usage: cgrep [OPTION] [PATTERN] files... cgrep [OPTIONS] [ITEM] @@ -96,7 +96,7 @@ Miscellaneous: -d --debug=INT Debug level: 1, 2 or 3- -n --no-quick Disable quick-search mode+ --no-shallow Disable shallow-search -? --help Display help message -V --version Print version information --numeric-version Print just the version number
cgrep.cabal view
@@ -1,6 +1,6 @@ Name: cgrep Description: Cgrep: a context-aware grep for source codes-Version: 6.6.14+Version: 6.6.15 Synopsis: Command line tool Homepage: http://awgn.github.io/cgrep/ License: GPL-2
src/CGrep/Common.hs view
@@ -19,8 +19,8 @@ module CGrep.Common (Text8, getTargetName, getTargetContents,- quickSearch,- runQuickSearch,+ shallowSearch,+ runSearch, expandMultiline, ignoreCase, trim, trim8) where@@ -56,21 +56,19 @@ getTargetContents xs = C.readFile xs -quickSearch :: Options -> [Text8] -> Text8 -> Maybe Bool-quickSearch opt ps text- | no_quick opt = Nothing- | otherwise = Just $ all findToken ps || null ps- where findToken tok = notNull $ tok `SC.nonOverlappingIndices` text+shallowSearch :: [Text8] -> Text8 -> [[Int]]+shallowSearch ps text = ps >>= (\p -> [p `SC.nonOverlappingIndices` text]) -runQuickSearch :: FilePath- -> Maybe Bool -- quicksearch+runSearch :: Options+ -> FilePath+ -> Bool -> OptionT IO [Output] -> OptionT IO [Output]-runQuickSearch filename quick doSearch =- if maybe False not quick- then mkOutput filename C.empty C.empty []- else doSearch+runSearch opt filename shallowTest doSearch =+ if shallowTest || no_shallow opt+ then doSearch+ else mkOutput filename C.empty C.empty [] expandMultiline :: Options -> Text8 -> Text8
src/CGrep/Output.hs view
@@ -48,6 +48,7 @@ import CGrep.Token import Options+import Util import Config import Reader import Safe@@ -290,5 +291,5 @@ hilightIndicies :: [Token] -> [(Int, Int)]-hilightIndicies = foldr (\t a -> let b = fst t in (b, b + length (snd t) - 1) : a) [] . filter (not . null . snd)+hilightIndicies = foldr (\t a -> let b = fst t in (b, b + length (snd t) - 1) : a) [] . filter (notNull . snd)
src/CGrep/Strategy/BoyerMoore.hs view
@@ -16,15 +16,14 @@ -- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -- +{-# LANGUAGE TupleSections #-} module CGrep.Strategy.BoyerMoore (search) where import qualified Data.ByteString.Char8 as C-import qualified Data.ByteString.Search as SC import Control.Monad.Trans.Reader import Control.Monad.IO.Class-import Control.Arrow as A import Data.List import CGrep.Common@@ -38,6 +37,7 @@ import Reader import Options import Debug+import Util search :: FilePath -> [Text8] -> OptionT IO [Output]@@ -50,18 +50,20 @@ -- transform text - let [text''', _ , text', _] = scanr ($) text [ expandMultiline opt- , contextFilter (getFileLang opt filename) (mkContextFilter opt)- , ignoreCase opt- ]+ let [text''', _ , _ , _] = scanr ($) text [ expandMultiline opt+ , contextFilter (getFileLang opt filename) (mkContextFilter opt)+ , ignoreCase opt+ ] putStrLevel1 $ "strategy : running Boyer-Moore search on " ++ filename ++ "..." - runQuickSearch filename (quickSearch opt patterns text') $ do+ let shallow = shallowSearch patterns text''' + runSearch opt filename (all notNull shallow) $ do+ -- search for matching tokens - let tokens = map (A.second C.unpack) $ patterns >>= (\p -> map (\i -> (i,p)) (p `SC.nonOverlappingIndices` text'''))+ let tokens = concatMap (\(p, xs) -> let p' = C.unpack p in map (,p') xs ) $ zip patterns shallow -- filter exact/partial matching tokens
src/CGrep/Strategy/Cpp/Semantic.hs view
@@ -23,7 +23,6 @@ import Control.Monad.Trans.Reader import Control.Monad.IO.Class-import Control.Applicative (liftA2) import Data.List import Data.Function import Data.Maybe@@ -59,9 +58,6 @@ patterns'' = map (map mkWildCardFromToken) patterns' -- [ [w1,w2,..], [w1,w2,..] ] patterns''' = map (combineMultiCard . map (:[])) patterns'' -- [ [m1,m2,..], [m1,m2,..] ] == [ [ [w1], [w2],..], [[w1],[w2],..]] -- -- quickSearch- identif = mapMaybe (\x -> case x of TokenCard (Cpp.TokenChar xs _) -> Just (rmQuote $ trim xs) TokenCard (Cpp.TokenString xs _) -> Just (rmQuote $ trim xs)@@ -79,10 +75,10 @@ let text'' = contextFilter (getFileLang opt filename) filt text' idpack = map C.pack identif- quick1 = quickSearch opt idpack text'- quick2 = quickSearch opt idpack text''+ quick1 = all notNull $ shallowSearch idpack text'+ quick2 = all notNull $ shallowSearch idpack text'' - runQuickSearch filename (liftA2 (&&) quick1 quick2) $ do+ runSearch opt filename (quick1 && quick2) $ do let [text''', _ , _] = scanr ($) text' [ expandMultiline opt , contextFilter (getFileLang opt filename) filt
src/CGrep/Strategy/Cpp/Tokenizer.hs view
@@ -35,6 +35,7 @@ import Reader import Options import Debug+import Util search :: FilePath -> [Text8] -> OptionT IO [Output]@@ -57,9 +58,9 @@ putStrLevel1 $ "strategy : running C/C++ token search on " ++ filename ++ "..." - --quickSearch ...+ let quick = all notNull $ shallowSearch ps text' - runQuickSearch filename (quickSearch opt ps text') $ do+ runSearch opt filename quick $ do -- parse source code, get the Cpp.Token list...
src/CGrep/Strategy/Generic/Semantic.hs view
@@ -29,7 +29,6 @@ import CGrep.Parser.Token import CGrep.Parser.WildCard -import Control.Applicative (liftA2) import Control.Monad.Trans.Reader import Control.Monad.IO.Class @@ -61,8 +60,6 @@ patterns' = map (map mkWildCardFromToken) patterns -- [ [w1,w2,..], [w1,w2,..] ] patterns'' = map (combineMultiCard . map (:[])) patterns' -- [ [m1,m2,..], [m1,m2,..] ] == [[[w1], [w2],..], [[w1],[w2],..]] - -- quickSearch ...- identif = mapMaybe (\x -> case x of TokenCard (Generic.TokenLiteral xs _) -> Just (rmQuote $ trim xs) TokenCard (Generic.TokenAlpha "OR" _) -> Nothing@@ -79,10 +76,10 @@ let text'' = contextFilter (getFileLang opt filename) filt text' idpack = map C.pack identif- quick1 = quickSearch opt idpack text'- quick2 = quickSearch opt idpack text''+ quick1 = all notNull $ shallowSearch idpack text'+ quick2 = all notNull $ shallowSearch idpack text'' - runQuickSearch filename (liftA2 (&&) quick1 quick2) $ do+ runSearch opt filename (quick1 && quick2) $ do -- expand multi-line
src/CmdOptions.hs view
@@ -77,7 +77,7 @@ , chunk = 16 &= help "Specify the length of chunks" , asynch = False &= help "Process chunks asynchronously" , debug = 0 &= groupname "\nMiscellaneous" &= help "Debug level: 1, 2 or 3"- , no_quick = False &= help "Disable quick-search mode"+ , no_shallow = False &= help "Disable shallow-search" &= explicit &= name "no-shallow" , others = [] &= args } &= summary ("Cgrep " ++ showVersion version ++ ". Usage: cgrep [OPTION] [PATTERN] files...") &= program "cgrep"
src/Main.hs view
@@ -216,7 +216,7 @@ -- read command-line options opts <- (if isTermOut- then \o -> o { color = (color o || configAutoColor conf) }+ then \o -> o { color = color o || configAutoColor conf } else id) <$> cmdArgsRun options -- check for multiple backends...
src/Options.hs view
@@ -82,7 +82,7 @@ , asynch :: Bool -- Misc: , debug :: Int- , no_quick :: Bool+ , no_shallow :: Bool , others :: [String] } deriving (Data, Typeable, Show)