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