Remove Config.{dispatcher,defaultNode}
[hcoop/domtool2.git] / src / htmlPrint.sml
CommitLineData
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
21signature HTML_PRINT_ARG = sig
22 include PRINTFN_INPUT where type rendering = HTML.text
3196000d 23
9b7ee2b2
AC
24 val setProviders : Order.providers -> unit
25end
3196000d 26
9b7ee2b2
AC
27structure HtmlPrintArg :> HTML_PRINT_ARG = struct
28
29open Ast Order
3196000d
AC
30
31structure TextToken = struct
32type token = string
33type style = HTMLDev.style
34fun string t = t
35fun style t = HTMLDev.styleTT
36fun size t = String.size t
37end
38
39structure SM = PPStreamFn(structure Token = TextToken
40 structure Device = HTMLDev)
41
42structure PD = PPDescFn(SM)
43open PD
44
3196000d
AC
45fun keyword s = style (HTMLDev.styleB, [string s])
46val punct = string
9b7ee2b2
AC
47val field = string
48val lit = string
49val ident = string
50
51val prov : providers option ref = ref NONE
52fun setProviders p = prov := SOME p
3196000d
AC
53
54fun 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
62fun 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])
66fun 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])
70fun 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
75fun anchor (s, d) = style (HTMLDev.anchor s, [d])
76fun link (s, d) = style (HTMLDev.link s, [d])
3196000d 77
9b7ee2b2
AC
78type rendering = HTML.text
79fun 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 86fun closeStream s = HTMLDev.done (SM.getDevice s)
3196000d
AC
87
88end
9b7ee2b2
AC
89
90structure HtmlPrint = PrintFn(HtmlPrintArg)