<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <!-- Generated by HsColour, http://www.cs.york.ac.uk/fp/darcs/hscolour/ --> <title>src/Haddock/Backends/HaddockDB.hs</title> <link type='text/css' rel='stylesheet' href='hscolour.css' /> </head> <body> <pre><a name="line-1"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span> <a name="line-2"></a><span class='hs-comment'>-- |</span> <a name="line-3"></a><span class='hs-comment'>-- Module : Haddock.Backends.HaddockDB</span> <a name="line-4"></a><span class='hs-comment'>-- Copyright : (c) Simon Marlow 2003</span> <a name="line-5"></a><span class='hs-comment'>-- License : BSD-like</span> <a name="line-6"></a><span class='hs-comment'>--</span> <a name="line-7"></a><span class='hs-comment'>-- Maintainer : haddock@projects.haskell.org</span> <a name="line-8"></a><span class='hs-comment'>-- Stability : experimental</span> <a name="line-9"></a><span class='hs-comment'>-- Portability : portable</span> <a name="line-10"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span> <a name="line-11"></a> <a name="line-12"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Haddock</span><span class='hs-varop'>.</span><span class='hs-conid'>Backends</span><span class='hs-varop'>.</span><span class='hs-conid'>HaddockDB</span> <span class='hs-layout'>(</span><span class='hs-varid'>ppDocBook</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span> <a name="line-13"></a> <a name="line-14"></a><span class='hs-comment'>{- <a name="line-15"></a>import HaddockTypes <a name="line-16"></a>import HaddockUtil <a name="line-17"></a>import HsSyn2 <a name="line-18"></a> <a name="line-19"></a>import Text.PrettyPrint <a name="line-20"></a>-}</span> <a name="line-21"></a> <a name="line-22"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span> <a name="line-23"></a><span class='hs-comment'>-- Printing the results in DocBook format</span> <a name="line-24"></a> <a name="line-25"></a><a name="ppDocBook"></a><span class='hs-definition'>ppDocBook</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>a</span> <a name="line-26"></a><span class='hs-definition'>ppDocBook</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-str'>"not working"</span> <a name="line-27"></a><span class='hs-comment'>{- <a name="line-28"></a>ppDocBook :: FilePath -> [(Module, Interface)] -> String <a name="line-29"></a>ppDocBook odir mods = render (ppIfaces mods) <a name="line-30"></a> <a name="line-31"></a>ppIfaces mods <a name="line-32"></a> = text "<!DOCTYPE BOOK PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\" [" <a name="line-33"></a> $$ text "]>" <a name="line-34"></a> $$ text "<book>" <a name="line-35"></a> $$ text "<bookinfo>" <a name="line-36"></a> $$ text "<author><othername>HaskellDoc version 0.0</othername></author>" <a name="line-37"></a> $$ text "</bookinfo>" <a name="line-38"></a> $$ text "<article>" <a name="line-39"></a> $$ vcat (map do_mod mods) <a name="line-40"></a> $$ text "</article></book>" <a name="line-41"></a> where <a name="line-42"></a> do_mod (Module mod, iface) <a name="line-43"></a> = text "<sect1 id=\"sec-" <> text mod <> text "\">" <a name="line-44"></a> $$ text "<title><literal>" <a name="line-45"></a> <> text mod <a name="line-46"></a> <> text "</literal></title>" <a name="line-47"></a> $$ text "<indexterm><primary><literal>" <a name="line-48"></a> <> text mod <a name="line-49"></a> <> text "</literal></primary></indexterm>" <a name="line-50"></a> $$ text "<variablelist>" <a name="line-51"></a> $$ vcat (map (do_export mod) (eltsFM (iface_decls iface))) <a name="line-52"></a> $$ text "</variablelist>" <a name="line-53"></a> $$ text "</sect1>" <a name="line-54"></a> <a name="line-55"></a> do_export mod decl | (nm:_) <- declBinders decl <a name="line-56"></a> = text "<varlistentry id=" <> ppLinkId mod nm <> char '>' <a name="line-57"></a> $$ text "<term><literal>" <a name="line-58"></a> <> do_decl decl <a name="line-59"></a> <> text "</literal></term>" <a name="line-60"></a> $$ text "<listitem>" <a name="line-61"></a> $$ text "<para>" <a name="line-62"></a> $$ text "</para>" <a name="line-63"></a> $$ text "</listitem>" <a name="line-64"></a> $$ text "</varlistentry>" <a name="line-65"></a> do_export _ _ = empty <a name="line-66"></a> <a name="line-67"></a> do_decl (HsTypeSig _ [nm] ty _) <a name="line-68"></a> = ppHsName nm <> text " :: " <> ppHsType ty <a name="line-69"></a> do_decl (HsTypeDecl _ nm args ty _) <a name="line-70"></a> = hsep ([text "type", ppHsName nm ] <a name="line-71"></a> ++ map ppHsName args <a name="line-72"></a> ++ [equals, ppHsType ty]) <a name="line-73"></a> do_decl (HsNewTypeDecl loc ctx nm args con drv _) <a name="line-74"></a> = hsep ([text "data", ppHsName nm] -- data, not newtype <a name="line-75"></a> ++ map ppHsName args <a name="line-76"></a> ) <+> equals <+> ppHsConstr con -- ToDo: derivings <a name="line-77"></a> do_decl (HsDataDecl loc ctx nm args cons drv _) <a name="line-78"></a> = hsep ([text "data", {-ToDo: context-}ppHsName nm] <a name="line-79"></a> ++ map ppHsName args) <a name="line-80"></a> <+> vcat (zipWith (<+>) (equals : repeat (char '|')) <a name="line-81"></a> (map ppHsConstr cons)) <a name="line-82"></a> do_decl (HsClassDecl loc ty fds decl _) <a name="line-83"></a> = hsep [text "class", ppHsType ty] <a name="line-84"></a> do_decl decl <a name="line-85"></a> = empty <a name="line-86"></a> <a name="line-87"></a>ppHsConstr :: HsConDecl -> Doc <a name="line-88"></a>ppHsConstr (HsRecDecl pos name tvs ctxt fieldList maybe_doc) = <a name="line-89"></a> ppHsName name <a name="line-90"></a> <> (braces . hsep . punctuate comma . map ppField $ fieldList) <a name="line-91"></a>ppHsConstr (HsConDecl pos name tvs ctxt typeList maybe_doc) = <a name="line-92"></a> hsep (ppHsName name : map ppHsBangType typeList) <a name="line-93"></a> <a name="line-94"></a>ppField (HsFieldDecl ns ty doc) <a name="line-95"></a> = hsep (punctuate comma (map ppHsName ns) ++ <a name="line-96"></a> [text "::", ppHsBangType ty]) <a name="line-97"></a> <a name="line-98"></a>ppHsBangType :: HsBangType -> Doc <a name="line-99"></a>ppHsBangType (HsBangedTy ty) = char '!' <> ppHsType ty <a name="line-100"></a>ppHsBangType (HsUnBangedTy ty) = ppHsType ty <a name="line-101"></a> <a name="line-102"></a>ppHsContext :: HsContext -> Doc <a name="line-103"></a>ppHsContext [] = empty <a name="line-104"></a>ppHsContext context = parenList (map (\ (a,b) -> ppHsQName a <+> <a name="line-105"></a> hsep (map ppHsAType b)) context) <a name="line-106"></a> <a name="line-107"></a>ppHsType :: HsType -> Doc <a name="line-108"></a>ppHsType (HsForAllType Nothing context htype) = <a name="line-109"></a> hsep [ ppHsContext context, text "=>", ppHsType htype] <a name="line-110"></a>ppHsType (HsForAllType (Just tvs) [] htype) = <a name="line-111"></a> hsep (text "forall" : map ppHsName tvs ++ text "." : [ppHsType htype]) <a name="line-112"></a>ppHsType (HsForAllType (Just tvs) context htype) = <a name="line-113"></a> hsep (text "forall" : map ppHsName tvs ++ text "." : <a name="line-114"></a> ppHsContext context : text "=>" : [ppHsType htype]) <a name="line-115"></a>ppHsType (HsTyFun a b) = fsep [ppHsBType a, text "-&gt;", ppHsType b] <a name="line-116"></a>ppHsType (HsTyIP n t) = fsep [(char '?' <> ppHsName n), text "::", ppHsType t] <a name="line-117"></a>ppHsType t = ppHsBType t <a name="line-118"></a> <a name="line-119"></a>ppHsBType (HsTyApp (HsTyCon (Qual (Module "Prelude") (HsTyClsName (HsSpecial "[]")))) b ) <a name="line-120"></a> = brackets $ ppHsType b <a name="line-121"></a>ppHsBType (HsTyApp a b) = fsep [ppHsBType a, ppHsAType b] <a name="line-122"></a>ppHsBType t = ppHsAType t <a name="line-123"></a> <a name="line-124"></a>ppHsAType :: HsType -> Doc <a name="line-125"></a>ppHsAType (HsTyTuple True l) = parenList . map ppHsType $ l <a name="line-126"></a>ppHsAType (HsTyTuple False l) = ubxParenList . map ppHsType $ l <a name="line-127"></a>-- special case <a name="line-128"></a>ppHsAType (HsTyApp (HsTyCon (Qual (Module "Prelude") (HsTyClsName (HsSpecial "[]")))) b ) <a name="line-129"></a> = brackets $ ppHsType b <a name="line-130"></a>ppHsAType (HsTyVar name) = ppHsName name <a name="line-131"></a>ppHsAType (HsTyCon name) = ppHsQName name <a name="line-132"></a>ppHsAType t = parens $ ppHsType t <a name="line-133"></a> <a name="line-134"></a>ppHsQName :: HsQName -> Doc <a name="line-135"></a>ppHsQName (UnQual str) = ppHsName str <a name="line-136"></a>ppHsQName n@(Qual (Module mod) str) <a name="line-137"></a> | n == unit_con_name = ppHsName str <a name="line-138"></a> | isSpecial str = ppHsName str <a name="line-139"></a> | otherwise <a name="line-140"></a> = text "<link linkend=" <> ppLinkId mod str <> char '>' <a name="line-141"></a> <> ppHsName str <a name="line-142"></a> <> text "</link>" <a name="line-143"></a> <a name="line-144"></a>isSpecial (HsTyClsName id) | HsSpecial _ <- id = True <a name="line-145"></a>isSpecial (HsVarName id) | HsSpecial _ <- id = True <a name="line-146"></a>isSpecial _ = False <a name="line-147"></a> <a name="line-148"></a>ppHsName :: HsName -> Doc <a name="line-149"></a>ppHsName (HsTyClsName id) = ppHsIdentifier id <a name="line-150"></a>ppHsName (HsVarName id) = ppHsIdentifier id <a name="line-151"></a> <a name="line-152"></a>ppHsIdentifier :: HsIdentifier -> Doc <a name="line-153"></a>ppHsIdentifier (HsIdent str) = text str <a name="line-154"></a>ppHsIdentifier (HsSymbol str) = text str <a name="line-155"></a>ppHsIdentifier (HsSpecial str) = text str <a name="line-156"></a> <a name="line-157"></a>ppLinkId :: String -> HsName -> Doc <a name="line-158"></a>ppLinkId mod str <a name="line-159"></a> = hcat [char '\"', text mod, char '.', ppHsName str, char '\"'] <a name="line-160"></a> <a name="line-161"></a>-- ----------------------------------------------------------------------------- <a name="line-162"></a>-- * Misc <a name="line-163"></a> <a name="line-164"></a>parenList :: [Doc] -> Doc <a name="line-165"></a>parenList = parens . fsep . punctuate comma <a name="line-166"></a> <a name="line-167"></a>ubxParenList :: [Doc] -> Doc <a name="line-168"></a>ubxParenList = ubxparens . fsep . punctuate comma <a name="line-169"></a> <a name="line-170"></a>ubxparens p = text "(#" <> p <> text "#)" <a name="line-171"></a>-}</span> </pre></body> </html>