author | wenzelm |
Fri, 02 Jan 2009 19:38:13 +0100 | |
changeset 29318 | 6337d1cb2ba0 |
parent 28904 | 3ef9489eeef5 |
child 29325 | a205acc94356 |
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 |
|
28017 | 10 |
type T = string * Properties.T |
23704 | 11 |
val none: T |
27883 | 12 |
val is_none: T -> bool |
23704 | 13 |
val properties: (string * string) list -> T -> T |
23623 | 14 |
val nameN: string |
27818 | 15 |
val name: string -> T -> T |
25982 | 16 |
val groupN: string |
26977 | 17 |
val theory_nameN: string |
25808 | 18 |
val idN: string |
23658 | 19 |
val kindN: string |
24777 | 20 |
val internalK: string |
28017 | 21 |
val property_internal: Properties.property |
23671 | 22 |
val lineN: string |
26001 | 23 |
val columnN: string |
27794 | 24 |
val offsetN: string |
27735 | 25 |
val end_lineN: string |
26 |
val end_columnN: string |
|
27794 | 27 |
val end_offsetN: string |
23671 | 28 |
val fileN: string |
27748 | 29 |
val position_properties': string list |
26051 | 30 |
val position_properties: string list |
23671 | 31 |
val positionN: string val position: T |
26255 | 32 |
val locationN: string val location: T |
23644 | 33 |
val indentN: string |
23704 | 34 |
val blockN: string val block: int -> T |
23695 | 35 |
val widthN: string |
23644 | 36 |
val breakN: string val break: int -> T |
37 |
val fbreakN: string val fbreak: T |
|
27828
edafacb690a3
renamed Markup.class to Markup.tclass, to avoid potential conflicts with spacial meaning in markup languages (e.g. HTML);
wenzelm
parents:
27818
diff
changeset
|
38 |
val tclassN: string val tclass: string -> T |
23637 | 39 |
val tyconN: string val tycon: string -> T |
28077 | 40 |
val fixed_declN: string val fixed_decl: string -> T |
26702
a079f8f0080b
added markup for fixed variables (local constants);
wenzelm
parents:
26255
diff
changeset
|
41 |
val fixedN: string val fixed: string -> T |
28113 | 42 |
val const_declN: string val const_decl: string -> T |
23637 | 43 |
val constN: string val const: string -> T |
28077 | 44 |
val fact_declN: string val fact_decl: string -> T |
27740 | 45 |
val factN: string val fact: string -> T |
46 |
val dynamic_factN: string val dynamic_fact: string -> T |
|
28077 | 47 |
val local_fact_declN: string val local_fact_decl: string -> T |
27818 | 48 |
val local_factN: string val local_fact: string -> T |
23719 | 49 |
val tfreeN: string val tfree: T |
50 |
val tvarN: string val tvar: T |
|
51 |
val freeN: string val free: T |
|
52 |
val skolemN: string val skolem: T |
|
53 |
val boundN: string val bound: T |
|
54 |
val varN: string val var: T |
|
29318
6337d1cb2ba0
added numeral, which supercedes num, xnum, float;
wenzelm
parents:
28904
diff
changeset
|
55 |
val numeralN: string val numeral: T |
27804 | 56 |
val literalN: string val literal: T |
29318
6337d1cb2ba0
added numeral, which supercedes num, xnum, float;
wenzelm
parents:
28904
diff
changeset
|
57 |
val inner_stringN: string val inner_string: T |
27883 | 58 |
val inner_commentN: string val inner_comment: T |
23637 | 59 |
val sortN: string val sort: T |
60 |
val typN: string val typ: T |
|
61 |
val termN: string val term: T |
|
27818 | 62 |
val propN: string val prop: T |
27748 | 63 |
val attributeN: string val attribute: string -> T |
64 |
val methodN: string val method: string -> T |
|
27875 | 65 |
val ML_sourceN: string val ML_source: T |
66 |
val doc_sourceN: string val doc_source: T |
|
27879 | 67 |
val antiqN: string val antiq: T |
27894 | 68 |
val ML_antiqN: string val ML_antiq: string -> T |
69 |
val doc_antiqN: string val doc_antiq: string -> T |
|
27836 | 70 |
val keyword_declN: string val keyword_decl: string -> T |
71 |
val command_declN: string val command_decl: string -> string -> T |
|
23637 | 72 |
val keywordN: string val keyword: string -> T |
73 |
val commandN: string val command: string -> T |
|
27836 | 74 |
val identN: string val ident: T |
23719 | 75 |
val stringN: string val string: T |
76 |
val altstringN: string val altstring: T |
|
77 |
val verbatimN: string val verbatim: T |
|
78 |
val commentN: string val comment: T |
|
79 |
val controlN: string val control: T |
|
80 |
val malformedN: string val malformed: T |
|
27851 | 81 |
val tokenN: string val token: T |
27660 | 82 |
val command_spanN: string val command_span: string -> T |
83 |
val ignored_spanN: string val ignored_span: T |
|
27836 | 84 |
val malformed_spanN: string val malformed_span: T |
23637 | 85 |
val stateN: string val state: T |
86 |
val subgoalN: string val subgoal: T |
|
24289 | 87 |
val sendbackN: string val sendback: T |
24555 | 88 |
val hiliteN: string val hilite: T |
27606 | 89 |
val unprocessedN: string val unprocessed: T |
90 |
val runningN: string val running: T |
|
27615 | 91 |
val failedN: string val failed: T |
27606 | 92 |
val finishedN: string val finished: T |
93 |
val disposedN: string val disposed: T |
|
27969 | 94 |
val pidN: string |
95 |
val sessionN: string |
|
96 |
val classN: string |
|
97 |
val messageN: string val message: string -> T |
|
98 |
val promptN: string val prompt: T |
|
99 |
val writelnN: string |
|
100 |
val priorityN: string |
|
101 |
val tracingN: string |
|
102 |
val warningN: string |
|
103 |
val errorN: string |
|
104 |
val debugN: string |
|
105 |
val initN: string |
|
106 |
val statusN: string |
|
23704 | 107 |
val default_output: T -> output * output |
23786 | 108 |
val add_mode: string -> (T -> output * output) -> unit |
23704 | 109 |
val output: T -> output * output |
23719 | 110 |
val enclose: T -> output -> output |
25552 | 111 |
val markup: T -> string -> string |
23623 | 112 |
end; |
113 |
||
114 |
structure Markup: MARKUP = |
|
115 |
struct |
|
116 |
||
23658 | 117 |
(* basic markup *) |
23623 | 118 |
|
28017 | 119 |
type T = string * Properties.T; |
23637 | 120 |
|
121 |
val none = ("", []); |
|
122 |
||
27883 | 123 |
fun is_none ("", _) = true |
124 |
| is_none _ = false; |
|
125 |
||
23794 | 126 |
|
23671 | 127 |
fun properties more_props ((elem, props): T) = |
28017 | 128 |
(elem, fold_rev Properties.put more_props props); |
23671 | 129 |
|
25552 | 130 |
fun markup_elem elem = (elem, (elem, []): T); |
23794 | 131 |
fun markup_string elem prop = (elem, fn s => (elem, [(prop, s)]): T); |
132 |
fun markup_int elem prop = (elem, fn i => (elem, [(prop, Int.toString i)]): T); |
|
133 |
||
26977 | 134 |
|
135 |
(* name *) |
|
136 |
||
23658 | 137 |
val nameN = "name"; |
27818 | 138 |
fun name a = properties [(nameN, a)]; |
139 |
||
25982 | 140 |
val groupN = "group"; |
26977 | 141 |
val theory_nameN = "theory_name"; |
24777 | 142 |
|
143 |
||
144 |
(* kind *) |
|
145 |
||
23658 | 146 |
val kindN = "kind"; |
23671 | 147 |
|
24777 | 148 |
val internalK = "internal"; |
149 |
val property_internal = (kindN, internalK); |
|
150 |
||
23658 | 151 |
|
23671 | 152 |
(* position *) |
153 |
||
154 |
val lineN = "line"; |
|
26001 | 155 |
val columnN = "column"; |
27794 | 156 |
val offsetN = "offset"; |
27735 | 157 |
val end_lineN = "end_line"; |
158 |
val end_columnN = "end_column"; |
|
27794 | 159 |
val end_offsetN = "end_offset"; |
23671 | 160 |
val fileN = "file"; |
25816 | 161 |
val idN = "id"; |
23671 | 162 |
|
27794 | 163 |
val position_properties' = [end_lineN, end_columnN, end_offsetN, fileN, idN]; |
164 |
val position_properties = [lineN, columnN, offsetN] @ position_properties'; |
|
27748 | 165 |
|
25552 | 166 |
val (positionN, position) = markup_elem "position"; |
26255 | 167 |
val (locationN, location) = markup_elem "location"; |
168 |
||
23644 | 169 |
|
170 |
(* pretty printing *) |
|
171 |
||
172 |
val indentN = "indent"; |
|
173 |
val (blockN, block) = markup_int "block" indentN; |
|
174 |
||
175 |
val widthN = "width"; |
|
176 |
val (breakN, break) = markup_int "break" widthN; |
|
177 |
||
25552 | 178 |
val (fbreakN, fbreak) = markup_elem "fbreak"; |
23637 | 179 |
|
180 |
||
23623 | 181 |
(* logical entities *) |
182 |
||
27828
edafacb690a3
renamed Markup.class to Markup.tclass, to avoid potential conflicts with spacial meaning in markup languages (e.g. HTML);
wenzelm
parents:
27818
diff
changeset
|
183 |
val (tclassN, tclass) = markup_string "tclass" nameN; |
23658 | 184 |
val (tyconN, tycon) = markup_string "tycon" nameN; |
28077 | 185 |
val (fixed_declN, fixed_decl) = markup_string "fixed_decl" nameN; |
26702
a079f8f0080b
added markup for fixed variables (local constants);
wenzelm
parents:
26255
diff
changeset
|
186 |
val (fixedN, fixed) = markup_string "fixed" nameN; |
28113 | 187 |
val (const_declN, const_decl) = markup_string "const_decl" nameN; |
23658 | 188 |
val (constN, const) = markup_string "const" nameN; |
28077 | 189 |
val (fact_declN, fact_decl) = markup_string "fact_decl" nameN; |
27740 | 190 |
val (factN, fact) = markup_string "fact" nameN; |
191 |
val (dynamic_factN, dynamic_fact) = markup_string "dynamic_fact" nameN; |
|
28077 | 192 |
val (local_fact_declN, local_fact_decl) = markup_string "local_fact_decl" nameN; |
27818 | 193 |
val (local_factN, local_fact) = markup_string "local_fact" nameN; |
23623 | 194 |
|
195 |
||
196 |
(* inner syntax *) |
|
197 |
||
25552 | 198 |
val (tfreeN, tfree) = markup_elem "tfree"; |
199 |
val (tvarN, tvar) = markup_elem "tvar"; |
|
200 |
val (freeN, free) = markup_elem "free"; |
|
201 |
val (skolemN, skolem) = markup_elem "skolem"; |
|
202 |
val (boundN, bound) = markup_elem "bound"; |
|
203 |
val (varN, var) = markup_elem "var"; |
|
29318
6337d1cb2ba0
added numeral, which supercedes num, xnum, float;
wenzelm
parents:
28904
diff
changeset
|
204 |
val (numeralN, numeral) = markup_elem "numeral"; |
27804 | 205 |
val (literalN, literal) = markup_elem "literal"; |
29318
6337d1cb2ba0
added numeral, which supercedes num, xnum, float;
wenzelm
parents:
28904
diff
changeset
|
206 |
val (inner_stringN, inner_string) = markup_elem "inner_string"; |
27883 | 207 |
val (inner_commentN, inner_comment) = markup_elem "inner_comment"; |
23719 | 208 |
|
25552 | 209 |
val (sortN, sort) = markup_elem "sort"; |
210 |
val (typN, typ) = markup_elem "typ"; |
|
211 |
val (termN, term) = markup_elem "term"; |
|
27818 | 212 |
val (propN, prop) = markup_elem "prop"; |
27748 | 213 |
|
214 |
val (attributeN, attribute) = markup_string "attribute" nameN; |
|
215 |
val (methodN, method) = markup_string "method" nameN; |
|
23623 | 216 |
|
217 |
||
27875 | 218 |
(* embedded source text *) |
219 |
||
220 |
val (ML_sourceN, ML_source) = markup_elem "ML_source"; |
|
221 |
val (doc_sourceN, doc_source) = markup_elem "doc_source"; |
|
222 |
||
27879 | 223 |
val (antiqN, antiq) = markup_elem "antiq"; |
27894 | 224 |
val (ML_antiqN, ML_antiq) = markup_string "ML_antiq" nameN; |
225 |
val (doc_antiqN, doc_antiq) = markup_string "doc_antiq" nameN; |
|
27879 | 226 |
|
27875 | 227 |
|
23623 | 228 |
(* outer syntax *) |
229 |
||
24870 | 230 |
val (keyword_declN, keyword_decl) = markup_string "keyword_decl" nameN; |
231 |
||
232 |
val command_declN = "command_decl"; |
|
233 |
fun command_decl name kind : T = (command_declN, [(nameN, name), (kindN, kind)]); |
|
234 |
||
27836 | 235 |
val (keywordN, keyword) = markup_string "keyword" nameN; |
236 |
val (commandN, command) = markup_string "command" nameN; |
|
237 |
val (identN, ident) = markup_elem "ident"; |
|
25552 | 238 |
val (stringN, string) = markup_elem "string"; |
239 |
val (altstringN, altstring) = markup_elem "altstring"; |
|
240 |
val (verbatimN, verbatim) = markup_elem "verbatim"; |
|
241 |
val (commentN, comment) = markup_elem "comment"; |
|
242 |
val (controlN, control) = markup_elem "control"; |
|
243 |
val (malformedN, malformed) = markup_elem "malformed"; |
|
23719 | 244 |
|
27851 | 245 |
val (tokenN, token) = markup_elem "token"; |
246 |
||
27660 | 247 |
val (command_spanN, command_span) = markup_string "command_span" nameN; |
248 |
val (ignored_spanN, ignored_span) = markup_elem "ignored_span"; |
|
27836 | 249 |
val (malformed_spanN, malformed_span) = markup_elem "malformed_span"; |
23719 | 250 |
|
23623 | 251 |
|
23637 | 252 |
(* toplevel *) |
253 |
||
25552 | 254 |
val (stateN, state) = markup_elem "state"; |
255 |
val (subgoalN, subgoal) = markup_elem "subgoal"; |
|
256 |
val (sendbackN, sendback) = markup_elem "sendback"; |
|
257 |
val (hiliteN, hilite) = markup_elem "hilite"; |
|
258 |
||
259 |
||
27606 | 260 |
(* command status *) |
261 |
||
262 |
val (unprocessedN, unprocessed) = markup_elem "unprocessed"; |
|
263 |
val (runningN, running) = markup_elem "running"; |
|
27615 | 264 |
val (failedN, failed) = markup_elem "failed"; |
27606 | 265 |
val (finishedN, finished) = markup_elem "finished"; |
266 |
val (disposedN, disposed) = markup_elem "disposed"; |
|
267 |
||
268 |
||
27969 | 269 |
(* messages *) |
270 |
||
271 |
val pidN = "pid"; |
|
272 |
val sessionN = "session"; |
|
273 |
||
274 |
val classN = "class"; |
|
275 |
val (messageN, message) = markup_string "message" classN; |
|
276 |
||
277 |
val (promptN, prompt) = markup_elem "prompt"; |
|
278 |
||
279 |
val writelnN = "writeln"; |
|
280 |
val priorityN = "priority"; |
|
281 |
val tracingN = "tracing"; |
|
282 |
val warningN = "warning"; |
|
283 |
val errorN = "error"; |
|
284 |
val debugN = "debug"; |
|
285 |
val initN = "init"; |
|
286 |
val statusN = "status"; |
|
287 |
||
288 |
||
23704 | 289 |
(* print mode operations *) |
290 |
||
291 |
fun default_output (_: T) = ("", ""); |
|
292 |
||
293 |
local |
|
294 |
val default = {output = default_output}; |
|
295 |
val modes = ref (Symtab.make [("", default)]); |
|
296 |
in |
|
23922
707639e9497d
marked some CRITICAL sections (for multithreading);
wenzelm
parents:
23794
diff
changeset
|
297 |
fun add_mode name output = CRITICAL (fn () => |
707639e9497d
marked some CRITICAL sections (for multithreading);
wenzelm
parents:
23794
diff
changeset
|
298 |
change modes (Symtab.update_new (name, {output = output}))); |
23704 | 299 |
fun get_mode () = |
24612 | 300 |
the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ())); |
23623 | 301 |
end; |
23704 | 302 |
|
27883 | 303 |
fun output m = if is_none m then ("", "") else #output (get_mode ()) m; |
23704 | 304 |
|
23719 | 305 |
val enclose = output #-> Library.enclose; |
306 |
||
25552 | 307 |
fun markup m = |
308 |
let val (bg, en) = output m |
|
309 |
in Library.enclose (Output.escape bg) (Output.escape en) end; |
|
310 |
||
23704 | 311 |
end; |