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