[Implement haddocking for the keywords file Neil Mitchell**20080813113449] { hunk ./data/generate/Haddock.hs 5 +import Text.HTML.TagSoup hunk ./data/generate/Haddock.hs 9 -haddock "keywords" = error "haddock keywords" +haddock "keyword" = do + src <- readFile "temp/keyword/keyword.html" + let items = concatMap keywordFormat $ partitions (~== "") $ + takeWhile (~/= "
") $ parseTags src + writeFile "temp/keyword/hoogle.txt" (unlines $ keywordPrefix ++ items) hunk ./data/generate/Haddock.hs 52 + + +keywordPrefix = + ["-- Hoogle documentation, generated by Hoogle" + ,"-- From http://www.haskell.org/haskellwiki/Keywords" + ,"-- See Hoogle, http://www.haskell.org/hoogle/" + ,"" + ,"-- | Haskell keywords, always available" + ,"@package keyword" + ] + + +keywordFormat x = concat ["" : docs ++ ["@keyword " ++ n] | n <- name] + where + name = words $ f $ fromAttrib "name" (head x) + docs = zipWith (++) ("-- | " : repeat "-- ") $ + concat $ intersperse [""] $ + map (docFormat . takeWhile (~/= "
")) $ + partitions isBlock x + + isBlock (TagOpen x _) = x `elem` ["p","pre"] + isBlock _ = False + + f ('.':'2':'C':'_':xs) = ' ' : f xs + f ('.':a:b:xs) = chr res : f xs + where [(res,"")] = readHex [a,b] + f (x:xs) = x : f xs + f [] = [] + + +docFormat :: [Tag] -> [String] +docFormat (TagOpen "pre" _:xs) = map ("> " ++) $ lines $ innerText xs +docFormat (TagOpen "p" _:xs) = g 0 [] $ words $ f xs + where + g n acc [] = [unwords $ reverse $ acc | acc /= []] + g n acc (x:xs) | nx+1+n > 70 = g n acc [] ++ g nx [x] xs + | otherwise = g (n+nx+1) (x:acc) xs + where nx = length x + + f (TagOpen "code" _:xs) = "" ++ innerText a ++ f (drop 1 b) + where (a,b) = break (~== "") xs + f (x:xs) = h x ++ f xs + f [] = [] + + h (TagText x) = unwords (lines x) + h (TagOpen "a" xs) = "" + h (TagClose "a") = "" + h (TagClose "p") = "" + h x = error $ "docFormat.f: " ++ show x + }