From af7f8c0379dc19ee831e25b64c9e94e733f331be Mon Sep 17 00:00:00 2001 From: simonmar Date: Mon, 9 Aug 2004 11:55:07 +0000 Subject: [haddock @ 2004-08-09 11:55:05 by simonmar] Add support for a short description for each module, which is included in the contents. The short description should be given in a "Description: " field of the header. Included in this patch are changes that make the format of the header a little more flexible. From the comments: -- all fields in the header are optional and have the form -- -- [spaces1][field name][spaces] ":" -- [text]"\n" ([spaces2][space][text]"\n" | [spaces]"\n")* -- where each [spaces2] should have [spaces1] as a prefix. -- -- Thus for the key "Description", -- -- > Description : this is a -- > rather long -- > -- > description -- > -- > The module comment starts here -- -- the value will be "this is a .. description" and the rest will begin -- at "The module comment". The header fields must be in the following order: Module, Description, Copyright, License, Maintainer, Stability, Portability. Patches submitted by: George Russell , with a few small changes be me, mostly to merge with other recent changes. ToDo: document the module header. --- src/HaddockModuleTree.hs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/HaddockModuleTree.hs') diff --git a/src/HaddockModuleTree.hs b/src/HaddockModuleTree.hs index f052bd69..bd877bf4 100644 --- a/src/HaddockModuleTree.hs +++ b/src/HaddockModuleTree.hs @@ -2,28 +2,29 @@ module HaddockModuleTree(ModuleTree(..), mkModuleTree) where import HsSyn -data ModuleTree = Node String Bool (Maybe String) [ModuleTree] +data ModuleTree = Node String Bool (Maybe String) (Maybe Doc) [ModuleTree] -mkModuleTree :: [(Module,Maybe String)] -> [ModuleTree] +mkModuleTree :: [(Module,Maybe String,Maybe Doc)] -> [ModuleTree] mkModuleTree mods = - foldr fn [] [ (splitModule mod, pkg) | (mod,pkg) <- mods ] + foldr fn [] [ (splitModule mod, pkg,short) | (mod,pkg,short) <- mods ] where - fn (mod,pkg) trees = addToTrees mod pkg trees + fn (mod,pkg,short) trees = addToTrees mod pkg short trees -addToTrees :: [String] -> Maybe String -> [ModuleTree] -> [ModuleTree] -addToTrees [] pkg ts = ts -addToTrees ss pkg [] = mkSubTree ss pkg -addToTrees (s1:ss) pkg (t@(Node s2 leaf node_pkg subs) : ts) - | s1 > s2 = t : addToTrees (s1:ss) pkg ts - | s1 == s2 = Node s2 (leaf || null ss) this_pkg (addToTrees ss pkg subs) : ts - | otherwise = mkSubTree (s1:ss) pkg ++ t : ts +addToTrees :: [String] -> Maybe String -> Maybe Doc -> [ModuleTree] -> [ModuleTree] +addToTrees [] pkg short ts = ts +addToTrees ss pkg short [] = mkSubTree ss pkg short +addToTrees (s1:ss) pkg short (t@(Node s2 leaf node_pkg node_short subs) : ts) + | s1 > s2 = t : addToTrees (s1:ss) pkg short ts + | s1 == s2 = Node s2 (leaf || null ss) this_pkg this_short (addToTrees ss pkg short subs) : ts + | otherwise = mkSubTree (s1:ss) pkg short ++ t : ts where this_pkg = if null ss then pkg else node_pkg + this_short = if null ss then short else node_short -mkSubTree :: [String] -> Maybe String -> [ModuleTree] -mkSubTree [] pkg = [] -mkSubTree [s] pkg = [Node s True pkg []] -mkSubTree (s:ss) pkg = [Node s (null ss) Nothing (mkSubTree ss pkg)] +mkSubTree :: [String] -> Maybe String -> Maybe Doc -> [ModuleTree] +mkSubTree [] pkg short = [] +mkSubTree [s] pkg short = [Node s True pkg short []] +mkSubTree (s:ss) pkg short = [Node s (null ss) Nothing Nothing (mkSubTree ss pkg short)] splitModule :: Module -> [String] splitModule (Module mdl) = split mdl -- cgit v1.2.3