author | wenzelm |
Mon, 07 Jun 2010 11:42:32 +0200 | |
changeset 37352 | c4f393759c59 |
parent 37195 | e87d305a4490 |
child 38229 | 61d0fe8b96ac |
permissions | -rw-r--r-- |
23623 | 1 |
(* Title: Pure/General/markup.ML |
2 |
Author: Makarius |
|
3 |
||
4 |
Common markup elements. |
|
5 |
*) |
|
6 |
||
7 |
signature MARKUP = |
|
8 |
sig |
|
28017 | 9 |
type T = string * Properties.T |
23704 | 10 |
val none: T |
27883 | 11 |
val is_none: T -> bool |
23704 | 12 |
val properties: (string * string) list -> T -> T |
23623 | 13 |
val nameN: string |
27818 | 14 |
val name: string -> T -> T |
30221 | 15 |
val bindingN: string val binding: string -> T |
23658 | 16 |
val kindN: string |
33088
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
17 |
val entityN: string val entity: string -> T |
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
18 |
val defN: string |
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
19 |
val refN: string |
23671 | 20 |
val lineN: string |
26001 | 21 |
val columnN: string |
27794 | 22 |
val offsetN: string |
27735 | 23 |
val end_lineN: string |
24 |
val end_columnN: string |
|
27794 | 25 |
val end_offsetN: string |
23671 | 26 |
val fileN: string |
30221 | 27 |
val idN: string |
27748 | 28 |
val position_properties': string list |
26051 | 29 |
val position_properties: string list |
23671 | 30 |
val positionN: string val position: T |
26255 | 31 |
val locationN: string val location: T |
23644 | 32 |
val indentN: string |
23704 | 33 |
val blockN: string val block: int -> T |
23695 | 34 |
val widthN: string |
23644 | 35 |
val breakN: string val break: int -> T |
36 |
val fbreakN: string val fbreak: T |
|
33985 | 37 |
val hiddenN: string val hidden: 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 |
|
30614 | 65 |
val ML_keywordN: string val ML_keyword: T |
37195 | 66 |
val ML_delimiterN: string val ML_delimiter: T |
30614 | 67 |
val ML_identN: string val ML_ident: T |
68 |
val ML_tvarN: string val ML_tvar: T |
|
69 |
val ML_numeralN: string val ML_numeral: T |
|
70 |
val ML_charN: string val ML_char: T |
|
71 |
val ML_stringN: string val ML_string: T |
|
72 |
val ML_commentN: string val ML_comment: T |
|
73 |
val ML_malformedN: string val ML_malformed: T |
|
30702 | 74 |
val ML_defN: string val ML_def: T |
31472 | 75 |
val ML_openN: string val ML_open: T |
76 |
val ML_structN: string val ML_struct: T |
|
30702 | 77 |
val ML_refN: string val ML_ref: T |
78 |
val ML_typingN: string val ML_typing: T |
|
27875 | 79 |
val ML_sourceN: string val ML_source: T |
80 |
val doc_sourceN: string val doc_source: T |
|
27879 | 81 |
val antiqN: string val antiq: T |
27894 | 82 |
val ML_antiqN: string val ML_antiq: string -> T |
83 |
val doc_antiqN: string val doc_antiq: string -> T |
|
27836 | 84 |
val keyword_declN: string val keyword_decl: string -> T |
85 |
val command_declN: string val command_decl: string -> string -> T |
|
37193 | 86 |
val keywordN: string val keyword: T |
37192 | 87 |
val operatorN: string val operator: T |
37193 | 88 |
val commandN: string val command: T |
27836 | 89 |
val identN: string val ident: T |
23719 | 90 |
val stringN: string val string: T |
91 |
val altstringN: string val altstring: T |
|
92 |
val verbatimN: string val verbatim: T |
|
93 |
val commentN: string val comment: T |
|
94 |
val controlN: string val control: T |
|
95 |
val malformedN: string val malformed: T |
|
27851 | 96 |
val tokenN: string val token: T |
27660 | 97 |
val command_spanN: string val command_span: string -> T |
98 |
val ignored_spanN: string val ignored_span: T |
|
27836 | 99 |
val malformed_spanN: string val malformed_span: T |
23637 | 100 |
val stateN: string val state: T |
101 |
val subgoalN: string val subgoal: T |
|
24289 | 102 |
val sendbackN: string val sendback: T |
24555 | 103 |
val hiliteN: string val hilite: T |
29417 | 104 |
val taskN: string |
27606 | 105 |
val unprocessedN: string val unprocessed: T |
29417 | 106 |
val runningN: string val running: string -> T |
37186
349e9223c685
explicit markup for forked goals, as indicated by Goal.fork;
wenzelm
parents:
34242
diff
changeset
|
107 |
val forkedN: string val forked: T |
349e9223c685
explicit markup for forked goals, as indicated by Goal.fork;
wenzelm
parents:
34242
diff
changeset
|
108 |
val joinedN: string val joined: T |
27615 | 109 |
val failedN: string val failed: T |
27606 | 110 |
val finishedN: string val finished: T |
111 |
val disposedN: string val disposed: T |
|
34242
5ccdc8bf3849
explicit markup of document assigment message (simplified variant of earlier "edits" 8c3e1f73953d);
wenzelm
parents:
34214
diff
changeset
|
112 |
val assignN: string val assign: T |
29488 | 113 |
val editN: string val edit: string -> string -> T |
27969 | 114 |
val pidN: string |
115 |
val promptN: string val prompt: T |
|
31384
ce169bd37fc0
IsabelleProcess: emit status "ready" after initialization and reports;
wenzelm
parents:
30702
diff
changeset
|
116 |
val readyN: string val ready: T |
29325 | 117 |
val no_output: output * output |
23704 | 118 |
val default_output: T -> output * output |
23786 | 119 |
val add_mode: string -> (T -> output * output) -> unit |
23704 | 120 |
val output: T -> output * output |
23719 | 121 |
val enclose: T -> output -> output |
25552 | 122 |
val markup: T -> string -> string |
23623 | 123 |
end; |
124 |
||
125 |
structure Markup: MARKUP = |
|
126 |
struct |
|
127 |
||
30221 | 128 |
(** markup elements **) |
129 |
||
23658 | 130 |
(* basic markup *) |
23623 | 131 |
|
28017 | 132 |
type T = string * Properties.T; |
23637 | 133 |
|
134 |
val none = ("", []); |
|
135 |
||
27883 | 136 |
fun is_none ("", _) = true |
137 |
| is_none _ = false; |
|
138 |
||
23794 | 139 |
|
23671 | 140 |
fun properties more_props ((elem, props): T) = |
28017 | 141 |
(elem, fold_rev Properties.put more_props props); |
23671 | 142 |
|
25552 | 143 |
fun markup_elem elem = (elem, (elem, []): T); |
23794 | 144 |
fun markup_string elem prop = (elem, fn s => (elem, [(prop, s)]): T); |
145 |
fun markup_int elem prop = (elem, fn i => (elem, [(prop, Int.toString i)]): T); |
|
146 |
||
26977 | 147 |
|
148 |
(* name *) |
|
149 |
||
23658 | 150 |
val nameN = "name"; |
27818 | 151 |
fun name a = properties [(nameN, a)]; |
152 |
||
30221 | 153 |
val (bindingN, binding) = markup_string "binding" nameN; |
154 |
||
24777 | 155 |
|
156 |
(* kind *) |
|
157 |
||
23658 | 158 |
val kindN = "kind"; |
23671 | 159 |
|
23658 | 160 |
|
33088
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
161 |
(* formal entities *) |
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
162 |
|
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
163 |
val (entityN, entity) = markup_string "entity" nameN; |
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
164 |
|
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
165 |
val defN = "def"; |
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
166 |
val refN = "ref"; |
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
167 |
|
757d7787b10c
markup for formal entities, with "def" or "ref" occurrences;
wenzelm
parents:
32738
diff
changeset
|
168 |
|
23671 | 169 |
(* position *) |
170 |
||
171 |
val lineN = "line"; |
|
26001 | 172 |
val columnN = "column"; |
27794 | 173 |
val offsetN = "offset"; |
27735 | 174 |
val end_lineN = "end_line"; |
175 |
val end_columnN = "end_column"; |
|
27794 | 176 |
val end_offsetN = "end_offset"; |
23671 | 177 |
val fileN = "file"; |
25816 | 178 |
val idN = "id"; |
23671 | 179 |
|
27794 | 180 |
val position_properties' = [end_lineN, end_columnN, end_offsetN, fileN, idN]; |
181 |
val position_properties = [lineN, columnN, offsetN] @ position_properties'; |
|
27748 | 182 |
|
25552 | 183 |
val (positionN, position) = markup_elem "position"; |
26255 | 184 |
val (locationN, location) = markup_elem "location"; |
185 |
||
23644 | 186 |
|
187 |
(* pretty printing *) |
|
188 |
||
189 |
val indentN = "indent"; |
|
190 |
val (blockN, block) = markup_int "block" indentN; |
|
191 |
||
192 |
val widthN = "width"; |
|
193 |
val (breakN, break) = markup_int "break" widthN; |
|
194 |
||
25552 | 195 |
val (fbreakN, fbreak) = markup_elem "fbreak"; |
23637 | 196 |
|
197 |
||
33985 | 198 |
(* hidden text *) |
199 |
||
200 |
val (hiddenN, hidden) = markup_elem "hidden"; |
|
201 |
||
202 |
||
23623 | 203 |
(* logical entities *) |
204 |
||
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
|
205 |
val (tclassN, tclass) = markup_string "tclass" nameN; |
23658 | 206 |
val (tyconN, tycon) = markup_string "tycon" nameN; |
28077 | 207 |
val (fixed_declN, fixed_decl) = markup_string "fixed_decl" nameN; |
26702
a079f8f0080b
added markup for fixed variables (local constants);
wenzelm
parents:
26255
diff
changeset
|
208 |
val (fixedN, fixed) = markup_string "fixed" nameN; |
28113 | 209 |
val (const_declN, const_decl) = markup_string "const_decl" nameN; |
23658 | 210 |
val (constN, const) = markup_string "const" nameN; |
28077 | 211 |
val (fact_declN, fact_decl) = markup_string "fact_decl" nameN; |
27740 | 212 |
val (factN, fact) = markup_string "fact" nameN; |
213 |
val (dynamic_factN, dynamic_fact) = markup_string "dynamic_fact" nameN; |
|
28077 | 214 |
val (local_fact_declN, local_fact_decl) = markup_string "local_fact_decl" nameN; |
27818 | 215 |
val (local_factN, local_fact) = markup_string "local_fact" nameN; |
23623 | 216 |
|
217 |
||
218 |
(* inner syntax *) |
|
219 |
||
25552 | 220 |
val (tfreeN, tfree) = markup_elem "tfree"; |
221 |
val (tvarN, tvar) = markup_elem "tvar"; |
|
222 |
val (freeN, free) = markup_elem "free"; |
|
223 |
val (skolemN, skolem) = markup_elem "skolem"; |
|
224 |
val (boundN, bound) = markup_elem "bound"; |
|
225 |
val (varN, var) = markup_elem "var"; |
|
29318
6337d1cb2ba0
added numeral, which supercedes num, xnum, float;
wenzelm
parents:
28904
diff
changeset
|
226 |
val (numeralN, numeral) = markup_elem "numeral"; |
27804 | 227 |
val (literalN, literal) = markup_elem "literal"; |
29318
6337d1cb2ba0
added numeral, which supercedes num, xnum, float;
wenzelm
parents:
28904
diff
changeset
|
228 |
val (inner_stringN, inner_string) = markup_elem "inner_string"; |
27883 | 229 |
val (inner_commentN, inner_comment) = markup_elem "inner_comment"; |
23719 | 230 |
|
25552 | 231 |
val (sortN, sort) = markup_elem "sort"; |
232 |
val (typN, typ) = markup_elem "typ"; |
|
233 |
val (termN, term) = markup_elem "term"; |
|
27818 | 234 |
val (propN, prop) = markup_elem "prop"; |
27748 | 235 |
|
236 |
val (attributeN, attribute) = markup_string "attribute" nameN; |
|
237 |
val (methodN, method) = markup_string "method" nameN; |
|
23623 | 238 |
|
239 |
||
30614 | 240 |
(* ML syntax *) |
241 |
||
242 |
val (ML_keywordN, ML_keyword) = markup_elem "ML_keyword"; |
|
37195 | 243 |
val (ML_delimiterN, ML_delimiter) = markup_elem "ML_delimiter"; |
30614 | 244 |
val (ML_identN, ML_ident) = markup_elem "ML_ident"; |
245 |
val (ML_tvarN, ML_tvar) = markup_elem "ML_tvar"; |
|
246 |
val (ML_numeralN, ML_numeral) = markup_elem "ML_numeral"; |
|
247 |
val (ML_charN, ML_char) = markup_elem "ML_char"; |
|
248 |
val (ML_stringN, ML_string) = markup_elem "ML_string"; |
|
249 |
val (ML_commentN, ML_comment) = markup_elem "ML_comment"; |
|
250 |
val (ML_malformedN, ML_malformed) = markup_elem "ML_malformed"; |
|
251 |
||
30702 | 252 |
val (ML_defN, ML_def) = markup_elem "ML_def"; |
31472 | 253 |
val (ML_openN, ML_open) = markup_elem "ML_open"; |
254 |
val (ML_structN, ML_struct) = markup_elem "ML_struct"; |
|
30702 | 255 |
val (ML_refN, ML_ref) = markup_elem "ML_ref"; |
256 |
val (ML_typingN, ML_typing) = markup_elem "ML_typing"; |
|
257 |
||
30614 | 258 |
|
27875 | 259 |
(* embedded source text *) |
260 |
||
261 |
val (ML_sourceN, ML_source) = markup_elem "ML_source"; |
|
262 |
val (doc_sourceN, doc_source) = markup_elem "doc_source"; |
|
263 |
||
27879 | 264 |
val (antiqN, antiq) = markup_elem "antiq"; |
27894 | 265 |
val (ML_antiqN, ML_antiq) = markup_string "ML_antiq" nameN; |
266 |
val (doc_antiqN, doc_antiq) = markup_string "doc_antiq" nameN; |
|
27879 | 267 |
|
27875 | 268 |
|
23623 | 269 |
(* outer syntax *) |
270 |
||
24870 | 271 |
val (keyword_declN, keyword_decl) = markup_string "keyword_decl" nameN; |
272 |
||
273 |
val command_declN = "command_decl"; |
|
274 |
fun command_decl name kind : T = (command_declN, [(nameN, name), (kindN, kind)]); |
|
275 |
||
37193 | 276 |
val (keywordN, keyword) = markup_elem "keyword"; |
37192 | 277 |
val (operatorN, operator) = markup_elem "operator"; |
37193 | 278 |
val (commandN, command) = markup_elem "command"; |
27836 | 279 |
val (identN, ident) = markup_elem "ident"; |
25552 | 280 |
val (stringN, string) = markup_elem "string"; |
281 |
val (altstringN, altstring) = markup_elem "altstring"; |
|
282 |
val (verbatimN, verbatim) = markup_elem "verbatim"; |
|
283 |
val (commentN, comment) = markup_elem "comment"; |
|
284 |
val (controlN, control) = markup_elem "control"; |
|
285 |
val (malformedN, malformed) = markup_elem "malformed"; |
|
23719 | 286 |
|
27851 | 287 |
val (tokenN, token) = markup_elem "token"; |
288 |
||
27660 | 289 |
val (command_spanN, command_span) = markup_string "command_span" nameN; |
290 |
val (ignored_spanN, ignored_span) = markup_elem "ignored_span"; |
|
27836 | 291 |
val (malformed_spanN, malformed_span) = markup_elem "malformed_span"; |
23719 | 292 |
|
23623 | 293 |
|
23637 | 294 |
(* toplevel *) |
295 |
||
25552 | 296 |
val (stateN, state) = markup_elem "state"; |
297 |
val (subgoalN, subgoal) = markup_elem "subgoal"; |
|
298 |
val (sendbackN, sendback) = markup_elem "sendback"; |
|
299 |
val (hiliteN, hilite) = markup_elem "hilite"; |
|
300 |
||
301 |
||
27606 | 302 |
(* command status *) |
303 |
||
29417 | 304 |
val taskN = "task"; |
305 |
||
27606 | 306 |
val (unprocessedN, unprocessed) = markup_elem "unprocessed"; |
29417 | 307 |
val (runningN, running) = markup_string "running" taskN; |
37186
349e9223c685
explicit markup for forked goals, as indicated by Goal.fork;
wenzelm
parents:
34242
diff
changeset
|
308 |
val (forkedN, forked) = markup_elem "forked"; |
349e9223c685
explicit markup for forked goals, as indicated by Goal.fork;
wenzelm
parents:
34242
diff
changeset
|
309 |
val (joinedN, joined) = markup_elem "joined"; |
27615 | 310 |
val (failedN, failed) = markup_elem "failed"; |
27606 | 311 |
val (finishedN, finished) = markup_elem "finished"; |
312 |
val (disposedN, disposed) = markup_elem "disposed"; |
|
313 |
||
29488 | 314 |
|
315 |
(* interactive documents *) |
|
316 |
||
34242
5ccdc8bf3849
explicit markup of document assigment message (simplified variant of earlier "edits" 8c3e1f73953d);
wenzelm
parents:
34214
diff
changeset
|
317 |
val (assignN, assign) = markup_elem "assign"; |
5ccdc8bf3849
explicit markup of document assigment message (simplified variant of earlier "edits" 8c3e1f73953d);
wenzelm
parents:
34214
diff
changeset
|
318 |
|
29488 | 319 |
val editN = "edit"; |
320 |
fun edit id state_id : T = (editN, [(idN, id), (stateN, state_id)]); |
|
29482 | 321 |
|
27606 | 322 |
|
27969 | 323 |
(* messages *) |
324 |
||
325 |
val pidN = "pid"; |
|
326 |
||
327 |
val (promptN, prompt) = markup_elem "prompt"; |
|
31384
ce169bd37fc0
IsabelleProcess: emit status "ready" after initialization and reports;
wenzelm
parents:
30702
diff
changeset
|
328 |
val (readyN, ready) = markup_elem "ready"; |
27969 | 329 |
|
330 |
||
331 |
||
30221 | 332 |
(** print mode operations **) |
23704 | 333 |
|
29325 | 334 |
val no_output = ("", ""); |
335 |
fun default_output (_: T) = no_output; |
|
23704 | 336 |
|
337 |
local |
|
338 |
val default = {output = default_output}; |
|
32738 | 339 |
val modes = Unsynchronized.ref (Symtab.make [("", default)]); |
23704 | 340 |
in |
23922
707639e9497d
marked some CRITICAL sections (for multithreading);
wenzelm
parents:
23794
diff
changeset
|
341 |
fun add_mode name output = CRITICAL (fn () => |
32738 | 342 |
Unsynchronized.change modes (Symtab.update_new (name, {output = output}))); |
23704 | 343 |
fun get_mode () = |
24612 | 344 |
the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ())); |
23623 | 345 |
end; |
23704 | 346 |
|
29325 | 347 |
fun output m = if is_none m then no_output else #output (get_mode ()) m; |
23704 | 348 |
|
23719 | 349 |
val enclose = output #-> Library.enclose; |
350 |
||
25552 | 351 |
fun markup m = |
352 |
let val (bg, en) = output m |
|
353 |
in Library.enclose (Output.escape bg) (Output.escape en) end; |
|
354 |
||
23704 | 355 |
end; |