91c5a390 |
1 | (* HCoop Domtool (http://hcoop.sourceforge.net/) |
2 | * Copyright (c) 2006, Adam Chlipala |
3 | * |
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. |
8 | * |
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. |
13 | * |
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. |
17 | *) |
18 | |
19 | (* Pretty-printing Domtool configuration file ASTs for HTML *) |
20 | |
a4c53cb2 |
21 | signature HTML_PRINT_ARG = sig |
22 | include PRINTFN_INPUT where type rendering = HTML.text |
91c5a390 |
23 | |
a4c53cb2 |
24 | val setProviders : Order.providers -> unit |
25 | end |
91c5a390 |
26 | |
a4c53cb2 |
27 | structure HtmlPrintArg :> HTML_PRINT_ARG = struct |
28 | |
29 | open Ast Order |
91c5a390 |
30 | |
31 | structure TextToken = struct |
32 | type token = string |
33 | type style = HTMLDev.style |
34 | fun string t = t |
35 | fun style t = HTMLDev.styleTT |
36 | fun size t = String.size t |
37 | end |
38 | |
39 | structure SM = PPStreamFn(structure Token = TextToken |
40 | structure Device = HTMLDev) |
41 | |
42 | structure PD = PPDescFn(SM) |
43 | open PD |
44 | |
91c5a390 |
45 | fun keyword s = style (HTMLDev.styleB, [string s]) |
46 | val punct = string |
a4c53cb2 |
47 | val field = string |
48 | val lit = string |
49 | val ident = string |
50 | |
51 | val prov : providers option ref = ref NONE |
52 | fun setProviders p = prov := SOME p |
91c5a390 |
53 | |
54 | fun modify file = |
55 | let |
56 | val file' = #file (OS.Path.splitDirFile file) |
57 | val file' = #base (OS.Path.splitBaseExt file') |
58 | in |
59 | file' |
60 | end |
61 | |
62 | fun context s = |
63 | case providesContext (valOf (!prov), s) of |
64 | NONE => string s |
65 | | SOME m => style (HTMLDev.link (modify m ^ ".html#C_" ^ s), [string s]) |
66 | fun typ s = |
67 | case providesType (valOf (!prov), s) of |
68 | NONE => string s |
69 | | SOME m => style (HTMLDev.link (modify m ^ ".html#T_" ^ s), [string s]) |
70 | fun exp s = |
71 | case providesValue (valOf (!prov), s) of |
72 | NONE => string s |
73 | | SOME m => style (HTMLDev.link (modify m ^ ".html#V_" ^ s), [string s]) |
74 | |
a4c53cb2 |
75 | fun anchor (s, d) = style (HTMLDev.anchor s, [d]) |
76 | fun link (s, d) = style (HTMLDev.link s, [d]) |
91c5a390 |
77 | |
a4c53cb2 |
78 | type rendering = HTML.text |
79 | fun openStream () = |
91c5a390 |
80 | let |
81 | val dev = HTMLDev.openDev {wid = 80, |
82 | textWid = NONE} |
91c5a390 |
83 | in |
a4c53cb2 |
84 | SM.openStream dev |
91c5a390 |
85 | end |
a4c53cb2 |
86 | fun closeStream s = HTMLDev.done (SM.getDevice s) |
91c5a390 |
87 | |
88 | end |
a4c53cb2 |
89 | |
90 | structure HtmlPrint = PrintFn(HtmlPrintArg) |