1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2006, Adam Chlipala
4 * This program is free software
; you can redistribute it
and/or
5 * modify it under the terms
of the GNU General Public License
6 * as published by the Free Software Foundation
; either version
2
7 * of the License
, or (at your option
) any later version
.
9 * This program is distributed
in the hope that it will be useful
,
10 * but WITHOUT ANY WARRANTY
; without even the implied warranty
of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
12 * GNU General Public License for more details
.
14 * You should have received a copy
of the GNU General Public License
15 * along
with this program
; if not
, write to the Free Software
16 * Foundation
, Inc
., 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA
.
19 (* Generating HTML documentation automatically
*)
21 structure Autodoc
:> AUTODOC
= struct
23 open Ast HTML HtmlPrint
29 | _
=> str (Char.toUpper (String.sub (s
, 0)))
30 ^
String.extract (s
, 1, NONE
)
34 val prog
= Parse
.parse fname
36 if !ErrorMsg
.anyErrors
then
39 Tycheck
.checkFile
G (Defaults
.tInit ()) prog
42 fun autodoc
{outdir
, infiles
} =
44 val (prov
, infiles
) = Order
.order infiles
45 val _
= HtmlPrint
.setProviders prov
47 val G
= foldl (fn (fname
, G
) => check
' G fname
) Env
.empty infiles
51 DVal (name
, NONE
, e
) =>
52 (case Env
.lookupVal G name
of
54 | SOME t
=> DVal (name
, SOME t
, e
))
59 val file
' = #
file (OS
.Path
.splitDirFile file
)
60 val file
' = #
base (OS
.Path
.splitBaseExt file
')
67 val (desc
, decls
, _
) = Parse
.parse file
69 val file
' = modify file
71 val title
= "Domtool Module " ^ uppercase file
'
73 val outf
= TextIO.openOut (outdir ^
"/" ^ file
' ^
".html")
75 (*fun doDecl (d
, desc
, _
) =
76 Option
.app (fn desc
=> (TextIO.output (outf
, "<p>");
77 TextIO.output (outf
, desc
);
78 TextIO.output (outf
, "</p>\n"))) desc
*)
82 content
= PCDATA title
}
84 val body
= case desc
of
86 | SOME desc
=> BlockList
[body
,
88 content
= PCDATA desc
}]
90 val entries
= map (fn (d
, desc
, _
) =>
92 val cblock
= HtmlPrint
.output (p_decl (annotate_decl d
))
94 val dblock
= case desc
of
95 NONE
=> TextBlock (PCDATA
"")
96 | SOME desc
=> BLOCKQUOTE (TextBlock (PCDATA desc
))
98 BlockList
[P
{align
= NONE
,
103 val body
= BlockList (body
:: entries
)
105 val html
= HTML
{version
= NONE
,
106 head
= [Head_TITLE title
],
107 body
= BODY
{background
= NONE
,
115 (*TextIO.output (outf
, Config
.Autodoc
.htmlHeader ("Domtool Module " ^ uppercase file
'));
116 Option
.app (fn desc
=> (TextIO.output (outf
, desc
);
117 TextIO.output (outf
, "\n"))) desc
;
121 TextIO.output (outf
, Config
.Autodoc
.htmlFooter
);*)
122 PrHTML
.prHTML
{putc
= (fn ch
=> TextIO.output1 (outf
, ch
)),
123 puts
= (fn s
=> TextIO.output (outf
, s
))} html
;
127 val outf
= TextIO.openOut (outdir ^
"/index.html")
129 TextIO.output (outf
, Config
.Autodoc
.htmlHeader
"Domtool Module Index");
133 val file
' = modify file
135 TextIO.output (outf
, "<li> <a href=\"");
136 TextIO.output (outf
, file
');
137 TextIO.output (outf
, ".html\">");
138 TextIO.output (outf
, uppercase file
');
139 TextIO.output (outf
, "</a></li>\n")
142 TextIO.output (outf
, Config
.Autodoc
.htmlFooter
);
143 TextIO.closeOut outf
;