author | wenzelm |
Thu, 01 Sep 2016 16:05:22 +0200 | |
changeset 63750 | 9c8a366778e1 |
parent 62877 | 741560a5283b |
child 63936 | b87784e19a77 |
permissions | -rw-r--r-- |
6118 | 1 |
(* Title: Pure/General/symbol.ML |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
2 |
Author: Markus Wenzel, TU Muenchen |
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
3 |
|
21897 | 4 |
Generalized characters with infinitely many named 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 |
61865 | 10 |
val spaces: int -> string |
26524 | 11 |
val STX: symbol |
12 |
val DEL: symbol |
|
62210 | 13 |
val open_: symbol |
14 |
val close: symbol |
|
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
15 |
val space: symbol |
62804 | 16 |
val is_space: symbol -> bool |
61579 | 17 |
val comment: symbol |
14678 | 18 |
val is_char: symbol -> bool |
37533
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents:
34095
diff
changeset
|
19 |
val is_utf8: symbol -> bool |
14678 | 20 |
val is_symbolic: symbol -> bool |
55033 | 21 |
val is_symbolic_char: symbol -> bool |
14678 | 22 |
val is_printable: symbol -> bool |
61470 | 23 |
val is_control: symbol -> bool |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
24 |
val eof: symbol |
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
25 |
val is_eof: symbol -> bool |
27766 | 26 |
val not_eof: symbol -> bool |
27732 | 27 |
val stopper: symbol Scan.stopper |
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
40509
diff
changeset
|
28 |
val is_malformed: symbol -> bool |
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
40509
diff
changeset
|
29 |
val malformed_msg: symbol -> string |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
30 |
val is_ascii: symbol -> bool |
14678 | 31 |
val is_ascii_letter: symbol -> bool |
32 |
val is_ascii_digit: symbol -> bool |
|
24580
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
wenzelm
parents:
23784
diff
changeset
|
33 |
val is_ascii_hex: symbol -> bool |
14678 | 34 |
val is_ascii_quasi: symbol -> bool |
35 |
val is_ascii_blank: symbol -> bool |
|
34095
c2f176a38448
robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents:
33955
diff
changeset
|
36 |
val is_ascii_control: symbol -> bool |
50236 | 37 |
val is_ascii_letdig: symbol -> bool |
20200 | 38 |
val is_ascii_lower: symbol -> bool |
39 |
val is_ascii_upper: symbol -> bool |
|
40 |
val to_ascii_lower: symbol -> symbol |
|
41 |
val to_ascii_upper: symbol -> symbol |
|
50238
98d35a7368bd
more uniform Symbol.is_ascii_identifier in ML/Scala;
wenzelm
parents:
50237
diff
changeset
|
42 |
val is_ascii_identifier: string -> bool |
50236 | 43 |
val scan_ascii_id: string list -> string * string list |
14834 | 44 |
val is_raw: symbol -> bool |
45 |
val decode_raw: symbol -> string |
|
14977
77d88064991a
added escape, export encode_raw, default mode now trivial, tuned;
wenzelm
parents:
14961
diff
changeset
|
46 |
val encode_raw: string -> string |
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
40509
diff
changeset
|
47 |
datatype sym = |
61475 | 48 |
Char of string | UTF8 of string | Sym of string | Control of string | Raw of string | |
43485 | 49 |
Malformed of string | EOF |
14873 | 50 |
val decode: symbol -> sym |
14678 | 51 |
datatype kind = Letter | Digit | Quasi | Blank | Other |
52 |
val kind: symbol -> kind |
|
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
53 |
val is_letter: symbol -> bool |
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
54 |
val is_digit: symbol -> bool |
12904 | 55 |
val is_quasi: symbol -> bool |
14678 | 56 |
val is_blank: symbol -> bool |
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:
43947
diff
changeset
|
57 |
val is_block_ctrl: symbol -> bool |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
58 |
val is_quasi_letter: symbol -> bool |
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
59 |
val is_letdig: symbol -> bool |
14728 | 60 |
val beginning: int -> symbol list -> string |
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
40509
diff
changeset
|
61 |
val source: (string, 'a) Source.source -> (symbol, (string, 'a) Source.source) Source.source |
6272 | 62 |
val explode: string -> symbol list |
50237 | 63 |
val esc: symbol -> string |
64 |
val escape: string -> string |
|
65 |
val scanner: string -> (string list -> 'a * string list) -> symbol list -> 'a |
|
50162 | 66 |
val split_words: symbol list -> string list |
67 |
val explode_words: string -> string list |
|
61435 | 68 |
val trim_blanks: string -> string |
14678 | 69 |
val bump_init: string -> string |
12904 | 70 |
val bump_string: string -> string |
14678 | 71 |
val length: symbol list -> int |
6692 | 72 |
val xsymbolsN: string |
40131
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
wenzelm
parents:
37728
diff
changeset
|
73 |
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
|
74 |
end; |
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
75 |
|
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
76 |
structure Symbol: SYMBOL = |
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
77 |
struct |
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
78 |
|
14678 | 79 |
(** type symbol **) |
6272 | 80 |
|
14678 | 81 |
(*Symbols, which are considered the smallest entities of any Isabelle |
6272 | 82 |
string, may be of the following form: |
14678 | 83 |
|
14834 | 84 |
(1) ASCII symbols: a |
17823 | 85 |
(2) regular symbols: \<ident> |
14834 | 86 |
(3) control symbols: \<^ident> |
87 |
(4) raw control symbols: \<^raw:...>, where "..." may be any printable |
|
20205
7b2958d3d575
raw symbols: disallow dot to avoid confusion in NameSpace.unpack;
wenzelm
parents:
20200
diff
changeset
|
88 |
character (excluding ".", ">"), or \<^raw000> |
6272 | 89 |
|
14678 | 90 |
Output is subject to the print_mode variable (default: verbatim), |
91 |
actual interpretation in display is up to front-end tools. |
|
6272 | 92 |
*) |
93 |
||
94 |
type symbol = string; |
|
95 |
||
26524 | 96 |
val STX = chr 2; |
97 |
val DEL = chr 127; |
|
98 |
||
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
99 |
val open_ = "\<open>"; |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
100 |
val close = "\<close>"; |
62210 | 101 |
|
26524 | 102 |
val space = chr 32; |
62804 | 103 |
fun is_space s = s = space; |
17063 | 104 |
|
61865 | 105 |
local |
106 |
val small_spaces = Vector.tabulate (65, fn i => replicate_string i space); |
|
107 |
in |
|
108 |
fun spaces n = |
|
109 |
if n < 64 then Vector.sub (small_spaces, n) |
|
110 |
else |
|
111 |
replicate_string (n div 64) (Vector.sub (small_spaces, 64)) ^ |
|
112 |
Vector.sub (small_spaces, n mod 64); |
|
113 |
end; |
|
114 |
||
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
115 |
val comment = "\<comment>"; |
61579 | 116 |
|
14678 | 117 |
fun is_char s = size s = 1; |
118 |
||
37533
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents:
34095
diff
changeset
|
119 |
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:
34095
diff
changeset
|
120 |
|
55033 | 121 |
fun raw_symbolic s = |
62877
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
wenzelm
parents:
62804
diff
changeset
|
122 |
String.isPrefix "\092<" s andalso String.isSuffix ">" s andalso not (String.isPrefix "\092<^" s); |
55033 | 123 |
|
14678 | 124 |
fun is_symbolic s = |
62210 | 125 |
s <> open_ andalso s <> close andalso raw_symbolic s; |
55033 | 126 |
|
127 |
val is_symbolic_char = member (op =) (raw_explode "!#$%&*+-/<=>?@^_|~"); |
|
14678 | 128 |
|
129 |
fun is_printable s = |
|
130 |
if is_char s then ord space <= ord s andalso ord s <= ord "~" |
|
55033 | 131 |
else is_utf8 s orelse raw_symbolic s; |
26632 | 132 |
|
61470 | 133 |
fun is_control s = |
62877
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
wenzelm
parents:
62804
diff
changeset
|
134 |
String.isPrefix "\092<^" s andalso String.isSuffix ">" s; |
61470 | 135 |
|
6272 | 136 |
|
14678 | 137 |
(* input source control *) |
6272 | 138 |
|
14678 | 139 |
val eof = ""; |
6272 | 140 |
fun is_eof s = s = eof; |
141 |
fun not_eof s = s <> eof; |
|
27732 | 142 |
val stopper = Scan.stopper (K eof) is_eof; |
6272 | 143 |
|
48774 | 144 |
fun is_malformed s = |
62877
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
wenzelm
parents:
62804
diff
changeset
|
145 |
String.isPrefix "\092<" s andalso not (String.isSuffix ">" s) |
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
wenzelm
parents:
62804
diff
changeset
|
146 |
orelse s = "\092<>" orelse s = "\092<^>"; |
48774 | 147 |
|
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
40509
diff
changeset
|
148 |
fun malformed_msg s = "Malformed symbolic character: " ^ quote s; |
14678 | 149 |
|
150 |
||
43418 | 151 |
(* ASCII symbols *) |
14678 | 152 |
|
153 |
fun is_ascii s = is_char s andalso ord s < 128; |
|
154 |
||
155 |
fun is_ascii_letter s = |
|
156 |
is_char s andalso |
|
157 |
(ord "A" <= ord s andalso ord s <= ord "Z" orelse |
|
158 |
ord "a" <= ord s andalso ord s <= ord "z"); |
|
159 |
||
160 |
fun is_ascii_digit s = |
|
161 |
is_char s andalso ord "0" <= ord s andalso ord s <= ord "9"; |
|
162 |
||
24580
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
wenzelm
parents:
23784
diff
changeset
|
163 |
fun is_ascii_hex s = |
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
wenzelm
parents:
23784
diff
changeset
|
164 |
is_char s andalso |
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
wenzelm
parents:
23784
diff
changeset
|
165 |
(ord "0" <= ord s andalso ord s <= ord "9" orelse |
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
wenzelm
parents:
23784
diff
changeset
|
166 |
ord "A" <= ord s andalso ord s <= ord "F" orelse |
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
wenzelm
parents:
23784
diff
changeset
|
167 |
ord "a" <= ord s andalso ord s <= ord "f"); |
916259859344
replaced Symbol.is_hex_letter to Symbol.is_ascii_hex;
wenzelm
parents:
23784
diff
changeset
|
168 |
|
14678 | 169 |
fun is_ascii_quasi "_" = true |
170 |
| is_ascii_quasi "'" = true |
|
171 |
| is_ascii_quasi _ = false; |
|
172 |
||
173 |
val is_ascii_blank = |
|
43845
d89353d17f54
added File.fold_pages for streaming of large files;
wenzelm
parents:
43777
diff
changeset
|
174 |
fn " " => true | "\t" => true | "\n" => true | "\^K" => true | "\f" => true | "\^M" => true |
14678 | 175 |
| _ => false; |
176 |
||
34095
c2f176a38448
robust representation of low ASCII control characters within XML/YXML text;
wenzelm
parents:
33955
diff
changeset
|
177 |
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:
33955
diff
changeset
|
178 |
|
50236 | 179 |
fun is_ascii_letdig s = is_ascii_letter s orelse is_ascii_digit s orelse is_ascii_quasi s; |
180 |
||
20200 | 181 |
fun is_ascii_lower s = is_char s andalso (ord "a" <= ord s andalso ord s <= ord "z"); |
182 |
fun is_ascii_upper s = is_char s andalso (ord "A" <= ord s andalso ord s <= ord "Z"); |
|
183 |
||
184 |
fun to_ascii_lower s = if is_ascii_upper s then chr (ord s + ord "a" - ord "A") else s; |
|
185 |
fun to_ascii_upper s = if is_ascii_lower s then chr (ord s + ord "A" - ord "a") else s; |
|
186 |
||
50238
98d35a7368bd
more uniform Symbol.is_ascii_identifier in ML/Scala;
wenzelm
parents:
50237
diff
changeset
|
187 |
fun is_ascii_identifier s = |
98d35a7368bd
more uniform Symbol.is_ascii_identifier in ML/Scala;
wenzelm
parents:
50237
diff
changeset
|
188 |
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:
50237
diff
changeset
|
189 |
forall_string is_ascii_letdig s; |
98d35a7368bd
more uniform Symbol.is_ascii_identifier in ML/Scala;
wenzelm
parents:
50237
diff
changeset
|
190 |
|
50236 | 191 |
val scan_ascii_id = Scan.one is_ascii_letter ^^ (Scan.many is_ascii_letdig >> implode); |
192 |
||
14678 | 193 |
|
14956
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
194 |
(* encode_raw *) |
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
195 |
|
20205
7b2958d3d575
raw symbols: disallow dot to avoid confusion in NameSpace.unpack;
wenzelm
parents:
20200
diff
changeset
|
196 |
fun raw_chr c = |
48773
0e1bab274672
more liberal scanning of potentially malformed symbols;
wenzelm
parents:
48704
diff
changeset
|
197 |
is_char c andalso |
0e1bab274672
more liberal scanning of potentially malformed symbols;
wenzelm
parents:
48704
diff
changeset
|
198 |
(ord space <= ord c andalso ord c <= ord "~" andalso c <> "." andalso c <> ">" |
0e1bab274672
more liberal scanning of potentially malformed symbols;
wenzelm
parents:
48704
diff
changeset
|
199 |
orelse ord c >= 128); |
14956
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
200 |
|
29324 | 201 |
fun encode_raw "" = "" |
202 |
| encode_raw str = |
|
203 |
let |
|
62877
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
wenzelm
parents:
62804
diff
changeset
|
204 |
val raw0 = enclose "\092<^raw:" ">"; |
29324 | 205 |
val raw1 = raw0 o implode; |
62877
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
wenzelm
parents:
62804
diff
changeset
|
206 |
val raw2 = enclose "\092<^raw" ">" o string_of_int o ord; |
50162 | 207 |
|
33955 | 208 |
fun encode cs = enc (take_prefix raw_chr cs) |
29324 | 209 |
and enc ([], []) = [] |
210 |
| enc (cs, []) = [raw1 cs] |
|
211 |
| enc ([], d :: ds) = raw2 d :: encode ds |
|
212 |
| enc (cs, d :: ds) = raw1 cs :: raw2 d :: encode ds; |
|
213 |
in |
|
40627
becf5d5187cc
renamed raw "explode" function to "raw_explode" to emphasize its meaning;
wenzelm
parents:
40523
diff
changeset
|
214 |
if exists_string (not o raw_chr) str then implode (encode (raw_explode str)) |
29324 | 215 |
else raw0 str |
216 |
end; |
|
14956
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
217 |
|
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
218 |
|
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
219 |
(* diagnostics *) |
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
220 |
|
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
221 |
fun beginning n cs = |
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
222 |
let |
33955 | 223 |
val drop_blanks = #1 o take_suffix is_ascii_blank; |
14956
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
224 |
val all_cs = drop_blanks cs; |
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
225 |
val dots = if length all_cs > n then " ..." else ""; |
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
226 |
in |
33955 | 227 |
(drop_blanks (take n all_cs) |
14956
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
228 |
|> map (fn c => if is_ascii_blank c then space else c) |
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
229 |
|> implode) ^ dots |
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
230 |
end; |
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
231 |
|
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
232 |
|
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
233 |
(* decode_raw *) |
14834 | 234 |
|
235 |
fun is_raw s = |
|
62877
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
wenzelm
parents:
62804
diff
changeset
|
236 |
String.isPrefix "\092<^raw" s andalso String.isSuffix ">" s; |
14834 | 237 |
|
238 |
fun decode_raw s = |
|
23676
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
239 |
if not (is_raw s) then error (malformed_msg s) |
62877
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
wenzelm
parents:
62804
diff
changeset
|
240 |
else if String.isPrefix "\092<^raw:" s then String.substring (s, 7, size s - 8) |
40627
becf5d5187cc
renamed raw "explode" function to "raw_explode" to emphasize its meaning;
wenzelm
parents:
40523
diff
changeset
|
241 |
else chr (#1 (Library.read_int (raw_explode (String.substring (s, 6, size s - 7))))); |
14834 | 242 |
|
243 |
||
14873 | 244 |
(* symbol variants *) |
245 |
||
37533
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents:
34095
diff
changeset
|
246 |
datatype sym = |
61475 | 247 |
Char of string | UTF8 of string | Sym of string | Control of string | Raw of string | |
43485 | 248 |
Malformed of string | EOF; |
14873 | 249 |
|
250 |
fun decode s = |
|
43485 | 251 |
if s = "" then EOF |
252 |
else if is_char s then Char s |
|
37533
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents:
34095
diff
changeset
|
253 |
else if is_utf8 s then UTF8 s |
14873 | 254 |
else if is_raw s then Raw (decode_raw s) |
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
40509
diff
changeset
|
255 |
else if is_malformed s then Malformed s |
61475 | 256 |
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:
40509
diff
changeset
|
257 |
else Sym (String.substring (s, 2, size s - 3)); |
14873 | 258 |
|
259 |
||
14678 | 260 |
(* standard symbol kinds *) |
261 |
||
14171
0cab06e3bbd0
Extended the notion of letter and digit, such that now one may use greek,
skalberg
parents:
13730
diff
changeset
|
262 |
local |
50235 | 263 |
val letter_symbols = |
264 |
Symtab.make_set [ |
|
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
265 |
"\<A>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
266 |
"\<B>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
267 |
"\<C>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
268 |
"\<D>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
269 |
"\<E>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
270 |
"\<F>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
271 |
"\<G>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
272 |
"\<H>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
273 |
"\<I>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
274 |
"\<J>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
275 |
"\<K>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
276 |
"\<L>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
277 |
"\<M>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
278 |
"\<N>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
279 |
"\<O>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
280 |
"\<P>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
281 |
"\<Q>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
282 |
"\<R>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
283 |
"\<S>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
284 |
"\<T>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
285 |
"\<U>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
286 |
"\<V>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
287 |
"\<W>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
288 |
"\<X>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
289 |
"\<Y>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
290 |
"\<Z>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
291 |
"\<a>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
292 |
"\<b>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
293 |
"\<c>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
294 |
"\<d>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
295 |
"\<e>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
296 |
"\<f>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
297 |
"\<g>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
298 |
"\<h>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
299 |
"\<i>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
300 |
"\<j>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
301 |
"\<k>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
302 |
"\<l>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
303 |
"\<m>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
304 |
"\<n>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
305 |
"\<o>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
306 |
"\<p>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
307 |
"\<q>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
308 |
"\<r>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
309 |
"\<s>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
310 |
"\<t>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
311 |
"\<u>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
312 |
"\<v>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
313 |
"\<w>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
314 |
"\<x>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
315 |
"\<y>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
316 |
"\<z>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
317 |
"\<AA>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
318 |
"\<BB>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
319 |
"\<CC>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
320 |
"\<DD>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
321 |
"\<EE>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
322 |
"\<FF>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
323 |
"\<GG>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
324 |
"\<HH>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
325 |
"\<II>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
326 |
"\<JJ>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
327 |
"\<KK>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
328 |
"\<LL>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
329 |
"\<MM>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
330 |
"\<NN>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
331 |
"\<OO>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
332 |
"\<PP>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
333 |
"\<QQ>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
334 |
"\<RR>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
335 |
"\<SS>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
336 |
"\<TT>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
337 |
"\<UU>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
338 |
"\<VV>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
339 |
"\<WW>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
340 |
"\<XX>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
341 |
"\<YY>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
342 |
"\<ZZ>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
343 |
"\<aa>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
344 |
"\<bb>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
345 |
"\<cc>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
346 |
"\<dd>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
347 |
"\<ee>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
348 |
"\<ff>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
349 |
"\<gg>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
350 |
"\<hh>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
351 |
"\<ii>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
352 |
"\<jj>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
353 |
"\<kk>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
354 |
"\<ll>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
355 |
"\<mm>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
356 |
"\<nn>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
357 |
"\<oo>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
358 |
"\<pp>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
359 |
"\<qq>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
360 |
"\<rr>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
361 |
"\<ss>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
362 |
"\<tt>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
363 |
"\<uu>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
364 |
"\<vv>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
365 |
"\<ww>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
366 |
"\<xx>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
367 |
"\<yy>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
368 |
"\<zz>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
369 |
"\<alpha>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
370 |
"\<beta>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
371 |
"\<gamma>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
372 |
"\<delta>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
373 |
"\<epsilon>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
374 |
"\<zeta>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
375 |
"\<eta>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
376 |
"\<theta>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
377 |
"\<iota>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
378 |
"\<kappa>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
379 |
(*"\<lambda>", sic!*) |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
380 |
"\<mu>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
381 |
"\<nu>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
382 |
"\<xi>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
383 |
"\<pi>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
384 |
"\<rho>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
385 |
"\<sigma>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
386 |
"\<tau>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
387 |
"\<upsilon>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
388 |
"\<phi>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
389 |
"\<chi>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
390 |
"\<psi>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
391 |
"\<omega>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
392 |
"\<Gamma>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
393 |
"\<Delta>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
394 |
"\<Theta>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
395 |
"\<Lambda>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
396 |
"\<Xi>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
397 |
"\<Pi>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
398 |
"\<Sigma>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
399 |
"\<Upsilon>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
400 |
"\<Phi>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
401 |
"\<Psi>", |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
402 |
"\<Omega>" |
50235 | 403 |
]; |
14171
0cab06e3bbd0
Extended the notion of letter and digit, such that now one may use greek,
skalberg
parents:
13730
diff
changeset
|
404 |
in |
50242
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
405 |
|
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
406 |
val is_letter_symbol = Symtab.defined letter_symbols; |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
407 |
|
14678 | 408 |
end; |
14173 | 409 |
|
50242
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
410 |
datatype kind = Letter | Digit | Quasi | Blank | Other; |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
411 |
|
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
412 |
fun kind s = |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
413 |
if is_ascii_letter s then Letter |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
414 |
else if is_ascii_digit s then Digit |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
415 |
else if is_ascii_quasi s then Quasi |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
416 |
else if is_ascii_blank s then Blank |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
417 |
else if is_char s then Other |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
418 |
else if is_letter_symbol s then Letter |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
419 |
else Other; |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
420 |
|
14678 | 421 |
fun is_letter s = kind s = Letter; |
422 |
fun is_digit s = kind s = Digit; |
|
423 |
fun is_quasi s = kind s = Quasi; |
|
424 |
fun is_blank s = kind s = Blank; |
|
6272 | 425 |
|
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
426 |
val is_block_ctrl = member (op =) ["\<^bsub>", "\<^esub>", "\<^bsup>", "\<^esup>"]; |
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:
43947
diff
changeset
|
427 |
|
14678 | 428 |
fun is_quasi_letter s = let val k = kind s in k = Letter orelse k = Quasi end; |
429 |
fun is_letdig s = let val k = kind s in k = Letter orelse k = Digit orelse k = Quasi end; |
|
11010 | 430 |
|
6272 | 431 |
|
432 |
||
14678 | 433 |
(** symbol input **) |
434 |
||
23676
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
435 |
(* source *) |
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
436 |
|
14678 | 437 |
local |
14561
c53396af770e
* raw control symbols are of the form \<^raw:...> now.
schirmer
parents:
14559
diff
changeset
|
438 |
|
37533
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents:
34095
diff
changeset
|
439 |
fun is_plain s = is_ascii s andalso s <> "\^M" andalso s <> "\\"; |
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents:
34095
diff
changeset
|
440 |
|
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents:
34095
diff
changeset
|
441 |
fun is_utf8_trailer s = is_char s andalso 128 <= ord s andalso ord s < 192; |
23676
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
442 |
|
37728
5d2b3e827371
implode pseudo utf8, i.e. decode byte-stuffed low ASCII characters;
wenzelm
parents:
37534
diff
changeset
|
443 |
fun implode_pseudo_utf8 (cs as ["\192", c]) = |
5d2b3e827371
implode pseudo utf8, i.e. decode byte-stuffed low ASCII characters;
wenzelm
parents:
37534
diff
changeset
|
444 |
if ord c < 160 then chr (ord c - 128) else implode cs |
5d2b3e827371
implode pseudo utf8, i.e. decode byte-stuffed low ASCII characters;
wenzelm
parents:
37534
diff
changeset
|
445 |
| implode_pseudo_utf8 cs = implode cs; |
5d2b3e827371
implode pseudo utf8, i.e. decode byte-stuffed low ASCII characters;
wenzelm
parents:
37534
diff
changeset
|
446 |
|
14678 | 447 |
val scan_encoded_newline = |
17756 | 448 |
$$ "\^M" -- $$ "\n" >> K "\n" || |
54734
b91afc3aa3e6
clarified Proof General legacy: special treatment of \<^newline> only in TTY mode;
wenzelm
parents:
54732
diff
changeset
|
449 |
$$ "\^M" >> K "\n"; |
14956
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
450 |
|
70ec4b8aef8d
prevent looping of error messages involving malformed symbols;
wenzelm
parents:
14908
diff
changeset
|
451 |
val scan_raw = |
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
21495
diff
changeset
|
452 |
Scan.this_string "raw:" ^^ (Scan.many raw_chr >> implode) || |
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
21495
diff
changeset
|
453 |
Scan.this_string "raw" ^^ (Scan.many1 is_ascii_digit >> implode); |
14678 | 454 |
|
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
40509
diff
changeset
|
455 |
val scan_total = |
23676
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
456 |
Scan.one is_plain || |
37728
5d2b3e827371
implode pseudo utf8, i.e. decode byte-stuffed low ASCII characters;
wenzelm
parents:
37534
diff
changeset
|
457 |
Scan.one is_utf8 ::: Scan.many is_utf8_trailer >> implode_pseudo_utf8 || |
23676
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
458 |
scan_encoded_newline || |
48773
0e1bab274672
more liberal scanning of potentially malformed symbols;
wenzelm
parents:
48704
diff
changeset
|
459 |
($$ "\\" ^^ $$ "<" ^^ |
50236 | 460 |
(($$ "^" ^^ Scan.optional (scan_raw || scan_ascii_id) "" || Scan.optional scan_ascii_id "") ^^ |
48774 | 461 |
Scan.optional ($$ ">") "")) || |
23676
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
462 |
Scan.one not_eof; |
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
463 |
|
14678 | 464 |
in |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
465 |
|
58864 | 466 |
fun source src = Source.source stopper (Scan.bulk scan_total) src; |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
467 |
|
14678 | 468 |
end; |
469 |
||
14562
980da32f4617
proper handling of lines terminated by CRLF or CR;
wenzelm
parents:
14561
diff
changeset
|
470 |
|
23676
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
471 |
(* explode *) |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
472 |
|
23676
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
473 |
local |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
474 |
|
14562
980da32f4617
proper handling of lines terminated by CRLF or CR;
wenzelm
parents:
14561
diff
changeset
|
475 |
fun no_explode [] = true |
980da32f4617
proper handling of lines terminated by CRLF or CR;
wenzelm
parents:
14561
diff
changeset
|
476 |
| no_explode ("\\" :: "<" :: _) = false |
17756 | 477 |
| no_explode ("\^M" :: _) = false |
37533
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents:
34095
diff
changeset
|
478 |
| no_explode (c :: cs) = is_ascii c andalso no_explode cs; |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
479 |
|
23676
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
480 |
in |
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
481 |
|
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
482 |
fun sym_explode str = |
40627
becf5d5187cc
renamed raw "explode" function to "raw_explode" to emphasize its meaning;
wenzelm
parents:
40523
diff
changeset
|
483 |
let val chs = raw_explode str in |
14562
980da32f4617
proper handling of lines terminated by CRLF or CR;
wenzelm
parents:
14561
diff
changeset
|
484 |
if no_explode chs then chs |
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
40509
diff
changeset
|
485 |
else Source.exhaust (source (Source.of_list chs)) |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
486 |
end; |
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
487 |
|
23676
ea9b7e9c2301
scan: changed treatment of malformed symbols, passed to next stage;
wenzelm
parents:
23618
diff
changeset
|
488 |
end; |
14994 | 489 |
|
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
490 |
|
50237 | 491 |
(* escape *) |
492 |
||
493 |
val esc = fn s => |
|
494 |
if is_char s then s |
|
495 |
else if is_utf8 s then translate_string (fn c => "\\" ^ string_of_int (ord c)) s |
|
496 |
else "\\" ^ s; |
|
497 |
||
498 |
val escape = implode o map esc o sym_explode; |
|
499 |
||
500 |
||
501 |
||
502 |
(** scanning through symbols **) |
|
503 |
||
504 |
(* scanner *) |
|
505 |
||
506 |
fun scanner msg scan syms = |
|
507 |
let |
|
508 |
fun message (ss, NONE) = (fn () => msg ^ ": " ^ quote (beginning 10 ss)) |
|
509 |
| message (ss, SOME msg') = (fn () => msg ^ ", " ^ msg' () ^ ": " ^ quote (beginning 10 ss)); |
|
510 |
val finite_scan = Scan.error (Scan.finite stopper (!! message scan)); |
|
511 |
in |
|
512 |
(case finite_scan syms of |
|
513 |
(result, []) => result |
|
514 |
| (_, rest) => error (message (rest, NONE) ())) |
|
515 |
end; |
|
516 |
||
517 |
||
50162 | 518 |
(* space-separated words *) |
519 |
||
520 |
val scan_word = |
|
521 |
Scan.many1 is_ascii_blank >> K NONE || |
|
522 |
Scan.many1 (fn s => not (is_ascii_blank s) andalso not_eof s) >> (SOME o implode); |
|
523 |
||
524 |
val split_words = scanner "Bad text" (Scan.repeat scan_word >> map_filter I); |
|
525 |
||
526 |
val explode_words = split_words o sym_explode; |
|
527 |
||
528 |
||
14678 | 529 |
(* blanks *) |
530 |
||
61707 | 531 |
val trim_blanks = sym_explode #> trim is_blank #> implode; |
14678 | 532 |
|
533 |
||
534 |
(* bump string -- treat as base 26 or base 1 numbers *) |
|
535 |
||
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62210
diff
changeset
|
536 |
fun symbolic_end (_ :: "\<^sub>" :: _) = true |
53198
06b096cf89ca
ignore trailing primes, e.g. rename \<alpha>' to \<alpha>'' instead of \<alpha>'a;
wenzelm
parents:
53016
diff
changeset
|
537 |
| symbolic_end ("'" :: ss) = symbolic_end ss |
55033 | 538 |
| symbolic_end (s :: _) = raw_symbolic s |
14908 | 539 |
| symbolic_end [] = false; |
14678 | 540 |
|
541 |
fun bump_init str = |
|
14908 | 542 |
if symbolic_end (rev (sym_explode str)) then str ^ "'" |
14678 | 543 |
else str ^ "a"; |
12904 | 544 |
|
545 |
fun bump_string str = |
|
546 |
let |
|
547 |
fun bump [] = ["a"] |
|
548 |
| bump ("z" :: ss) = "a" :: bump ss |
|
549 |
| bump (s :: ss) = |
|
14678 | 550 |
if is_char s andalso ord "a" <= ord s andalso ord s < ord "z" |
12904 | 551 |
then chr (ord s + 1) :: ss |
552 |
else "a" :: s :: ss; |
|
14678 | 553 |
|
33955 | 554 |
val (ss, qs) = apfst rev (take_suffix is_quasi (sym_explode str)); |
14908 | 555 |
val ss' = if symbolic_end ss then "'" :: ss else bump ss; |
14678 | 556 |
in implode (rev ss' @ qs) end; |
557 |
||
12904 | 558 |
|
6272 | 559 |
|
29324 | 560 |
(** symbol output **) |
14977
77d88064991a
added escape, export encode_raw, default mode now trivial, tuned;
wenzelm
parents:
14961
diff
changeset
|
561 |
|
29324 | 562 |
(* length *) |
6272 | 563 |
|
14678 | 564 |
fun sym_len s = |
24593
1547ea587f5a
added some int constraints (ML_Parse.fix_ints not active here);
wenzelm
parents:
24580
diff
changeset
|
565 |
if not (is_printable s) then (0: int) |
62877
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
wenzelm
parents:
62804
diff
changeset
|
566 |
else if String.isPrefix "\092<long" s then 2 |
741560a5283b
avoid malformed Isabelle symbols during bootstrap;
wenzelm
parents:
62804
diff
changeset
|
567 |
else if String.isPrefix "\092<Long" s then 2 |
14678 | 568 |
else 1; |
569 |
||
19473 | 570 |
fun sym_length ss = fold (fn s => fn n => sym_len s + n) ss 0; |
14678 | 571 |
|
29324 | 572 |
|
573 |
(* print mode *) |
|
574 |
||
575 |
val xsymbolsN = "xsymbols"; |
|
576 |
||
577 |
fun output s = (s, sym_length (sym_explode s)); |
|
578 |
||
579 |
||
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
580 |
(*final declarations of this structure!*) |
29324 | 581 |
val explode = sym_explode; |
6272 | 582 |
val length = sym_length; |
6116
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
583 |
|
8ba2f25610f7
files scan.ML, source.ML, symbol.ML, pretty.ML moved to Pure/General;
wenzelm
parents:
diff
changeset
|
584 |
end; |