| author | wenzelm | 
| Wed, 19 May 2021 15:53:55 +0200 | |
| changeset 73746 | b2d47981c8dc | 
| parent 73198 | a9eaf8c3b728 | 
| child 77723 | b761c91c2447 | 
| permissions | -rw-r--r-- | 
| 6118 | 1 | (* Title: Pure/General/symbol.ML | 
| 63936 | 2 | Author: Makarius | 
| 6116 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 3 | |
| 69490 | 4 | Isabelle text symbols. | 
| 6116 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 5 | *) | 
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 6 | |
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 7 | signature SYMBOL = | 
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 8 | sig | 
| 40509 | 9 | type symbol = string | 
| 63936 | 10 | val explode: string -> symbol list | 
| 61865 | 11 | val spaces: int -> string | 
| 26524 | 12 | val STX: symbol | 
| 13 | val DEL: symbol | |
| 62210 | 14 | val open_: symbol | 
| 15 | val close: symbol | |
| 6116 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 16 | val space: symbol | 
| 62804 | 17 | val is_space: symbol -> bool | 
| 61579 | 18 | val comment: symbol | 
| 67413 | 19 | val cancel: symbol | 
| 67428 | 20 | val latex: symbol | 
| 69891 
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
 wenzelm parents: 
69592diff
changeset | 21 | val marker: symbol | 
| 14678 | 22 | val is_char: symbol -> bool | 
| 37533 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
34095diff
changeset | 23 | val is_utf8: symbol -> bool | 
| 14678 | 24 | val is_symbolic: symbol -> bool | 
| 55033 | 25 | val is_symbolic_char: symbol -> bool | 
| 14678 | 26 | val is_printable: symbol -> bool | 
| 69592 
a80d8ec6c998
support for isabelle update -u control_cartouches;
 wenzelm parents: 
69490diff
changeset | 27 | val control_prefix: string | 
| 
a80d8ec6c998
support for isabelle update -u control_cartouches;
 wenzelm parents: 
69490diff
changeset | 28 | val control_suffix: string | 
| 61470 | 29 | val is_control: symbol -> bool | 
| 6116 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 30 | val eof: symbol | 
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 31 | val is_eof: symbol -> bool | 
| 27766 | 32 | val not_eof: symbol -> bool | 
| 27732 | 33 | val stopper: symbol Scan.stopper | 
| 40523 
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
 wenzelm parents: 
40509diff
changeset | 34 | val is_malformed: symbol -> bool | 
| 
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
 wenzelm parents: 
40509diff
changeset | 35 | val malformed_msg: symbol -> string | 
| 6116 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 36 | val is_ascii: symbol -> bool | 
| 14678 | 37 | val is_ascii_letter: symbol -> bool | 
| 38 | val is_ascii_digit: symbol -> bool | |
| 24580 
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
 wenzelm parents: 
23784diff
changeset | 39 | val is_ascii_hex: symbol -> bool | 
| 14678 | 40 | val is_ascii_quasi: symbol -> bool | 
| 41 | val is_ascii_blank: symbol -> bool | |
| 69452 | 42 | val is_ascii_line_terminator: symbol -> bool | 
| 34095 
c2f176a38448
robust representation of low ASCII control characters within XML/YXML text;
 wenzelm parents: 
33955diff
changeset | 43 | val is_ascii_control: symbol -> bool | 
| 50236 | 44 | val is_ascii_letdig: symbol -> bool | 
| 20200 | 45 | val is_ascii_lower: symbol -> bool | 
| 46 | val is_ascii_upper: symbol -> bool | |
| 47 | val to_ascii_lower: symbol -> symbol | |
| 48 | val to_ascii_upper: symbol -> symbol | |
| 50238 
98d35a7368bd
more uniform Symbol.is_ascii_identifier in ML/Scala;
 wenzelm parents: 
50237diff
changeset | 49 | val is_ascii_identifier: string -> bool | 
| 50236 | 50 | val scan_ascii_id: string list -> string * string list | 
| 40523 
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
 wenzelm parents: 
