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