author | wenzelm |
Tue, 05 Aug 2008 13:31:36 +0200 | |
changeset 27740 | 0b22524c05e2 |
parent 27735 | 044901e02cc6 |
child 27743 | 7420e78f1541 |
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 |
26977 | 18 |
val theory_nameN: string |
25808 | 19 |
val idN: string |
23658 | 20 |
val kindN: string |
24777 | 21 |
val internalK: string |
22 |
val property_internal: property |
|
23671 | 23 |
val lineN: string |
26001 | 24 |
val columnN: string |
27735 | 25 |
val end_lineN: string |
26 |
val end_columnN: string |
|
23671 | 27 |
val fileN: string |
26051 | 28 |
val position_properties: string list |
23671 | 29 |
val positionN: string val position: T |
26255 | 30 |
val locationN: string val location: T |
23644 | 31 |
val indentN: string |
23704 | 32 |
val blockN: string val block: int -> T |
23695 | 33 |
val widthN: string |
23644 | 34 |
val breakN: string val break: int -> T |
35 |
val fbreakN: string val fbreak: T |
|
23637 | 36 |
val classN: string val class: string -> T |
37 |
val tyconN: string val tycon: string -> T |
|
26702
a079f8f0080b
added markup for fixed variables (local constants);
wenzelm
parents:
26255
diff
changeset
|
38 |
val fixedN: string val fixed: string -> T |
23637 | 39 |
val constN: string val const: string -> T |
27740 | 40 |
val factN: string val fact: string -> T |
41 |
val dynamic_factN: string val dynamic_fact: string -> T |
|
23719 | 42 |
val tfreeN: string val tfree: T |
43 |
val tvarN: string val tvar: T |
|
44 |
val freeN: string val free: T |
|
45 |
val skolemN: string val skolem: T |
|
46 |
val boundN: string val bound: T |
|
47 |
val varN: string val var: T |
|
48 |
val numN: string val num: T |
|
49 |
val xnumN: string val xnum: T |
|
50 |
val xstrN: string val xstr: T |
|
23637 | 51 |
val sortN: string val sort: T |
52 |
val typN: string val typ: T |
|
53 |
val termN: string val term: T |
|
27740 | 54 |
val propN: string val prop: T |
23637 | 55 |
val keywordN: string val keyword: string -> T |
56 |
val commandN: string val command: string -> T |
|
24870 | 57 |
val keyword_declN: string val keyword_decl: string -> T |
58 |
val command_declN: string val command_decl: string -> string -> T |
|
23719 | 59 |
val stringN: string val string: T |
60 |
val altstringN: string val altstring: T |
|
61 |
val verbatimN: string val verbatim: T |
|
62 |
val commentN: string val comment: T |
|
63 |
val controlN: string val control: T |
|
64 |
val malformedN: string val malformed: T |
|
23786 | 65 |
val antiqN: string val antiq: T |
27660 | 66 |
val command_spanN: string val command_span: string -> T |
67 |
val ignored_spanN: string val ignored_span: T |
|
68 |
val unknown_spanN: string val unknown_span: T |
|
27523 | 69 |
val promptN: string val prompt: T |
23637 | 70 |
val stateN: string val state: T |
71 |
val subgoalN: string val subgoal: T |
|
24289 | 72 |
val sendbackN: string val sendback: T |
24555 | 73 |
val hiliteN: string val hilite: T |
27606 | 74 |
val unprocessedN: string val unprocessed: T |
75 |
val runningN: string val running: T |
|
27615 | 76 |
val failedN: string val failed: T |
27606 | 77 |
val finishedN: string val finished: T |
78 |
val disposedN: string val disposed: T |
|
23704 | 79 |
val default_output: T -> output * output |
23786 | 80 |
val add_mode: string -> (T -> output * output) -> unit |
23704 | 81 |
val output: T -> output * output |
23719 | 82 |
val enclose: T -> output -> output |
25552 | 83 |
val markup: T -> string -> string |
23623 | 84 |
end; |
85 |
||
86 |
structure Markup: MARKUP = |
|
87 |
struct |
|
88 |
||
23658 | 89 |
(* basic markup *) |
23623 | 90 |
|
23637 | 91 |
type property = string * string; |
92 |
type T = string * property list; |
|
93 |
||
94 |
val none = ("", []); |
|
95 |
||
23794 | 96 |
|
23671 | 97 |
fun properties more_props ((elem, props): T) = |
98 |
(elem, fold_rev (AList.update (op =)) more_props props); |
|
99 |
||
23794 | 100 |
fun get_string ((_, props): T) prop = AList.lookup (op =) props prop; |
101 |
fun get_int m prop = (case get_string m prop of NONE => NONE | SOME s => Int.fromString s); |
|
102 |
||
25552 | 103 |
fun markup_elem elem = (elem, (elem, []): T); |
23794 | 104 |
fun markup_string elem prop = (elem, fn s => (elem, [(prop, s)]): T); |
105 |
fun markup_int elem prop = (elem, fn i => (elem, [(prop, Int.toString i)]): T); |
|
106 |
||
26977 | 107 |
|
108 |
(* name *) |
|
109 |
||
23658 | 110 |
val nameN = "name"; |
25982 | 111 |
val groupN = "group"; |
26977 | 112 |
val theory_nameN = "theory_name"; |
24777 | 113 |
|
114 |
||
115 |
(* kind *) |
|
116 |
||
23658 | 117 |
val kindN = "kind"; |
23671 | 118 |
|
24777 | 119 |
val internalK = "internal"; |
120 |
val property_internal = (kindN, internalK); |
|
121 |
||
23658 | 122 |
|
23671 | 123 |
(* position *) |
124 |
||
125 |
val lineN = "line"; |
|
26001 | 126 |
val columnN = "column"; |
27735 | 127 |
val end_lineN = "end_line"; |
128 |
val end_columnN = "end_column"; |
|
23671 | 129 |
val fileN = "file"; |
25816 | 130 |
val idN = "id"; |
23671 | 131 |
|
27735 | 132 |
val position_properties = [lineN, columnN, end_lineN, end_columnN, fileN, idN]; |
25552 | 133 |
val (positionN, position) = markup_elem "position"; |
23644 | 134 |
|
26255 | 135 |
val (locationN, location) = markup_elem "location"; |
136 |
||
23644 | 137 |
|
138 |
(* pretty printing *) |
|
139 |
||
140 |
val indentN = "indent"; |
|
141 |
val (blockN, block) = markup_int "block" indentN; |
|
142 |
||
143 |
val widthN = "width"; |
|
144 |
val (breakN, break) = markup_int "break" widthN; |
|
145 |
||
25552 | 146 |
val (fbreakN, fbreak) = markup_elem "fbreak"; |
23637 | 147 |
|
148 |
||
23623 | 149 |
(* logical entities *) |
150 |
||
23658 | 151 |
val (classN, class) = markup_string "class" nameN; |
152 |
val (tyconN, tycon) = markup_string "tycon" nameN; |
|
26702
a079f8f0080b
added markup for fixed variables (local constants);
wenzelm
parents:
26255
diff
changeset
|
153 |
val (fixedN, fixed) = markup_string "fixed" nameN; |
23658 | 154 |
val (constN, const) = markup_string "const" nameN; |
27740 | 155 |
val (factN, fact) = markup_string "fact" nameN; |
156 |
val (dynamic_factN, dynamic_fact) = markup_string "dynamic_fact" nameN; |
|
23623 | 157 |
|
158 |
||
159 |
(* inner syntax *) |
|
160 |
||
25552 | 161 |
val (tfreeN, tfree) = markup_elem "tfree"; |
162 |
val (tvarN, tvar) = markup_elem "tvar"; |
|
163 |
val (freeN, free) = markup_elem "free"; |
|
164 |
val (skolemN, skolem) = markup_elem "skolem"; |
|
165 |
val (boundN, bound) = markup_elem "bound"; |
|
166 |
val (varN, var) = markup_elem "var"; |
|
167 |
val (numN, num) = markup_elem "num"; |
|
168 |
val (xnumN, xnum) = markup_elem "xnum"; |
|
169 |
val (xstrN, xstr) = markup_elem "xstr"; |
|
23719 | 170 |
|
25552 | 171 |
val (sortN, sort) = markup_elem "sort"; |
172 |
val (typN, typ) = markup_elem "typ"; |
|
173 |
val (termN, term) = markup_elem "term"; |
|
27740 | 174 |
val (propN, prop) = markup_elem "prop"; |
23623 | 175 |
|
176 |
||
177 |
(* outer syntax *) |
|
178 |
||
23658 | 179 |
val (keywordN, keyword) = markup_string "keyword" nameN; |
180 |
val (commandN, command) = markup_string "command" nameN; |
|
23637 | 181 |
|
24870 | 182 |
val (keyword_declN, keyword_decl) = markup_string "keyword_decl" nameN; |
183 |
||
184 |
val command_declN = "command_decl"; |
|
185 |
fun command_decl name kind : T = (command_declN, [(nameN, name), (kindN, kind)]); |
|
186 |
||
25552 | 187 |
val (stringN, string) = markup_elem "string"; |
188 |
val (altstringN, altstring) = markup_elem "altstring"; |
|
189 |
val (verbatimN, verbatim) = markup_elem "verbatim"; |
|
190 |
val (commentN, comment) = markup_elem "comment"; |
|
191 |
val (controlN, control) = markup_elem "control"; |
|
192 |
val (malformedN, malformed) = markup_elem "malformed"; |
|
23719 | 193 |
|
25552 | 194 |
val (antiqN, antiq) = markup_elem "antiq"; |
23786 | 195 |
|
27660 | 196 |
val (command_spanN, command_span) = markup_string "command_span" nameN; |
197 |
val (ignored_spanN, ignored_span) = markup_elem "ignored_span"; |
|
198 |
val (unknown_spanN, unknown_span) = markup_elem "unknown_span"; |
|
23719 | 199 |
|
23623 | 200 |
|
23637 | 201 |
(* toplevel *) |
202 |
||
27523 | 203 |
val (promptN, prompt) = markup_elem "prompt"; |
25552 | 204 |
val (stateN, state) = markup_elem "state"; |
205 |
val (subgoalN, subgoal) = markup_elem "subgoal"; |
|
206 |
val (sendbackN, sendback) = markup_elem "sendback"; |
|
207 |
val (hiliteN, hilite) = markup_elem "hilite"; |
|
208 |
||
209 |
||
27606 | 210 |
(* command status *) |
211 |
||
212 |
val (unprocessedN, unprocessed) = markup_elem "unprocessed"; |
|
213 |
val (runningN, running) = markup_elem "running"; |
|
27615 | 214 |
val (failedN, failed) = markup_elem "failed"; |
27606 | 215 |
val (finishedN, finished) = markup_elem "finished"; |
216 |
val (disposedN, disposed) = markup_elem "disposed"; |
|
217 |
||
218 |
||
23704 | 219 |
(* print mode operations *) |
220 |
||
221 |
fun default_output (_: T) = ("", ""); |
|
222 |
||
223 |
local |
|
224 |
val default = {output = default_output}; |
|
225 |
val modes = ref (Symtab.make [("", default)]); |
|
226 |
in |
|
23922
707639e9497d
marked some CRITICAL sections (for multithreading);
wenzelm
parents:
23794
diff
changeset
|
227 |
fun add_mode name output = CRITICAL (fn () => |
707639e9497d
marked some CRITICAL sections (for multithreading);
wenzelm
parents:
23794
diff
changeset
|
228 |
change modes (Symtab.update_new (name, {output = output}))); |
23704 | 229 |
fun get_mode () = |
24612 | 230 |
the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ())); |
23623 | 231 |
end; |
23704 | 232 |
|
23786 | 233 |
fun output ("", _) = ("", "") |
234 |
| output m = #output (get_mode ()) m; |
|
23704 | 235 |
|
23719 | 236 |
val enclose = output #-> Library.enclose; |
237 |
||
25552 | 238 |
fun markup m = |
239 |
let val (bg, en) = output m |
|
240 |
in Library.enclose (Output.escape bg) (Output.escape en) end; |
|
241 |
||
23704 | 242 |
end; |