Commit | Line | Data |
---|---|---|
3196000d AC |
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 | ||
9b7ee2b2 AC |
21 | signature HTML_PRINT_ARG = sig |
22 | include PRINTFN_INPUT where type rendering = HTML.text | |
3196000d | 23 | |
9b7ee2b2 AC |
24 | val setProviders : Order.providers -> unit |
25 | end | |
3196000d | 26 | |
9b7ee2b2 AC |
27 | structure HtmlPrintArg :> HTML_PRINT_ARG = struct |
28 | ||
29 | open Ast Order | |
3196000d AC |
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 | ||
3196000d AC |
45 | fun keyword s = style (HTMLDev.styleB, [string s]) |
46 | val punct = string | |
9b7ee2b2 AC |
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 | |
3196000d AC |
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 | ||
9b7ee2b2 AC |
75 | fun anchor (s, d) = style (HTMLDev.anchor s, [d]) |
76 | fun link (s, d) = style (HTMLDev.link s, [d]) | |
3196000d | 77 | |
9b7ee2b2 AC |
78 | type rendering = HTML.text |
79 | fun openStream () = | |
3196000d AC |
80 | let |
81 | val dev = HTMLDev.openDev {wid = 80, | |
82 | textWid = NONE} | |
3196000d | 83 | in |
9b7ee2b2 | 84 | SM.openStream dev |
3196000d | 85 | end |
9b7ee2b2 | 86 | fun closeStream s = HTMLDev.done (SM.getDevice s) |
3196000d AC |
87 | |
88 | end | |
9b7ee2b2 AC |
89 | |
90 | structure HtmlPrint = PrintFn(HtmlPrintArg) |