cgrep 6.5.2 → 6.5.3
raw patch · 9 files changed
+34/−33 lines, 9 files
Files
- README.md +1/−1
- cgrep.cabal +1/−1
- src/CGrep/Common.hs +1/−1
- src/CGrep/Semantic/WildCard.hs +14/−14
- src/CGrep/Strategy/Cpp/Semantic.hs +7/−6
- src/CGrep/Strategy/Generic/Semantic.hs +6/−5
- src/Config.hs +1/−1
- src/Main.hs +2/−2
- src/Util.hs +1/−2
README.md view
@@ -4,7 +4,7 @@ Usage ----- -Cgrep 6.5.2 Usage: cgrep [OPTION] [PATTERN] files...+Cgrep 6.5.3 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.5.2+Version: 6.5.3 Synopsis: Command line tool Homepage: http://awgn.github.io/cgrep/ License: GPL-2
src/CGrep/Common.hs view
@@ -59,7 +59,7 @@ quickSearch :: Options -> [Text8] -> Text8 -> Maybe Bool quickSearch opt ps text | no_turbo opt = Nothing- | otherwise = Just $ any has_pattern ps+ | otherwise = Just $ any has_pattern ps || null ps where has_pattern pat = notNull $ pat `SC.nonOverlappingIndices` text
src/CGrep/Semantic/WildCard.hs view
@@ -17,12 +17,10 @@ -- module CGrep.Semantic.WildCard (WildCard(..), MultiCard,- wildCardMap, mkWildCardFromToken, combineMultiCard, filterTokensWithMultiCards, wildCardMatch,- isWildCardPattern, multiCardMatch) where import qualified Data.Map as M@@ -36,6 +34,7 @@ import Options import Util + data WildCard a = TokenCard a | AnyCard |@@ -50,6 +49,7 @@ deriving (Show, Eq, Ord) + type MultiCard a = [WildCard a] @@ -70,10 +70,11 @@ mkWildCardFromToken :: (SemanticToken a) => a -> WildCard a mkWildCardFromToken t | tkIsIdentifier t = case () of- _ | Just wc <- M.lookup str wildCardMap -> wc- | isWildCardPattern str -> IdentifCard str- | otherwise -> TokenCard $ tkToIdentif (rmWildCardEscape str) (tkToOffset t)- where str = tkToString t+ _ | Just wc <- M.lookup str wildCardMap -> wc+ | isWildCardIdentif str -> IdentifCard str+ | otherwise -> TokenCard $ tkToIdentif (rmWildCardEscape str) (tkToOffset t)+ where str = tkToString t+ | otherwise = TokenCard t @@ -118,19 +119,18 @@ where ts = multiCardGroupCompare opt l r -isWildCardPattern :: String -> Bool-isWildCardPattern s =+isWildCardIdentif :: String -> Bool+isWildCardIdentif s = case () of- _ | (x:y:_) <- s -> wprefix x && not (wprefix y)+ _ | (x:y:_) <- s -> wprefix x && isNumber y | [x] <- s -> wprefix x- | otherwise -> error "isWildCardPattern"+ | otherwise -> error "isWildCardIdentif" where wprefix x = x == '$' || x == '_' rmWildCardEscape :: String -> String-rmWildCardEscape ('$':'_':xs) = '_' : xs-rmWildCardEscape ('_':'_':xs) = '_' : xs-rmWildCardEscape ('$':'$':xs) = '$' : xs+rmWildCardEscape ('$':xs) = xs+rmWildCardEscape ('_':xs) = xs rmWildCardEscape xs = xs @@ -143,7 +143,7 @@ {-# INLINE multiCardCheckOccurences #-} -- Note: pattern $ and _ match any token, whereas $1 $2 (_1 _2 etc.) match tokens--- that must compare equal in the relative occurrences+-- that must compare equal in the respective occurrences -- multiCardCheckOccurences :: (SemanticToken a) => [(Bool, (MultiCard a, [String]))] -> Bool
src/CGrep/Strategy/Cpp/Semantic.hs view
@@ -58,12 +58,13 @@ -- quick Search... - ps' = filter (/= "OR") $ (mapMaybe (\x -> case x of- TokenCard (Cpp.TokenChar xs _) -> Just (rmQuote $ trim xs)- TokenCard (Cpp.TokenString xs _) -> Just (rmQuote $ trim xs)- TokenCard t -> Just (Cpp.toString t)- _ -> Nothing- ) . concat) patterns'+ ps' = (mapMaybe (\x -> case x of+ TokenCard (Cpp.TokenChar xs _) -> Just (rmQuote $ trim xs)+ TokenCard (Cpp.TokenString xs _) -> Just (rmQuote $ trim xs)+ TokenCard (Cpp.TokenIdentifier "OR" _) -> Nothing+ TokenCard t -> Just (Cpp.toString t)+ _ -> Nothing+ ) . concat) patterns' found = quickSearch opt (map C.pack ps') text'
src/CGrep/Strategy/Generic/Semantic.hs view
@@ -59,11 +59,12 @@ -- quickSearch ... - ps' = filter (/= "OR") $ (mapMaybe (\x -> case x of- TokenCard (Generic.TokenLiteral xs _) -> Just (rmQuote $ trim xs)- TokenCard t -> Just (tkToString t)- _ -> Nothing- ) . concat) patterns'+ ps' = (mapMaybe (\x -> case x of+ TokenCard (Generic.TokenLiteral xs _) -> Just (rmQuote $ trim xs)+ TokenCard (Generic.TokenAlpha "OR" _) -> Nothing+ TokenCard t -> Just (tkToString t)+ _ -> Nothing+ ) . concat) patterns' found = quickSearch opt (map C.pack ps') text'
src/Config.hs view
@@ -31,7 +31,7 @@ cgreprc = "cgreprc" version :: String-version = "6.5.2"+version = "6.5.3" data Config = Config
src/Main.hs view
@@ -68,11 +68,11 @@ xs <- getDirectoryContents dir (dirs,files) <- partitionM doesDirectoryExist [dir </> x | x <- xs, x `notElem` [".", ".."]] -- process files- let files' = flip mapMaybe files+ let files' = mapMaybe (\n -> let filename = takeFileName n in if isNothing $ getFileLang opts filename >>= (\f -> f `elemIndex` langs <|> toMaybe 0 (null langs)) then Nothing- else Just n)+ else Just n) files unless (null files') $ let chunks = chunksOf (Options.chunk opts) files' in
src/Util.hs view
@@ -25,12 +25,11 @@ import Data.Maybe import Data.Char-import Control.Monad -- from hlint :-) partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a], [a])-partitionM f [] = return ([], [])+partitionM _ [] = return ([], []) partitionM f (x:xs) = do res <- f x (as,bs) <- partitionM f xs