author | wenzelm |
Sat, 23 Aug 2008 23:07:38 +0200 | |
changeset 27969 | 46d7057b8614 |
parent 27894 | a06f78f917e0 |
child 28017 | 4919bd124a58 |
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 |
27883 | 15 |
val is_none: T -> bool |
23704 | 16 |
val properties: (string * string) list -> T -> T |
23623 | 17 |
val nameN: string |
27818 | 18 |
val name: string -> T -> T |
25982 | 19 |
val groupN: string |
26977 | 20 |
val theory_nameN: string |
25808 | 21 |
val idN: string |
23658 | 22 |
val kindN: string |
24777 | 23 |
val internalK: string |
24 |
val property_internal: property |
|
23671 | 25 |
val lineN: string |
26001 | 26 |
val columnN: string |
27794 | 27 |
val offsetN: string |
27735 | 28 |
val end_lineN: string |
29 |
val end_columnN: string |
|
27794 | 30 |
val end_offsetN: string |
23671 | 31 |
val fileN: string |
27748 | 32 |
val position_properties': string list |
26051 | 33 |
val position_properties: string list |
23671 | 34 |
val positionN: string val position: T |
26255 | 35 |
val locationN: string val location: T |
23644 | 36 |
val indentN: string |
23704 | 37 |
val blockN: string val block: int -> T |
23695 | 38 |
val widthN: string |
23644 | 39 |
val breakN: string val break: int -> T |
40 |
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
|
41 |
val tclassN: string val tclass: string -> T |
23637 | 42 |
val tyconN: string val tycon: string -> T |
26702
a079f8f0080b
added markup for fixed variables (local constants);
wenzelm
parents:
26255
diff
changeset
|
43 |
val fixedN: string val fixed: string -> T |
23637 | 44 |
val constN: string val const: string -> T |
27740 | 45 |
val factN: string val fact: string -> T |
46 |
val dynamic_factN: string val dynamic_fact: string -> T |
|
27818 | 47 |
val local_factN: string val local_fact: string -> T |
23719 | 48 |
val tfreeN: string val tfree: T |
49 |
val tvarN: string val tvar: T |
|
50 |
val freeN: string val free: T |
|
51 |
val skolemN: string val skolem: T |
|
52 |
val boundN: string val bound: T |
|
53 |
val varN: string val var: T |
|
54 |
val numN: string val num: T |
|
55 |
val xnumN: string val xnum: T |
|
56 |
val xstrN: string val xstr: T |
|
27804 | 57 |
val literalN: string val literal: 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 |
|
23637 | 119 |
type property = string * string; |
120 |
type T = string * property list; |
|
121 |
||
122 |
val none = ("", []); |
|
123 |
||
27883 | 124 |
fun is_none ("", _) = true |
125 |
| is_none _ = false; |
|
126 |
||
23794 | 127 |
|
23671 | 128 |
fun properties more_props ((elem, props): T) = |
129 |
(elem, fold_rev (AList.update (op =)) more_props props); |
|
130 |
||
23794 | 131 |
fun get_string ((_, props): T) prop = AList.lookup (op =) props prop; |
132 |
fun get_int m prop = (case get_string m prop of NONE => NONE | SOME s => Int.fromString s); |
|
133 |
||
25552 | 134 |
fun markup_elem elem = (elem, (elem, []): T); |
23794 | 135 |
fun markup_string elem prop = (elem, fn s => (elem, [(prop, s)]): T); |
136 |
fun markup_int elem prop = (elem, fn i => (elem, [(prop, Int.toString i)]): T); |
|
137 |
||
26977 | 138 |
|
139 |
(* name *) |
|
140 |
||
23658 | 141 |
val nameN = "name"; |
27818 | 142 |
fun name a = properties [(nameN, a)]; |
143 |
||
25982 | 144 |
val groupN = "group"; |
26977 | 145 |
val theory_nameN = "theory_name"; |
24777 | 146 |
|
147 |
||
148 |
(* kind *) |
|
149 |
||
23658 | 150 |
val kindN = "kind"; |
23671 | 151 |
|
24777 | 152 |
val internalK = "internal"; |
153 |
val property_internal = (kindN, internalK); |
|
154 |
||
23658 | 155 |
|
23671 | 156 |
(* position *) |
157 |
||
158 |
val lineN = "line"; |
|
26001 | 159 |
val columnN = "column"; |
27794 | 160 |
val offsetN = "offset"; |
27735 | 161 |
val end_lineN = "end_line"; |
162 |
val end_columnN = "end_column"; |
|
27794 | 163 |
val end_offsetN = "end_offset"; |
23671 | 164 |
val fileN = "file"; |
25816 | 165 |
val idN = "id"; |
23671 | 166 |
|
27794 | 167 |
val position_properties' = [end_lineN, end_columnN, end_offsetN, fileN, idN]; |
168 |
val position_properties = [lineN, columnN, offsetN] @ position_properties'; |
|
27748 | 169 |
|
25552 | 170 |
val (positionN, position) = markup_elem "position"; |
26255 | 171 |
val (locationN, location) = markup_elem "location"; |
172 |
||
23644 | 173 |
|
174 |
(* pretty printing *) |
|
175 |
||
176 |
val indentN = "indent"; |
|
177 |
val (blockN, block) = markup_int "block" indentN; |
|
178 |
||
179 |
val widthN = "width"; |
|
180 |
val (breakN, break) = markup_int "break" widthN; |
|
181 |
||
25552 | 182 |
val (fbreakN, fbreak) = markup_elem "fbreak"; |
23637 | 183 |
|
184 |
||
23623 | 185 |
(* logical entities *) |
186 |
||
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
|
187 |
val (tclassN, tclass) = markup_string "tclass" nameN; |
23658 | 188 |
val (tyconN, tycon) = markup_string "tycon" nameN; |
26702
a079f8f0080b
added markup for fixed variables (local constants);
wenzelm
parents:
26255
diff
changeset
|
189 |
val (fixedN, fixed) = markup_string "fixed" nameN; |
23658 | 190 |
val (constN, const) = markup_string "const" nameN; |
27740 | 191 |
val (factN, fact) = markup_string "fact" nameN; |
192 |
val (dynamic_factN, dynamic_fact) = markup_string "dynamic_fact" 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"; |
|
204 |
val (numN, num) = markup_elem "num"; |
|
205 |
val (xnumN, xnum) = markup_elem "xnum"; |
|
206 |
val (xstrN, xstr) = markup_elem "xstr"; |
|
27804 | 207 |
val (literalN, literal) = markup_elem "literal"; |
27883 | 208 |
val (inner_commentN, inner_comment) = markup_elem "inner_comment"; |
23719 | 209 |
|
25552 | 210 |
val (sortN, sort) = markup_elem "sort"; |
211 |
val (typN, typ) = markup_elem "typ"; |
|
212 |
val (termN, term) = markup_elem "term"; |
|
27818 | 213 |
val (propN, prop) = markup_elem "prop"; |
27748 | 214 |
|
215 |
val (attributeN, attribute) = markup_string "attribute" nameN; |
|
216 |
val (methodN, method) = markup_string "method" nameN; |
|
23623 | 217 |
|
218 |
||
27875 | 219 |
(* embedded source text *) |
220 |
||
221 |
val (ML_sourceN, ML_source) = markup_elem "ML_source"; |
|
222 |
val (doc_sourceN, doc_source) = markup_elem "doc_source"; |
|
223 |
||
27879 | 224 |
val (antiqN, antiq) = markup_elem "antiq"; |
27894 | 225 |
val (ML_antiqN, ML_antiq) = markup_string "ML_antiq" nameN; |
226 |
val (doc_antiqN, doc_antiq) = markup_string "doc_antiq" nameN; |
|
27879 | 227 |
|
27875 | 228 |
|
23623 | 229 |
(* outer syntax *) |
230 |
||
24870 | 231 |
val (keyword_declN, keyword_decl) = markup_string "keyword_decl" nameN; |
232 |
||
233 |
val command_declN = "command_decl"; |
|
234 |
fun command_decl name kind : T = (command_declN, [(nameN, name), (kindN, kind)]); |
|
235 |
||
27836 | 236 |
val (keywordN, keyword) = markup_string "keyword" nameN; |
237 |
val (commandN, command) = markup_string "command" nameN; |
|
238 |
val (identN, ident) = markup_elem "ident"; |
|
25552 | 239 |
val (stringN, string) = markup_elem "string"; |
240 |
val (altstringN, altstring) = markup_elem "altstring"; |
|
241 |
val (verbatimN, verbatim) = markup_elem "verbatim"; |
|
242 |
val (commentN, comment) = markup_elem "comment"; |
|
243 |
val (controlN, control) = markup_elem "control"; |
|
244 |
val (malformedN, malformed) = markup_elem "malformed"; |
|
23719 | 245 |
|
27851 | 246 |
val (tokenN, token) = markup_elem "token"; |
247 |
||
27660 | 248 |
val (command_spanN, command_span) = markup_string "command_span" nameN; |
249 |
val (ignored_spanN, ignored_span) = markup_elem "ignored_span"; |
|
27836 | 250 |
val (malformed_spanN, malformed_span) = markup_elem "malformed_span"; |
23719 | 251 |
|
23623 | 252 |
|
23637 | 253 |
(* toplevel *) |
254 |
||
25552 | 255 |
val (stateN, state) = markup_elem "state"; |
256 |
val (subgoalN, subgoal) = markup_elem "subgoal"; |
|
257 |
val (sendbackN, sendback) = markup_elem "sendback"; |
|
258 |
val (hiliteN, hilite) = markup_elem "hilite"; |
|
259 |
||
260 |
||
27606 | 261 |
(* command status *) |
262 |
||
263 |
val (unprocessedN, unprocessed) = markup_elem "unprocessed"; |
|
264 |
val (runningN, running) = markup_elem "running"; |
|
27615 | 265 |
val (failedN, failed) = markup_elem "failed"; |
27606 | 266 |
val (finishedN, finished) = markup_elem "finished"; |
267 |
val (disposedN, disposed) = markup_elem "disposed"; |
|
268 |
||
269 |
||
27969 | 270 |
(* messages *) |
271 |
||
272 |
val pidN = "pid"; |
|
273 |
val sessionN = "session"; |
|
274 |
||
275 |
val classN = "class"; |
|
276 |
val (messageN, message) = markup_string "message" classN; |
|
277 |
||
278 |
val (promptN, prompt) = markup_elem "prompt"; |
|
279 |
||
280 |
val writelnN = "writeln"; |
|
281 |
val priorityN = "priority"; |
|
282 |
val tracingN = "tracing"; |
|
283 |
val warningN = "warning"; |
|
284 |
val errorN = "error"; |
|
285 |
val debugN = "debug"; |
|
286 |
val initN = "init"; |
|
287 |
val statusN = "status"; |
|
288 |
||
289 |
||
23704 | 290 |
(* print mode operations *) |
291 |
||
292 |
fun default_output (_: T) = ("", ""); |
|
293 |
||
294 |
local |
|
295 |
val default = {output = default_output}; |
|
296 |
val modes = ref (Symtab.make [("", default)]); |
|
297 |
in |
|
23922
707639e9497d
marked some CRITICAL sections (for multithreading);
wenzelm
parents:
23794
diff
changeset
|
298 |
fun add_mode name output = CRITICAL (fn () => |
707639e9497d
marked some CRITICAL sections (for multithreading);
wenzelm
parents:
23794
diff
changeset
|
299 |
change modes (Symtab.update_new (name, {output = output}))); |
23704 | 300 |
fun get_mode () = |
24612 | 301 |
the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ())); |
23623 | 302 |
end; |
23704 | 303 |
|
27883 | 304 |
fun output m = if is_none m then ("", "") else #output (get_mode ()) m; |
23704 | 305 |
|
23719 | 306 |
val enclose = output #-> Library.enclose; |
307 |
||
25552 | 308 |
fun markup m = |
309 |
let val (bg, en) = output m |
|
310 |
in Library.enclose (Output.escape bg) (Output.escape en) end; |
|
311 |
||
23704 | 312 |
end; |