diff options
author | Ian Lynagh <igloo@earth.li> | 2007-03-14 16:01:02 +0000 |
---|---|---|
committer | Ian Lynagh <igloo@earth.li> | 2007-03-14 16:01:02 +0000 |
commit | 115568e850a69989358cb0c38a281f6958d6b499 (patch) | |
tree | e65701215e2d7d58ce3e319062a1c446f8170c93 /utils | |
parent | 87ebda2011a8ef511b14d96728f01c419e5bb665 (diff) | |
download | haskell-115568e850a69989358cb0c38a281f6958d6b499.tar.gz |
Tweak hasktags to cope with abc::def correctly
Patch from Marc Weber in
http://www.haskell.org/pipermail/glasgow-haskell-users/2007-February/011998.html
Diffstat (limited to 'utils')
-rw-r--r-- | utils/hasktags/HaskTags.hs | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/utils/hasktags/HaskTags.hs b/utils/hasktags/HaskTags.hs index 43bffee2b8..a27752e55a 100644 --- a/utils/hasktags/HaskTags.hs +++ b/utils/hasktags/HaskTags.hs @@ -146,20 +146,34 @@ spacedwords xs = (blanks ++ wordchars):(spacedwords rest2) findthings :: FileName -> IO FileData findthings filename = do - text <- readFile filename - evaluate text -- forces evaluation of text - -- too many files were being opened otherwise since - -- readFile is lazy - let aslines = lines text - let wordlines = map words aslines - let noslcoms = map stripslcomments wordlines - let tokens = concat $ zipWith3 (withline filename) noslcoms - aslines [0 ..] - let nocoms = stripblockcomments tokens - return $ FileData filename $ findstuff nocoms + text <- readFile filename + evaluate text -- forces evaluation of text + -- too many files were being opened otherwise since + -- readFile is lazy + let aslines = lines text + let wordlines = map mywords aslines + let noslcoms = map stripslcomments wordlines + let tokens = concat $ zipWith3 (withline filename) noslcoms aslines [0 ..] + let nocoms = stripblockcomments tokens + return $ FileData filename $ findstuff nocoms where evaluate [] = return () evaluate (c:cs) = c `seq` evaluate cs - + -- my words is mainly copied from Data.List. + -- difference abc::def is split into three words instead of one. + -- We should really be lexing Haskell properly here rather + -- than using hacks like this. In the future we expect hasktags + -- to be replaced by something using the GHC API. + mywords :: String -> [String] + mywords (':':':':xs) = "::" : mywords xs + mywords s = case dropWhile isSpace s of + "" -> [] + s' -> w : mywords s'' + where (w, s'') = myBreak s' + myBreak [] = ([],[]) + myBreak (':':':':xs) = ([], "::"++xs) + myBreak (' ':xs) = ([],xs); + myBreak (x:xs) = let (a,b) = myBreak xs + in (x:a,b) -- Create tokens from words, by recording their line number -- and which token they are through that line |