author | wenzelm |
Fri, 28 Mar 2008 22:39:42 +0100 | |
changeset 26471 | f4c956461353 |
parent 26255 | 2246d8bbe89d |
child 26702 | a079f8f0080b |
permissions | -rw-r--r-- |
23623 | 1 |
(* Title: Pure/General/markup.ML |
2 |
ID: $Id$ |
|
3 |
Author: Makarius |
|
4 |
||
5 |
Common markup elements. |
|
6 |
*) |
|
7 |
||
8 |
signature MARKUP = |
|
9 |
sig |
|
10 |
type property = string * string |
|
23658 | 11 |
type T = string * property list |
23794 | 12 |
val get_string: T -> string -> string option |
13 |
val get_int: T -> string -> int option |
|
23704 | 14 |
val none: T |
15 |
val properties: (string * string) list -> T -> T |
|
23623 | 16 |
val nameN: string |
25982 | 17 |
val groupN: string |
25808 | 18 |
val idN: string |
23658 | 19 |
val kindN: string |
24777 | 20 |
val internalK: string |
21 |
val property_internal: property |
|
23671 | 22 |
val lineN: string |
26001 | 23 |
val columnN: string |
23671 | 24 |
val fileN: string |
26051 | 25 |
val position_properties: string list |
23671 | 26 |
val positionN: string val position: T |
26255 | 27 |
val locationN: string val location: T |
23644 | 28 |
val indentN: string |
23704 | 29 |
val blockN: string val block: int -> T |
23695 | 30 |
val widthN: string |
23644 | 31 |
val breakN: string val break: int -> T |
32 |
val fbreakN: string val fbreak: T |
|
23637 | 33 |
val classN: string val class: string -> T |
34 |
val tyconN: string val tycon: string -> T |
|
35 |
val constN: string val const: string -> T |
|
36 |
val axiomN: string val axiom: string -> T |
|
23719 | 37 |
val tfreeN: string val tfree: T |
38 |
val tvarN: string val tvar: T |
|
39 |
val freeN: string val free: T |
|
40 |
val skolemN: string val skolem: T |
|
41 |
val boundN: string val bound: T |
|
42 |
val varN: string val var: T |
|
43 |
val numN: string val num: T |
|
44 |
val xnumN: string val xnum: T |
|
45 |
val xstrN: string val xstr: T |
|
23637 | 46 |
val sortN: string val sort: T |
47 |
val typN: string val typ: T |
|
48 |
val termN: string val term: T |
|
49 |
val keywordN: string val keyword: string -> T |
|
50 |
val commandN: string val command: string -> T |
|
24870 | 51 |
val keyword_declN: string val keyword_decl: string -> T |
52 |
val command_declN: string val command_decl: string -> string -> T |
|
23719 | 53 |
val stringN: string val string: T |
54 |
val altstringN: string val altstring: T |
|
55 |
val verbatimN: string val verbatim: T |
|
56 |
val commentN: string val comment: T |
|
57 |
val controlN: string val control: T |
|
58 |
val malformedN: string val malformed: T |
|
23786 | 59 |
val antiqN: string val antiq: T |
23719 | 60 |
val whitespaceN: string val whitespace: T |
61 |
val junkN: string val junk: T |
|
62 |
val commandspanN: string val commandspan: string -> T |
|
23637 | 63 |
val stateN: string val state: T |
64 |
val subgoalN: string val subgoal: T |
|
24289 | 65 |
val sendbackN: string val sendback: T |
24555 | 66 |
val hiliteN: string val hilite: T |
23704 | 67 |
val default_output: T -> output * output |
23786 | 68 |
val add_mode: string -> (T -> output * output) -> unit |
23704 | 69 |
val output: T -> output * output |
23719 | 70 |
val enclose: T -> output -> output |
25552 | 71 |
val markup: T -> string -> string |
23623 | 72 |
end; |
73 |
||
74 |
structure Markup: MARKUP = |
|
75 |
struct |
|
76 |
||
23658 | 77 |
(* basic markup *) |
23623 | 78 |
|
23637 | 79 |
type property = string * string; |
80 |
type T = string * property list; |
|
81 |
||
82 |
val none = ("", []); |
|
83 |
||
23794 | 84 |
|
23671 | 85 |
fun properties more_props ((elem, props): T) = |
86 |
(elem, fold_rev (AList.update (op =)) more_props props); |
|
87 |
||
23794 | 88 |
fun get_string ((_, props): T) prop = AList.lookup (op =) props prop; |
89 |
fun get_int m prop = (case get_string m prop of NONE => NONE | SOME s => Int.fromString s); |
|
90 |
||
25552 | 91 |
fun markup_elem elem = (elem, (elem, []): T); |
23794 | 92 |
fun markup_string elem prop = (elem, fn s => (elem, [(prop, s)]): T); |
93 |
fun markup_int elem prop = (elem, fn i => (elem, [(prop, Int.toString i)]): T); |
|
94 |
||
23658 | 95 |
val nameN = "name"; |
25982 | 96 |
val groupN = "group"; |
24777 | 97 |
|
98 |
||
99 |
(* kind *) |
|
100 |
||
23658 | 101 |
val kindN = "kind"; |
23671 | 102 |
|
24777 | 103 |
val internalK = "internal"; |
104 |
val property_internal = (kindN, internalK); |
|
105 |
||
23658 | 106 |
|
23671 | 107 |
(* position *) |
108 |
||
109 |
val lineN = "line"; |
|
26001 | 110 |
val columnN = "column"; |
23671 | 111 |
val fileN = "file"; |
25816 | 112 |
val idN = "id"; |
23671 | 113 |
|
26051 | 114 |
val position_properties = [lineN, columnN, fileN, idN]; |
25552 | 115 |
val (positionN, position) = markup_elem "position"; |
23644 | 116 |
|
26255 | 117 |
val (locationN, location) = markup_elem "location"; |
118 |
||
23644 | 119 |
|
120 |
(* pretty printing *) |
|
121 |
||
122 |
val indentN = "indent"; |
|
123 |
val (blockN, block) = markup_int "block" indentN; |
|
124 |
||
125 |
val widthN = "width"; |
|
126 |
val (breakN, break) = markup_int "break" widthN; |
|
127 |
||
25552 | 128 |
val (fbreakN, fbreak) = markup_elem "fbreak"; |
23637 | 129 |
|
130 |
||
23623 | 131 |
(* logical entities *) |
132 |
||
23658 | 133 |
val (classN, class) = markup_string "class" nameN; |
134 |
val (tyconN, tycon) = markup_string "tycon" nameN; |
|
135 |
val (constN, const) = markup_string "const" nameN; |
|
136 |
val (axiomN, axiom) = markup_string "axiom" nameN; |
|
23623 | 137 |
|
138 |
||
139 |
(* inner syntax *) |
|
140 |
||
25552 | 141 |
val (tfreeN, tfree) = markup_elem "tfree"; |
142 |
val (tvarN, tvar) = markup_elem "tvar"; |
|
143 |
val (freeN, free) = markup_elem "free"; |
|
144 |
val (skolemN, skolem) = markup_elem "skolem"; |
|
145 |
val (boundN, bound) = markup_elem "bound"; |
|
146 |
val (varN, var) = markup_elem "var"; |
|
147 |
val (numN, num) = markup_elem "num"; |
|
148 |
val (xnumN, xnum) = markup_elem "xnum"; |
|
149 |
val (xstrN, xstr) = markup_elem "xstr"; |
|
23719 | 150 |
|
25552 | 151 |
val (sortN, sort) = markup_elem "sort"; |
152 |
val (typN, typ) = markup_elem "typ"; |
|
153 |
val (termN, term) = markup_elem "term"; |
|
23623 | 154 |
|
155 |
||
156 |
(* outer syntax *) |
|
157 |
||
23658 | 158 |
val (keywordN, keyword) = markup_string "keyword" nameN; |
159 |
val (commandN, command) = markup_string "command" nameN; |
|
23637 | 160 |
|
24870 | 161 |
val (keyword_declN, keyword_decl) = markup_string "keyword_decl" nameN; |
162 |
||
163 |
val command_declN = "command_decl"; |
|
164 |
fun command_decl name kind : T = (command_declN, [(nameN, name), (kindN, kind)]); |
|
165 |
||
25552 | 166 |
val (stringN, string) = markup_elem "string"; |
167 |
val (altstringN, altstring) = markup_elem "altstring"; |
|
168 |
val (verbatimN, verbatim) = markup_elem "verbatim"; |
|
169 |
val (commentN, comment) = markup_elem "comment"; |
|
170 |
val (controlN, control) = markup_elem "control"; |
|
171 |
val (malformedN, malformed) = markup_elem "malformed"; |
|
23719 | 172 |
|
25552 | 173 |
val (antiqN, antiq) = markup_elem "antiq"; |
23786 | 174 |
|
25552 | 175 |
val (whitespaceN, whitespace) = markup_elem "whitespace"; |
176 |
val (junkN, junk) = markup_elem "junk"; |
|
23719 | 177 |
val (commandspanN, commandspan) = markup_string "commandspan" nameN; |
178 |
||
23623 | 179 |
|
23637 | 180 |
(* toplevel *) |
181 |
||
25552 | 182 |
val (stateN, state) = markup_elem "state"; |
183 |
val (subgoalN, subgoal) = markup_elem "subgoal"; |
|
184 |
val (sendbackN, sendback) = markup_elem "sendback"; |
|
185 |
val (hiliteN, hilite) = markup_elem "hilite"; |
|
186 |
||
187 |
||
23704 | 188 |
(* print mode operations *) |
189 |
||
190 |
fun default_output (_: T) = ("", ""); |
|
191 |
||
192 |
local |
|
193 |
val default = {output = default_output}; |
|
194 |
val modes = ref (Symtab.make [("", default)]); |
|
195 |
in |
|
23922
707639e9497d
marked some CRITICAL sections (for multithreading);
wenzelm
parents:
23794
diff
changeset
|
196 |
fun add_mode name output = CRITICAL (fn () => |
707639e9497d
marked some CRITICAL sections (for multithreading);
wenzelm
parents:
23794
diff
changeset
|
197 |
change modes (Symtab.update_new (name, {output = output}))); |
23704 | 198 |
fun get_mode () = |
24612 | 199 |
the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ())); |
23623 | 200 |
end; |
23704 | 201 |
|
23786 | 202 |
fun output ("", _) = ("", "") |
203 |
| output m = #output (get_mode ()) m; |
|
23704 | 204 |
|
23719 | 205 |
val enclose = output #-> Library.enclose; |
206 |
||
25552 | 207 |
fun markup m = |
208 |
let val (bg, en) = output m |
|
209 |
in Library.enclose (Output.escape bg) (Output.escape en) end; |
|
210 |
||
23704 | 211 |
end; |