| author | wenzelm | 
| Tue, 21 Feb 2012 20:22:23 +0100 | |
| changeset 46579 | fa035a015ea8 | 
| parent 45674 | eb65c9d17e2f | 
| child 46894 | e2ad717ec889 | 
| permissions | -rw-r--r-- | 
| 45670 | 1 | (* Title: Pure/PIDE/markup.ML | 
| 23623 | 2 | Author: Makarius | 
| 3 | ||
| 45666 | 4 | Generic markup elements. | 
| 23623 | 5 | *) | 
| 6 | ||
| 7 | signature MARKUP = | |
| 8 | sig | |
| 38414 
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
 wenzelm parents: 
38229diff
changeset | 9 | val parse_int: string -> int | 
| 
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
 wenzelm parents: 
38229diff
changeset | 10 | val print_int: int -> string | 
| 28017 | 11 | type T = string * Properties.T | 
| 38474 
e498dc2eb576
uniform Markup.empty/Markup.Empty in ML and Scala;
 wenzelm parents: 
38429diff
changeset | 12 | val empty: T | 
| 
e498dc2eb576
uniform Markup.empty/Markup.Empty in ML and Scala;
 wenzelm parents: 
38429diff
changeset | 13 | val is_empty: T -> bool | 
| 38229 | 14 | val properties: Properties.T -> T -> T | 
| 23623 | 15 | val nameN: string | 
| 27818 | 16 | val name: string -> T -> T | 
| 38887 
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
 wenzelm parents: 
38871diff
changeset | 17 | val kindN: string | 
| 40131 
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
 wenzelm parents: 
39585diff
changeset | 18 | val no_output: Output.output * Output.output | 
| 
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
 wenzelm parents: 
39585diff
changeset | 19 | val default_output: T -> Output.output * Output.output | 
| 
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
 wenzelm parents: 
39585diff
changeset | 20 | val add_mode: string -> (T -> Output.output * Output.output) -> unit | 
| 
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
 wenzelm parents: 
39585diff
changeset | 21 | val output: T -> Output.output * Output.output | 
| 
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
 wenzelm parents: 
39585diff
changeset | 22 | val enclose: T -> Output.output -> Output.output | 
| 25552 | 23 | val markup: T -> string -> string | 
| 43665 | 24 | val markup_only: T -> string | 
| 23623 | 25 | end; | 
| 26 | ||
| 27 | structure Markup: MARKUP = | |
| 28 | struct | |
| 29 | ||
| 30221 | 30 | (** markup elements **) | 
| 31 | ||
| 38414 
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
 wenzelm parents: 
38229diff
changeset | 32 | (* integers *) | 
| 
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
 wenzelm parents: 
38229diff
changeset | 33 | |
| 
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
 wenzelm parents: 
38229diff
changeset | 34 | fun parse_int s = | 
| 43797 
fad7758421bf
more precise integer Markup.properties/XML.attributes: disallow ML-style ~ minus;
 wenzelm parents: 
43748diff
changeset | 35 | let val i = Int.fromString s in | 
| 
fad7758421bf
more precise integer Markup.properties/XML.attributes: disallow ML-style ~ minus;
 wenzelm parents: 
43748diff
changeset | 36 | if is_none i orelse String.isPrefix "~" s | 
| 
fad7758421bf
more precise integer Markup.properties/XML.attributes: disallow ML-style ~ minus;
 wenzelm parents: 
43748diff
changeset | 37 |     then raise Fail ("Bad integer: " ^ quote s)
 | 
| 
fad7758421bf
more precise integer Markup.properties/XML.attributes: disallow ML-style ~ minus;
 wenzelm parents: 
43748diff
changeset | 38 | else the i | 
| 
fad7758421bf
more precise integer Markup.properties/XML.attributes: disallow ML-style ~ minus;
 wenzelm parents: 
43748diff
changeset | 39 | end; | 
| 38414 
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
 wenzelm parents: 
38229diff
changeset | 40 | |
| 
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
 wenzelm parents: 
38229diff
changeset | 41 | val print_int = signed_string_of_int; | 
| 
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
 wenzelm parents: 
38229diff
changeset | 42 | |
| 
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
 wenzelm parents: 
38229diff
changeset | 43 | |
| 23658 | 44 | (* basic markup *) | 
| 23623 | 45 | |
| 28017 | 46 | type T = string * Properties.T; | 
| 23637 | 47 | |
| 38474 
e498dc2eb576
uniform Markup.empty/Markup.Empty in ML and Scala;
 wenzelm parents: 
38429diff
changeset | 48 | val empty = ("", []);
 | 
| 23637 | 49 | |
| 38474 
e498dc2eb576
uniform Markup.empty/Markup.Empty in ML and Scala;
 wenzelm parents: 
38429diff
changeset | 50 | fun is_empty ("", _) = true
 | 
| 
e498dc2eb576
uniform Markup.empty/Markup.Empty in ML and Scala;
 wenzelm parents: 
38429diff
changeset | 51 | | is_empty _ = false; | 
| 27883 | 52 | |
| 23794 | 53 | |
| 23671 | 54 | fun properties more_props ((elem, props): T) = | 
| 28017 | 55 | (elem, fold_rev Properties.put more_props props); | 
| 23671 | 56 | |
| 26977 | 57 | |
| 38721 
ca8b14fa0d0d
added some proof state markup, notably number of subgoals (e.g. for indentation);
 wenzelm parents: 
38474diff
changeset | 58 | (* misc properties *) | 
| 26977 | 59 | |
| 23658 | 60 | val nameN = "name"; | 
| 27818 | 61 | fun name a = properties [(nameN, a)]; | 
| 62 | ||
| 23658 | 63 | val kindN = "kind"; | 
| 23671 | 64 | |
| 23658 | 65 | |
| 27969 | 66 | |
| 30221 | 67 | (** print mode operations **) | 
| 23704 | 68 | |
| 29325 | 69 | val no_output = ("", "");
 | 
| 70 | fun default_output (_: T) = no_output; | |
| 23704 | 71 | |
| 72 | local | |
| 73 |   val default = {output = default_output};
 | |
| 43684 | 74 |   val modes = Synchronized.var "Markup.modes" (Symtab.make [("", default)]);
 | 
| 23704 | 75 | in | 
| 43684 | 76 | fun add_mode name output = | 
| 77 |     Synchronized.change modes (Symtab.update_new (name, {output = output}));
 | |
| 23704 | 78 | fun get_mode () = | 
| 43684 | 79 | the_default default | 
| 80 | (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ())); | |
| 23623 | 81 | end; | 
| 23704 | 82 | |
| 38474 
e498dc2eb576
uniform Markup.empty/Markup.Empty in ML and Scala;
 wenzelm parents: 
38429diff
changeset | 83 | fun output m = if is_empty m then no_output else #output (get_mode ()) m; | 
| 23704 | 84 | |
| 23719 | 85 | val enclose = output #-> Library.enclose; | 
| 86 | ||
| 25552 | 87 | fun markup m = | 
| 88 | let val (bg, en) = output m | |
| 89 | in Library.enclose (Output.escape bg) (Output.escape en) end; | |
| 90 | ||
| 43665 | 91 | fun markup_only m = markup m ""; | 
| 92 | ||
| 23704 | 93 | end; |