cgrep 6.4.4 → 6.4.5
raw patch · 10 files changed
+46/−54 lines, 10 files
Files
- README.md +1/−1
- cgrep.cabal +1/−1
- src/CGrep/Semantic/Cpp/Token.hs +1/−1
- src/CGrep/Strategy/BoyerMoore.hs +5/−5
- src/CGrep/Strategy/Cpp/Semantic.hs +10/−10
- src/CGrep/Strategy/Cpp/Tokenizer.hs +6/−8
- src/CGrep/Strategy/Generic/Semantic.hs +10/−13
- src/CGrep/Strategy/Levenshtein.hs +5/−6
- src/CGrep/Strategy/Regex.hs +5/−7
- src/Config.hs +2/−2
README.md view
@@ -4,7 +4,7 @@ Usage ----- -Cgrep 6.4.4 Usage: cgrep [OPTION] [PATTERN] files...+Cgrep 6.4.5 Usage: cgrep [OPTION] [PATTERN] files... cgrep [OPTIONS] [ITEM]
cgrep.cabal view
@@ -1,6 +1,6 @@ Name: cgrep Description: Cgrep: a context-aware grep for source codes-Version: 6.4.4+Version: 6.4.5 Synopsis: Command line tool Homepage: http://awgn.github.io/cgrep/ License: GPL-2
src/CGrep/Semantic/Cpp/Token.hs view
@@ -197,10 +197,10 @@ let token = fromJust $ getTokenDirective xs state `mplus` getTokenHeaderName xs state `mplus`- getTokenIdOrKeyword xs state `mplus` getTokenNumber xs state `mplus` getTokenString xs state `mplus` getTokenChar xs state `mplus`+ getTokenIdOrKeyword xs state `mplus` getTokenOpOrPunct xs state tstring = toString token len = fromIntegral $ length tstring
src/CGrep/Strategy/BoyerMoore.hs view
@@ -50,7 +50,7 @@ -- quick search... - let found = quickSearch opt ps text'+ found = quickSearch opt ps text' -- put banners... @@ -66,15 +66,15 @@ -- expand multi-line - let text''' = expandMultiline opt text''+ text''' = expandMultiline opt text'' -- search for matching tokens - let tokens = map (A.second C.unpack) $ ps >>= (\p -> map (\i -> (i,p)) (p `SC.nonOverlappingIndices` text'''))+ tokens = map (A.second C.unpack) $ ps >>= (\p -> map (\i -> (i,p)) (p `SC.nonOverlappingIndices` text''')) - -- filter exact matching tokens+ -- filter exact/partial matching tokens - let tokens' = if word_match opt || prefix_match opt || suffix_match opt+ tokens' = if word_match opt || prefix_match opt || suffix_match opt then filter (checkToken opt text''') tokens else tokens
src/CGrep/Strategy/Cpp/Semantic.hs view
@@ -50,26 +50,26 @@ let text' = ignoreCase opt text - let filt = (mkContextFilter opt) { getComment = False }+ filt = (mkContextFilter opt) { getComment = False } -- pre-process patterns - let patterns = map (Cpp.tokenizer . contextFilter (Just Cpp) filt) ps -- [ [t1,t2,..], [t1,t2...] ]+ patterns = map (Cpp.tokenizer . contextFilter (Just Cpp) filt) ps -- [ [t1,t2,..], [t1,t2...] ] - let patterns' = map (map mkWildCard) patterns -- [ [w1,w2,..], [w1,w2,..] ]+ patterns' = map (map mkWildCard) patterns -- [ [w1,w2,..], [w1,w2,..] ] - let patterns'' = map (combineMultiCard . map (:[])) patterns' -- [ [m1,m2,..], [m1,m2,..] ] == [ [ [w1], [w2],..], [[w1],[w2],..]]+ patterns'' = map (combineMultiCard . map (:[])) patterns' -- [ [m1,m2,..], [m1,m2,..] ] == [ [ [w1], [w2],..], [[w1],[w2],..]] -- quick Search... - let ps' = map (C.pack . (\l -> if null l then ""+ ps' = map (C.pack . (\l -> if null l then "" else maximumBy (compare `on` length) l) . mapMaybe (\x -> case x of TokenCard (Cpp.TokenChar xs _) -> Just $ unquotes $ trim xs TokenCard (Cpp.TokenString xs _) -> Just $ unquotes $ trim xs TokenCard t -> Just $ Cpp.toString t _ -> Nothing)) patterns' - let found = quickSearch opt ps' text'+ found = quickSearch opt ps' text' -- put banners... @@ -88,17 +88,17 @@ -- expand multi-line - let text''' = expandMultiline opt text''+ text''' = expandMultiline opt text'' -- parse source code, get the Cpp.Token list... - let tokens = Cpp.tokenizer text'''+ tokens = Cpp.tokenizer text''' -- get matching tokens ... - let tokens' = sortBy (compare `on` Cpp.offset) $ nub $ concatMap (\ms -> filterTokensWithMultiCards opt ms tokens) patterns''+ tokens' = sortBy (compare `on` Cpp.offset) $ nub $ concatMap (\ms -> filterTokensWithMultiCards opt ms tokens) patterns'' - let matches = map (\t -> let n = fromIntegral (Cpp.offset t) in (n, Cpp.toString t)) tokens' :: [(Int, String)]+ matches = map (\t -> let n = fromIntegral (Cpp.offset t) in (n, Cpp.toString t)) tokens' :: [(Int, String)] putStrLevel2 (debug opt) $ "tokens : " ++ show tokens' putStrLevel2 (debug opt) $ "matches : " ++ show matches
src/CGrep/Strategy/Cpp/Tokenizer.hs view
@@ -43,8 +43,7 @@ -- transform text let text' = ignoreCase opt text-- let filt = (mkContextFilter opt) { getComment = False }+ filt = (mkContextFilter opt) { getComment = False } putStrLevel1 (debug opt) $ "strategy : running C/C++ token search on " ++ filename ++ "..." @@ -62,15 +61,15 @@ -- expand multi-line - let text''' = expandMultiline opt text''+ text''' = expandMultiline opt text'' -- parse source code, get the Cpp.Token list... - let tokens = Cpp.tokenizer text'''+ tokens = Cpp.tokenizer text''' -- context-filterting... - let tokens'= filter (Cpp.tokenFilter Cpp.TokenFilter { Cpp.filtIdentifier = identifier opt,+ tokens'= filter (Cpp.tokenFilter Cpp.TokenFilter { Cpp.filtIdentifier = identifier opt, Cpp.filtDirective = directive opt, Cpp.filtKeyword = keyword opt, Cpp.filtHeader = header opt,@@ -81,17 +80,16 @@ -- filter tokens... - let tokens'' = cppTokenFilter opt (map C.unpack ps) tokens'+ tokens'' = cppTokenFilter opt (map C.unpack ps) tokens' -- convert Cpp.Tokens to CGrep.Tokens - let matches = map (\t -> let off = fromIntegral (Cpp.offset t) in (off, Cpp.toString t)) tokens'' :: [(Int, String)]+ matches = map (\t -> let off = fromIntegral (Cpp.offset t) in (off, Cpp.toString t)) tokens'' :: [(Int, String)] putStrLevel2 (debug opt) $ "tokens : " ++ show tokens putStrLevel2 (debug opt) $ "tokens' : " ++ show tokens' putStrLevel2 (debug opt) $ "tokens'' : " ++ show tokens'' putStrLevel2 (debug opt) $ "matches : " ++ show matches- putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text''' ++ "\n---" return $ mkOutput opt filename text text''' matches
src/CGrep/Strategy/Generic/Semantic.hs view
@@ -50,19 +50,17 @@ let text' = ignoreCase opt text - let filt = (mkContextFilter opt) { getComment = False }+ filt = (mkContextFilter opt) { getComment = False } -- pre-process patterns - let patterns = map (Generic.tokenizer . contextFilter (getLang opt filename) filt) ps -- [ [t1,t2,..], [t1,t2...] ]-- let patterns' = map (map mkWildCard) patterns -- [ [w1,w2,..], [w1,w2,..] ]-- let patterns'' = map (combineMultiCard . map (:[])) patterns' -- [ [m1,m2,..], [m1,m2,..] ] == [ [ [w1], [w2],..], [[w1],[w2],..]]+ patterns = map (Generic.tokenizer . contextFilter (getLang opt filename) filt) ps -- [ [t1,t2,..], [t1,t2...] ]+ patterns' = map (map mkWildCard) patterns -- [ [w1,w2,..], [w1,w2,..] ]+ patterns'' = map (combineMultiCard . map (:[])) patterns' -- [ [m1,m2,..], [m1,m2,..] ] == [ [ [w1], [w2],..], [[w1],[w2],..]] -- quickSearch ... - let ps' = map ( C.pack . (\l -> if null l then ""+ ps' = map ( C.pack . (\l -> if null l then "" else maximumBy (compare `on` length) l) . mapMaybe (\x -> case x of TokenCard (Generic.TokenLiteral xs _) -> Just (unquotes $ trim xs) TokenCard t -> Just (tkToString t)@@ -87,20 +85,19 @@ -- expand multi-line - let text''' = expandMultiline opt text''+ text''' = expandMultiline opt text'' -- parse source code, get the Generic.Token list... - let tokens = Generic.tokenizer text'''+ tokens = Generic.tokenizer text''' -- get matching tokens ... - let tokens' = sortBy (compare `on` Generic.offset) $ nub $ concatMap (\ms -> filterTokensWithMultiCards opt ms tokens) patterns''+ tokens' = sortBy (compare `on` Generic.offset) $ nub $ concatMap (\ms -> filterTokensWithMultiCards opt ms tokens) patterns'' - let matches = map (\t -> let n = fromIntegral (Generic.offset t) in (n, Generic.toString t)) tokens' :: [(Int, String)]+ matches = map (\t -> let n = fromIntegral (Generic.offset t) in (n, Generic.toString t)) tokens' :: [(Int, String)] - putStrLevel2 (debug opt) $ "tokens : " ++ show tokens- putStrLevel2 (debug opt) $ "tokens' : " ++ show tokens'+ putStrLevel2 (debug opt) $ "tokens : " ++ show tokens' putStrLevel2 (debug opt) $ "matches : " ++ show matches putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text''' ++ "\n---"
src/CGrep/Strategy/Levenshtein.hs view
@@ -41,22 +41,21 @@ let text' = ignoreCase opt . contextFilter (getLang opt filename) (mkContextFilter opt) $ text - let text'' = expandMultiline opt text'+ text'' = expandMultiline opt text' -- parse source code, get the Cpp.Token list... - let tokens' = tokenizer text''+ tokens' = tokenizer text'' -- filter tokens... - let patterns = map C.unpack ps+ patterns = map C.unpack ps - let matches = filter (\t -> any (\p -> p ~== snd t) patterns) tokens'+ matches = filter (\t -> any (\p -> p ~== snd t) patterns) tokens' putStrLevel1 (debug opt) $ "strategy : running edit-distance (Levenshtein) search on " ++ filename ++ "..."- putStrLevel2 (debug opt) $ "tokens' : " ++ show tokens'+ putStrLevel2 (debug opt) $ "tokens : " ++ show tokens' putStrLevel2 (debug opt) $ "matches : " ++ show matches- putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text'' ++ "\n---" return $ mkOutput opt filename text text'' matches
src/CGrep/Strategy/Regex.hs view
@@ -45,22 +45,20 @@ let text' = expandMultiline opt . ignoreCase opt $ text - -- put banners...-- putStrLevel1 (debug opt) $ "strategy : running regex search on " ++ filename ++ "..."- -- context filter - let text'' = contextFilter (getLang opt filename) (mkContextFilter opt) text'+ text'' = contextFilter (getLang opt filename) (mkContextFilter opt) text' -- expand multi-line - let text''' = expandMultiline opt text''+ text''' = expandMultiline opt text'' -- search for matching tokens - let tokens = map (\(str, (off,_)) -> (off, C.unpack str) ) $ concatMap elems $ ps >>= (\p -> elems (getAllTextMatches $ text''' =~ p :: (Array Int) (MatchText Text8)) )+ tokens = map (\(str, (off,_)) -> (off, C.unpack str) ) $+ concatMap elems $ ps >>= (\p -> elems (getAllTextMatches $ text''' =~ p :: (Array Int) (MatchText Text8))) + putStrLevel1 (debug opt) $ "strategy : running regex search on " ++ filename ++ "..." putStrLevel2 (debug opt) $ "tokens : " ++ show tokens putStrLevel3 (debug opt) $ "---\n" ++ C.unpack text''' ++ "\n---"
src/Config.hs view
@@ -31,7 +31,7 @@ cgreprc = "cgreprc" version :: String-version = "6.4.4"+version = "6.4.5" data Config = Config {@@ -45,7 +45,7 @@ getConfig = do home <- getHomeDirectory conf <- liftM msum $ forM [ home </> "." ++ cgreprc, "/etc" </> cgreprc ] $ \f ->- doesFileExist f >>= \b -> return $ guard b >> Just f+ (doesFileExist >=> (\b -> return $ guard b >> Just f)) f if isJust conf then readFile (fromJust conf) >>= \xs -> return (prettyRead (dropComments xs) "Config error" :: Config)