40509diff
changeset | 51 | datatype sym = | 
| 63936 | 52 | Char of string | UTF8 of string | Sym of string | Control of string | Malformed of string | EOF | 
| 14873 | 53 | val decode: symbol -> sym | 
| 67373 | 54 | val encode: sym -> symbol | 
| 14678 | 55 | datatype kind = Letter | Digit | Quasi | Blank | Other | 
| 56 | val kind: symbol -> kind | |
| 6116 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 57 | val is_letter: symbol -> bool | 
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 58 | val is_digit: symbol -> bool | 
| 12904 | 59 | val is_quasi: symbol -> bool | 
| 14678 | 60 | val is_blank: symbol -> bool | 
| 73198 
a9eaf8c3b728
tuned signature (e.g. see HTML.control_block in Isabelle/Scala);
 wenzelm parents: 
73163diff
changeset | 61 | val is_control_block: symbol -> bool | 
| 
a9eaf8c3b728
tuned signature (e.g. see HTML.control_block in Isabelle/Scala);
 wenzelm parents: 
73163diff
changeset | 62 | val has_control_block: symbol list -> bool | 
| 6116 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 63 | val is_quasi_letter: symbol -> bool | 
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 64 | val is_letdig: symbol -> bool | 
| 14728 | 65 | val beginning: int -> symbol list -> string | 
| 50237 | 66 | val esc: symbol -> string | 
| 67 | val escape: string -> string | |
| 68 | val scanner: string -> (string list -> 'a * string list) -> symbol list -> 'a | |
| 50162 | 69 | val split_words: symbol list -> string list | 
| 70 | val explode_words: string -> string list | |
| 61435 | 71 | val trim_blanks: string -> string | 
| 14678 | 72 | val bump_init: string -> string | 
| 12904 | 73 | val bump_string: string -> string | 
| 67512 | 74 | val sub: symbol | 
| 75 | val sup: symbol | |
| 76 | val bold: symbol | |
| 77 | val make_sub: string -> string | |
| 78 | val make_sup: string -> string | |
| 79 | val make_bold: string -> string | |
| 14678 | 80 | val length: symbol list -> int | 
| 40131 
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
 wenzelm parents: 
37728diff
changeset | 81 | val output: string -> Output.output * int | 
| 6116 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 82 | end; | 
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 83 | |
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 84 | structure Symbol: SYMBOL = | 
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 85 | struct | 
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 86 | |
| 14678 | 87 | (** type symbol **) | 
| 6272 | 88 | |
| 14678 | 89 | (*Symbols, which are considered the smallest entities of any Isabelle | 
| 6272 | 90 | string, may be of the following form: | 
| 14678 | 91 | |
| 63936 | 92 | (1) ASCII: a | 
| 93 | (2) UTF-8: ä | |
| 17823 | 94 | (2) regular symbols: \<ident> | 
| 14834 | 95 | (3) control symbols: \<^ident> | 
| 6272 | 96 | |
| 14678 | 97 | Output is subject to the print_mode variable (default: verbatim), | 
| 98 | actual interpretation in display is up to front-end tools. | |
| 6272 | 99 | *) | 
| 100 | ||
| 101 | type symbol = string; | |
| 102 | ||
| 26524 | 103 | val STX = chr 2; | 
| 104 | val DEL = chr 127; | |
| 105 | ||
| 62529 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 106 | val open_ = "\<open>"; | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 107 | val close = "\<close>"; | 
| 62210 | 108 | |
| 26524 | 109 | val space = chr 32; | 
| 62804 | 110 | fun is_space s = s = space; | 
| 17063 | 111 | |
| 61865 | 112 | local | 
| 113 | val small_spaces = Vector.tabulate (65, fn i => replicate_string i space); | |
| 114 | in | |
| 115 | fun spaces n = | |
| 116 | if n < 64 then Vector.sub (small_spaces, n) | |
| 117 | else | |
| 118 | replicate_string (n div 64) (Vector.sub (small_spaces, 64)) ^ | |
| 119 | Vector.sub (small_spaces, n mod 64); | |
| 120 | end; | |
| 121 | ||
| 62529 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 122 | val comment = "\<comment>"; | 
| 67413 | 123 | val cancel = "\<^cancel>"; | 
| 67428 | 124 | val latex = "\<^latex>"; | 
| 69891 
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
 wenzelm parents: 
69592diff
changeset | 125 | val marker = "\<^marker>"; | 
| 61579 | 126 | |
| 14678 | 127 | fun is_char s = size s = 1; | 
| 128 | ||
| 37533 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
34095diff
changeset | 129 | fun is_utf8 s = size s > 0 andalso forall_string (fn c => ord c >= 128) s; | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
34095diff
changeset | 130 | |
| 55033 | 131 | fun raw_symbolic s = | 
| 62877 
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
 wenzelm parents: 
62804diff
changeset | 132 | String.isPrefix "\092<" s andalso String.isSuffix ">" s andalso not (String.isPrefix "\092<^" s); | 
| 55033 | 133 | |
| 14678 | 134 | fun is_symbolic s = | 
| 62210 | 135 | s <> open_ andalso s <> close andalso raw_symbolic s; | 
| 55033 | 136 | |
| 137 | val is_symbolic_char = member (op =) (raw_explode "!#$%&*+-/<=>?@^_|~"); | |
| 14678 | 138 | |
| 139 | fun is_printable s = | |
| 64275 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 140 | if is_char s then 32 <= ord s andalso ord s <= Char.ord #"~" | 
| 55033 | 141 | else is_utf8 s orelse raw_symbolic s; | 
| 26632 | 142 | |
| 69592 
a80d8ec6c998
support for isabelle update -u control_cartouches;
 wenzelm parents: 
69490diff
changeset | 143 | val control_prefix = "\092<^"; | 
| 
a80d8ec6c998
support for isabelle update -u control_cartouches;
 wenzelm parents: 
69490diff
changeset | 144 | val control_suffix = ">"; | 
| 
a80d8ec6c998
support for isabelle update -u control_cartouches;
 wenzelm parents: 
69490diff
changeset | 145 | |
| 61470 | 146 | fun is_control s = | 
| 69592 
a80d8ec6c998
support for isabelle update -u control_cartouches;
 wenzelm parents: 
69490diff
changeset | 147 | String.isPrefix control_prefix s andalso String.isSuffix control_suffix s; | 
| 61470 | 148 | |
| 6272 | 149 | |
| 14678 | 150 | (* input source control *) | 
| 6272 | 151 | |
| 14678 | 152 | val eof = ""; | 
| 6272 | 153 | fun is_eof s = s = eof; | 
| 154 | fun not_eof s = s <> eof; | |
| 27732 | 155 | val stopper = Scan.stopper (K eof) is_eof; | 
| 6272 | 156 | |
| 48774 | 157 | fun is_malformed s = | 
| 62877 
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
 wenzelm parents: 
62804diff
changeset | 158 | String.isPrefix "\092<" s andalso not (String.isSuffix ">" s) | 
| 
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
 wenzelm parents: 
62804diff
changeset | 159 | orelse s = "\092<>" orelse s = "\092<^>"; | 
| 48774 | 160 | |
| 40523 
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
 wenzelm parents: 
40509diff
changeset | 161 | fun malformed_msg s = "Malformed symbolic character: " ^ quote s; | 
| 14678 | 162 | |
| 163 | ||
| 43418 | 164 | (* ASCII symbols *) | 
| 14678 | 165 | |
| 166 | fun is_ascii s = is_char s andalso ord s < 128; | |
| 167 | ||
| 168 | fun is_ascii_letter s = | |
| 169 | is_char s andalso | |
| 64275 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 170 | (Char.ord #"A" <= ord s andalso ord s <= Char.ord #"Z" orelse | 
| 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 171 | Char.ord #"a" <= ord s andalso ord s <= Char.ord #"z"); | 
| 14678 | 172 | |
| 173 | fun is_ascii_digit s = | |
| 64275 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 174 | is_char s andalso Char.ord #"0" <= ord s andalso ord s <= Char.ord #"9"; | 
| 14678 | 175 | |
| 24580 
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
 wenzelm parents: 
23784diff
changeset | 176 | fun is_ascii_hex s = | 
| 
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
 wenzelm parents: 
23784diff
changeset | 177 | is_char s andalso | 
| 64275 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 178 | (Char.ord #"0" <= ord s andalso ord s <= Char.ord #"9" orelse | 
| 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 179 | Char.ord #"A" <= ord s andalso ord s <= Char.ord #"F" orelse | 
| 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 180 | Char.ord #"a" <= ord s andalso ord s <= Char.ord #"f"); | 
| 24580 
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
 wenzelm parents: 
23784diff
changeset | 181 | |
| 14678 | 182 | fun is_ascii_quasi "_" = true | 
| 183 | | is_ascii_quasi "'" = true | |
| 184 | | is_ascii_quasi _ = false; | |
| 185 | ||
| 186 | val is_ascii_blank = | |
| 43845 
d89353d17f54
added File.fold_pages for streaming of large files;
 wenzelm parents: 
43777diff
changeset | 187 | fn " " => true | "\t" => true | "\n" => true | "\^K" => true | "\f" => true | "\^M" => true | 
| 14678 | 188 | | _ => false; | 
| 189 | ||
| 69452 | 190 | val is_ascii_line_terminator = | 
| 191 | fn "\r" => true | "\n" => true | _ => false; | |
| 192 | ||
| 34095 
c2f176a38448
robust representation of low ASCII control characters within XML/YXML text;
 wenzelm parents: 
33955diff
changeset | 193 | fun is_ascii_control s = is_char s andalso ord s < 32 andalso not (is_ascii_blank s); | 
| 
c2f176a38448
robust representation of low ASCII control characters within XML/YXML text;
 wenzelm parents: 
33955diff
changeset | 194 | |
| 50236 | 195 | fun is_ascii_letdig s = is_ascii_letter s orelse is_ascii_digit s orelse is_ascii_quasi s; | 
| 196 | ||
| 64275 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 197 | fun is_ascii_lower s = is_char s andalso (Char.ord #"a" <= ord s andalso ord s <= Char.ord #"z"); | 
| 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 198 | fun is_ascii_upper s = is_char s andalso (Char.ord #"A" <= ord s andalso ord s <= Char.ord #"Z"); | 
| 20200 | 199 | |
| 64275 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 200 | fun to_ascii_lower s = if is_ascii_upper s then chr (ord s + Char.ord #"a" - Char.ord #"A") else s; | 
| 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 201 | fun to_ascii_upper s = if is_ascii_lower s then chr (ord s + Char.ord #"A" - Char.ord #"a") else s; | 
| 20200 | 202 | |
| 50238 
98d35a7368bd
more uniform Symbol.is_ascii_identifier in ML/Scala;
 wenzelm parents: 
50237diff
changeset | 203 | fun is_ascii_identifier s = | 
| 
98d35a7368bd
more uniform Symbol.is_ascii_identifier in ML/Scala;
 wenzelm parents: 
50237diff
changeset | 204 | size s > 0 andalso is_ascii_letter (String.substring (s, 0, 1)) andalso | 
| 
98d35a7368bd
more uniform Symbol.is_ascii_identifier in ML/Scala;
 wenzelm parents: 
50237diff
changeset | 205 | forall_string is_ascii_letdig s; | 
| 
98d35a7368bd
more uniform Symbol.is_ascii_identifier in ML/Scala;
 wenzelm parents: 
50237diff
changeset | 206 | |
| 50236 | 207 | val scan_ascii_id = Scan.one is_ascii_letter ^^ (Scan.many is_ascii_letdig >> implode); | 
| 208 | ||
| 14678 | 209 | |
| 14956 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 210 | (* diagnostics *) | 
| 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 211 | |
| 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 212 | fun beginning n cs = | 
| 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 213 | let | 
| 67522 | 214 | val drop_blanks = drop_suffix is_ascii_blank; | 
| 14956 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 215 | val all_cs = drop_blanks cs; | 
| 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 216 | val dots = if length all_cs > n then " ..." else ""; | 
| 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 217 | in | 
| 33955 | 218 | (drop_blanks (take n all_cs) | 
| 14956 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 219 | |> map (fn c => if is_ascii_blank c then space else c) | 
| 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 220 | |> implode) ^ dots | 
| 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 221 | end; | 
| 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 222 | |
| 
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
 wenzelm parents: 
14908diff
changeset | 223 | |
| 14873 | 224 | (* symbol variants *) | 
| 225 | ||
| 37533 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
34095diff
changeset | 226 | datatype sym = | 
| 63936 | 227 | Char of string | UTF8 of string | Sym of string | Control of string | Malformed of string | EOF; | 
| 14873 | 228 | |
| 229 | fun decode s = | |
| 43485 | 230 | if s = "" then EOF | 
| 231 | else if is_char s then Char s | |
| 37533 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
34095diff
changeset | 232 | else if is_utf8 s then UTF8 s | 
| 40523 
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
 wenzelm parents: 
40509diff
changeset | 233 | else if is_malformed s then Malformed s | 
| 61475 | 234 | else if is_control s then Control (String.substring (s, 3, size s - 4)) | 
| 40523 
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
 wenzelm parents: 
40509diff
changeset | 235 | else Sym (String.substring (s, 2, size s - 3)); | 
| 14873 | 236 | |
| 67373 | 237 | fun encode (Char s) = s | 
| 238 | | encode (UTF8 s) = s | |
| 239 | | encode (Sym s) = "\092<" ^ s ^ ">" | |
| 240 | | encode (Control s) = "\092<^" ^ s ^ ">" | |
| 241 | | encode (Malformed s) = s | |
| 242 | | encode EOF = ""; | |
| 243 | ||
| 14873 | 244 | |
| 14678 | 245 | (* standard symbol kinds *) | 
| 246 | ||
| 14171 
0cab06e3bbd0
Extended the notion of letter and digit, such that now one may use greek,
 skalberg parents: 
13730diff
changeset | 247 | local | 
| 50235 | 248 | val letter_symbols = | 
| 249 | Symtab.make_set [ | |
| 62529 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 250 | "\<A>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 251 | "\<B>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 252 | "\<C>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 253 | "\<D>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 254 | "\<E>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 255 | "\<F>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 256 | "\<G>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 257 | "\<H>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 258 | "\<I>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 259 | "\<J>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 260 | "\<K>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 261 | "\<L>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 262 | "\<M>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 263 | "\<N>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 264 | "\<O>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 265 | "\<P>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 266 | "\<Q>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 267 | "\<R>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 268 | "\<S>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 269 | "\<T>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 270 | "\<U>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 271 | "\<V>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 272 | "\<W>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 273 | "\<X>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 274 | "\<Y>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 275 | "\<Z>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 276 | "\<a>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 277 | "\<b>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 278 | "\<c>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 279 | "\<d>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 280 | "\<e>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 281 | "\<f>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 282 | "\<g>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 283 | "\<h>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 284 | "\<i>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 285 | "\<j>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 286 | "\<k>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 287 | "\<l>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 288 | "\<m>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 289 | "\<n>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 290 | "\<o>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 291 | "\<p>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 292 | "\<q>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 293 | "\<r>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 294 | "\<s>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 295 | "\<t>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 296 | "\<u>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 297 | "\<v>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 298 | "\<w>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 299 | "\<x>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 300 | "\<y>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 301 | "\<z>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 302 | "\<AA>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 303 | "\<BB>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 304 | "\<CC>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 305 | "\<DD>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 306 | "\<EE>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 307 | "\<FF>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 308 | "\<GG>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 309 | "\<HH>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 310 | "\<II>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 311 | "\<JJ>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 312 | "\<KK>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 313 | "\<LL>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 314 | "\<MM>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 315 | "\<NN>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 316 | "\<OO>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 317 | "\<PP>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 318 | "\<QQ>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 319 | "\<RR>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 320 | "\<SS>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 321 | "\<TT>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 322 | "\<UU>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 323 | "\<VV>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 324 | "\<WW>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 325 | "\<XX>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 326 | "\<YY>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 327 | "\<ZZ>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 328 | "\<aa>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 329 | "\<bb>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 330 | "\<cc>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 331 | "\<dd>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 332 | "\<ee>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 333 | "\<ff>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 334 | "\<gg>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 335 | "\<hh>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 336 | "\<ii>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 337 | "\<jj>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 338 | "\<kk>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 339 | "\<ll>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 340 | "\<mm>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 341 | "\<nn>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 342 | "\<oo>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 343 | "\<pp>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 344 | "\<qq>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 345 | "\<rr>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 346 | "\<ss>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 347 | "\<tt>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 348 | "\<uu>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 349 | "\<vv>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 350 | "\<ww>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 351 | "\<xx>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 352 | "\<yy>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 353 | "\<zz>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 354 | "\<alpha>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 355 | "\<beta>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 356 | "\<gamma>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 357 | "\<delta>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 358 | "\<epsilon>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 359 | "\<zeta>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 360 | "\<eta>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 361 | "\<theta>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 362 | "\<iota>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 363 | "\<kappa>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 364 | (*"\<lambda>", sic!*) | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 365 | "\<mu>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 366 | "\<nu>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 367 | "\<xi>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 368 | "\<pi>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 369 | "\<rho>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 370 | "\<sigma>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 371 | "\<tau>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 372 | "\<upsilon>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 373 | "\<phi>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 374 | "\<chi>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 375 | "\<psi>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 376 | "\<omega>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 377 | "\<Gamma>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 378 | "\<Delta>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 379 | "\<Theta>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 380 | "\<Lambda>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 381 | "\<Xi>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 382 | "\<Pi>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 383 | "\<Sigma>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 384 | "\<Upsilon>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 385 | "\<Phi>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 386 | "\<Psi>", | 
| 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 387 | "\<Omega>" | 
| 50235 | 388 | ]; | 
| 14171 
0cab06e3bbd0
Extended the notion of letter and digit, such that now one may use greek,
 skalberg parents: 
13730diff
changeset | 389 | in | 
| 50242 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 390 | |
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 391 | val is_letter_symbol = Symtab.defined letter_symbols; | 
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 392 | |
| 14678 | 393 | end; | 
| 14173 | 394 | |
| 50242 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 395 | datatype kind = Letter | Digit | Quasi | Blank | Other; | 
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 396 | |
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 397 | fun kind s = | 
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 398 | if is_ascii_letter s then Letter | 
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 399 | else if is_ascii_digit s then Digit | 
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 400 | else if is_ascii_quasi s then Quasi | 
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 401 | else if is_ascii_blank s then Blank | 
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 402 | else if is_char s then Other | 
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 403 | else if is_letter_symbol s then Letter | 
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 404 | else Other; | 
| 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 405 | |
| 14678 | 406 | fun is_letter s = kind s = Letter; | 
| 407 | fun is_digit s = kind s = Digit; | |
| 408 | fun is_quasi s = kind s = Quasi; | |
| 409 | fun is_blank s = kind s = Blank; | |
| 6272 | 410 | |
| 73198 
a9eaf8c3b728
tuned signature (e.g. see HTML.control_block in Isabelle/Scala);
 wenzelm parents: 
73163diff
changeset | 411 | val is_control_block = member (op =) ["\<^bsub>", "\<^esub>", "\<^bsup>", "\<^esup>"]; | 
| 
a9eaf8c3b728
tuned signature (e.g. see HTML.control_block in Isabelle/Scala);
 wenzelm parents: 
73163diff
changeset | 412 | val has_control_block = exists is_control_block; | 
| 47850 
c638127b4653
avoid interference of markup for literal tokens, which may contain slightly odd \<^bsub> \<^esub> counted as pseudo-markup (especially relevant for HTML output, e.g. of thm power3_eq_cube);
 wenzelm parents: 
43947diff
changeset | 413 | |
| 14678 | 414 | fun is_quasi_letter s = let val k = kind s in k = Letter orelse k = Quasi end; | 
| 415 | fun is_letdig s = let val k = kind s in k = Letter orelse k = Digit orelse k = Quasi end; | |
| 11010 | 416 | |
| 6272 | 417 | |
| 50237 | 418 | (* escape *) | 
| 419 | ||
| 420 | val esc = fn s => | |
| 421 | if is_char s then s | |
| 422 | else if is_utf8 s then translate_string (fn c => "\\" ^ string_of_int (ord c)) s | |
| 423 | else "\\" ^ s; | |
| 424 | ||
| 63936 | 425 | val escape = implode o map esc o Symbol.explode; | 
| 50237 | 426 | |
| 427 | ||
| 428 | ||
| 429 | (** scanning through symbols **) | |
| 430 | ||
| 431 | (* scanner *) | |
| 432 | ||
| 433 | fun scanner msg scan syms = | |
| 434 | let | |
| 435 | fun message (ss, NONE) = (fn () => msg ^ ": " ^ quote (beginning 10 ss)) | |
| 436 | | message (ss, SOME msg') = (fn () => msg ^ ", " ^ msg' () ^ ": " ^ quote (beginning 10 ss)); | |
| 437 | val finite_scan = Scan.error (Scan.finite stopper (!! message scan)); | |
| 438 | in | |
| 439 | (case finite_scan syms of | |
| 440 | (result, []) => result | |
| 441 | | (_, rest) => error (message (rest, NONE) ())) | |
| 442 | end; | |
| 443 | ||
| 444 | ||
| 50162 | 445 | (* space-separated words *) | 
| 446 | ||
| 447 | val scan_word = | |
| 448 | Scan.many1 is_ascii_blank >> K NONE || | |
| 449 | Scan.many1 (fn s => not (is_ascii_blank s) andalso not_eof s) >> (SOME o implode); | |
| 450 | ||
| 451 | val split_words = scanner "Bad text" (Scan.repeat scan_word >> map_filter I); | |
| 452 | ||
| 63936 | 453 | val explode_words = split_words o Symbol.explode; | 
| 50162 | 454 | |
| 455 | ||
| 14678 | 456 | (* blanks *) | 
| 457 | ||
| 63936 | 458 | val trim_blanks = Symbol.explode #> trim is_blank #> implode; | 
| 14678 | 459 | |
| 460 | ||
| 461 | (* bump string -- treat as base 26 or base 1 numbers *) | |
| 462 | ||
| 62529 
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
 wenzelm parents: 
62210diff
changeset | 463 | fun symbolic_end (_ :: "\<^sub>" :: _) = true | 
| 53198 
06b096cf89ca
ignore trailing primes, e.g. rename \<alpha>' to \<alpha>'' instead of \<alpha>'a;
 wenzelm parents: 
53016diff
changeset | 464 |   | symbolic_end ("'" :: ss) = symbolic_end ss
 | 
| 55033 | 465 | | symbolic_end (s :: _) = raw_symbolic s | 
| 14908 | 466 | | symbolic_end [] = false; | 
| 14678 | 467 | |
| 468 | fun bump_init str = | |
| 63936 | 469 | if symbolic_end (rev (Symbol.explode str)) then str ^ "'" | 
| 14678 | 470 | else str ^ "a"; | 
| 12904 | 471 | |
| 472 | fun bump_string str = | |
| 473 | let | |
| 474 | fun bump [] = ["a"] | |
| 475 |       | bump ("z" :: ss) = "a" :: bump ss
 | |
| 476 | | bump (s :: ss) = | |
| 64275 
ac2abc987cf9
accomodate Poly/ML repository version, which treats singleton strings as boxed;
 wenzelm parents: 
63936diff
changeset | 477 | if is_char s andalso Char.ord #"a" <= ord s andalso ord s < Char.ord #"z" | 
| 12904 | 478 | then chr (ord s + 1) :: ss | 
| 479 | else "a" :: s :: ss; | |
| 14678 | 480 | |
| 67522 | 481 | val (ss, qs) = apfst rev (chop_suffix is_quasi (Symbol.explode str)); | 
| 14908 | 482 | val ss' = if symbolic_end ss then "'" :: ss else bump ss; | 
| 14678 | 483 | in implode (rev ss' @ qs) end; | 
| 484 | ||
| 12904 | 485 | |
| 67512 | 486 | (* styles *) | 
| 487 | ||
| 488 | val sub = "\092<^sub>"; | |
| 489 | val sup = "\092<^sup>"; | |
| 490 | val bold = "\092<^bold>"; | |
| 491 | ||
| 492 | fun make_style sym = | |
| 493 | Symbol.explode #> maps (fn s => [sym, s]) #> implode; | |
| 494 | ||
| 495 | val make_sub = make_style sub; | |
| 496 | val make_sup = make_style sup; | |
| 497 | val make_bold = make_style bold; | |
| 498 | ||
| 499 | ||
| 6272 | 500 | |
| 29324 | 501 | (** symbol output **) | 
| 14977 
77d88064991a
added escape, export encode_raw, default mode now trivial, tuned;
 wenzelm parents: 
14961diff
changeset | 502 | |
| 29324 | 503 | (* length *) | 
| 6272 | 504 | |
| 14678 | 505 | fun sym_len s = | 
| 71649 | 506 | if String.isPrefix "\092<long" s orelse String.isPrefix "\092<Long" s then 2 | 
| 507 | else if is_printable s then 1 | |
| 508 | else 0; | |
| 14678 | 509 | |
| 19473 | 510 | fun sym_length ss = fold (fn s => fn n => sym_len s + n) ss 0; | 
| 14678 | 511 | |
| 63936 | 512 | fun output s = (s, sym_length (Symbol.explode s)); | 
| 29324 | 513 | |
| 514 | ||
| 6116 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 515 | (*final declarations of this structure!*) | 
| 63936 | 516 | val explode = Symbol.explode; | 
| 6272 | 517 | val length = sym_length; | 
| 6116 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 518 | |
| 
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
 wenzelm parents: diff
changeset | 519 | end; |