hasktags - small patch

Lennart Kolmodin kolmodin at dtek.chalmers.se
Sat Feb 17 03:32:21 EST 2007


Marc Weber wrote:
> This small patch introduces a now mywords function which recognizes a::b as words a,::,b
> which is what we need here (?) It does work in the above example.
> 
> Here is the diff. Is it worth applying?
> 
> 154c154
> <       let wordlines = map words aslines
> ---
>>       let wordlines = map mywords aslines
> 161a162,174
>>       -- my words is mainly copied from Data.List.
>>       -- difference abc::def is split into three words instead of one.
>>       mywords :: String -> [String]
>>       mywords (':':':':xs) = "::" : mywords xs
>>       mywords s       =  case dropWhile {-partain:Char.-}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)

Without really knowing in which context this function is going to be
used, expected results and so on, I've cooked up another alternative.
Naturally it's possible to remove the spaces too if it's really required.


let wordlines =
       map (groupBy (\a b -> isVarChar a == isVarChar b)) aslines
     isVarChar x = any ($ x) [isDigit, isAlpha, (== '_'), (== '\'')]


It parses

data LogInController =
   LogInController {rLoggedIn::R Bool, rwUserName::RWE String,
rwPasswd::RWE String}

as

["data"," ","LogInController"," = ","LogInController","
{","rLoggedIn","::","R"," ","Bool",", ","rwUserName","::","RWE","
","String",", ","rwPasswd","::","RWE"," ","String","}"]

Cheers,
   Lennart K



More information about the Glasgow-haskell-users mailing list