| author | blanchet | 
| Tue, 01 Apr 2014 10:51:29 +0200 | |
| changeset 56346 | 42533f8f4729 | 
| parent 55962 | fbd0e768bc8f | 
| child 58410 | 6d46ad54a2ab | 
| permissions | -rw-r--r-- | 
| 18 | 1 | (* Title: Pure/Syntax/lexicon.ML | 
| 2 | Author: Tobias Nipkow and Markus Wenzel, TU Muenchen | |
| 0 | 3 | |
| 4703 | 4 | Lexer for the inner Isabelle syntax (terms and types). | 
| 18 | 5 | *) | 
| 0 | 6 | |
| 42290 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 7 | signature LEXICON = | 
| 4247 
9bba9251bb4d
added implode_xstr: string list -> string, explode_xstr: string -> string list;
 wenzelm parents: 
3828diff
changeset | 8 | sig | 
| 42476 | 9 | structure Syntax: | 
| 10 | sig | |
| 11 | val const: string -> term | |
| 12 | val free: string -> term | |
| 13 | val var: indexname -> term | |
| 14 | end | |
| 30573 | 15 | val scan_id: Symbol_Pos.T list -> Symbol_Pos.T list * Symbol_Pos.T list | 
| 16 | val scan_longid: Symbol_Pos.T list -> Symbol_Pos.T list * Symbol_Pos.T list | |
| 17 | val scan_tid: Symbol_Pos.T list -> Symbol_Pos.T list * Symbol_Pos.T list | |
| 18 | val scan_nat: Symbol_Pos.T list -> Symbol_Pos.T list * Symbol_Pos.T list | |
| 19 | val scan_int: Symbol_Pos.T list -> Symbol_Pos.T list * Symbol_Pos.T list | |
| 40290 
47f572aff50a
support for floating-point tokens in outer syntax (coinciding with inner syntax version);
 wenzelm parents: 
39510diff
changeset | 20 | val scan_float: Symbol_Pos.T list -> Symbol_Pos.T list * Symbol_Pos.T list | 
| 30573 | 21 | val scan_hex: Symbol_Pos.T list -> Symbol_Pos.T list * Symbol_Pos.T list | 
| 22 | val scan_bin: Symbol_Pos.T list -> Symbol_Pos.T list * Symbol_Pos.T list | |
| 23 | val scan_var: Symbol_Pos.T list -> Symbol_Pos.T list * Symbol_Pos.T list | |
| 24 | val scan_tvar: Symbol_Pos.T list -> Symbol_Pos.T list * Symbol_Pos.T list | |
| 50239 | 25 | val is_tid: string -> bool | 
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 26 | datatype token_kind = | 
| 55108 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 27 | Literal | IdentSy | LongIdentSy | VarSy | TFreeSy | TVarSy | NumSy | | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 28 | FloatSy | XNumSy | StrSy | StringSy | Cartouche | Space | Comment | EOF | 
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 29 | datatype token = Token of token_kind * string * Position.range | 
| 27806 | 30 | val str_of_token: token -> string | 
| 31 | val pos_of_token: token -> Position.T | |
| 27887 | 32 | val is_proper: token -> bool | 
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 33 | val mk_eof: Position.T -> token | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 34 | val eof: token | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 35 | val is_eof: token -> bool | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 36 | val stopper: token Scan.stopper | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
164diff
changeset | 37 | val terminals: string list | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
164diff
changeset | 38 | val is_terminal: string -> bool | 
| 49821 
d15fe10593ff
clarified output token markup (see also bc22daeed49e);
 wenzelm parents: 
48992diff
changeset | 39 | val literal_markup: string -> Markup.T | 
| 44736 | 40 | val report_of_token: token -> Position.report | 
| 39510 
d9f5f01faa1b
Syntax.read_asts error: report token ranges within message -- no side-effect here;
 wenzelm parents: 
39507diff
changeset | 41 | val reported_token_range: Proof.context -> token -> string | 
| 18 | 42 | val matching_tokens: token * token -> bool | 
| 43 | val valued_token: token -> bool | |
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
164diff
changeset | 44 | val predef_term: string -> token option | 
| 55108 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 45 | val implode_string: Symbol.symbol list -> string | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 46 | val explode_string: string * Position.T -> Symbol_Pos.T list | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 47 | val implode_str: Symbol.symbol list -> string | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 48 | val explode_str: string * Position.T -> Symbol_Pos.T list | 
| 30573 | 49 | val tokenize: Scan.lexicon -> bool -> Symbol_Pos.T list -> token list | 
| 42290 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 50 | val read_indexname: string -> indexname | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 51 | val read_var: string -> term | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 52 | val read_variable: string -> indexname option | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 53 | val read_nat: string -> int option | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 54 | val read_int: string -> int option | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 55 |   val read_xnum: string -> {radix: int, leading_zeros: int, value: int}
 | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 56 |   val read_float: string -> {mant: int, exp: int}
 | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 57 | val mark_class: string -> string val unmark_class: string -> string | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 58 | val mark_type: string -> string val unmark_type: string -> string | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 59 | val mark_const: string -> string val unmark_const: string -> string | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 60 | val mark_fixed: string -> string val unmark_fixed: string -> string | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 61 | val unmark: | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 62 |    {case_class: string -> 'a,
 | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 63 | case_type: string -> 'a, | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 64 | case_const: string -> 'a, | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 65 | case_fixed: string -> 'a, | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 66 | case_default: string -> 'a} -> string -> 'a | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 67 | val is_marked: string -> bool | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 68 | val dummy_type: term | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 69 | val fun_type: term | 
| 4247 
9bba9251bb4d
added implode_xstr: string list -> string, explode_xstr: string -> string list;
 wenzelm parents: 
3828diff
changeset | 70 | end; | 
| 0 | 71 | |
| 14679 | 72 | structure Lexicon: LEXICON = | 
| 0 | 73 | struct | 
| 74 | ||
| 42476 | 75 | (** syntaxtic terms **) | 
| 76 | ||
| 77 | structure Syntax = | |
| 78 | struct | |
| 79 | ||
| 80 | fun const c = Const (c, dummyT); | |
| 81 | fun free x = Free (x, dummyT); | |
| 82 | fun var xi = Var (xi, dummyT); | |
| 83 | ||
| 84 | end; | |
| 85 | ||
| 86 | ||
| 87 | ||
| 4703 | 88 | (** basic scanners **) | 
| 89 | ||
| 30573 | 90 | open Basic_Symbol_Pos; | 
| 27773 | 91 | |
| 55105 | 92 | val err_prefix = "Inner lexical error: "; | 
| 93 | ||
| 94 | fun !!! msg = Symbol_Pos.!!! (fn () => err_prefix ^ msg); | |
| 27773 | 95 | |
| 50239 | 96 | val scan_id = Symbol_Pos.scan_ident; | 
| 27773 | 97 | val scan_longid = scan_id @@@ (Scan.repeat1 ($$$ "." @@@ scan_id) >> flat); | 
| 98 | val scan_tid = $$$ "'" @@@ scan_id; | |
| 4703 | 99 | |
| 40525 
14a2e686bdac
eliminated slightly odd pervasive Symbol_Pos.symbol;
 wenzelm parents: 
40290diff
changeset | 100 | val scan_nat = Scan.many1 (Symbol.is_digit o Symbol_Pos.symbol); | 
| 27773 | 101 | val scan_int = $$$ "-" @@@ scan_nat || scan_nat; | 
| 28904 | 102 | val scan_natdot = scan_nat @@@ $$$ "." @@@ scan_nat; | 
| 103 | val scan_float = $$$ "-" @@@ scan_natdot || scan_natdot; | |
| 40525 
14a2e686bdac
eliminated slightly odd pervasive Symbol_Pos.symbol;
 wenzelm parents: 
40290diff
changeset | 104 | val scan_hex = $$$ "0" @@@ $$$ "x" @@@ Scan.many1 (Symbol.is_ascii_hex o Symbol_Pos.symbol); | 
| 27773 | 105 | val scan_bin = $$$ "0" @@@ $$$ "b" @@@ Scan.many1 (fn (s, _) => s = "0" orelse s = "1"); | 
| 4703 | 106 | |
| 27773 | 107 | val scan_id_nat = scan_id @@@ Scan.optional ($$$ "." @@@ scan_nat) []; | 
| 108 | val scan_var = $$$ "?" @@@ scan_id_nat; | |
| 109 | val scan_tvar = $$$ "?" @@@ $$$ "'" @@@ scan_id_nat; | |
| 4703 | 110 | |
| 50239 | 111 | fun is_tid s = | 
| 112 | (case try (unprefix "'") s of | |
| 113 | SOME s' => Symbol_Pos.is_identifier s' | |
| 114 | | NONE => false); | |
| 115 | ||
| 4703 | 116 | |
| 117 | ||
| 18 | 118 | (** datatype token **) | 
| 0 | 119 | |
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 120 | datatype token_kind = | 
| 55108 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 121 | Literal | IdentSy | LongIdentSy | VarSy | TFreeSy | TVarSy | NumSy | | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 122 | FloatSy | XNumSy | StrSy | StringSy | Cartouche | Space | Comment | EOF; | 
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 123 | |
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 124 | datatype token = Token of token_kind * string * Position.range; | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 125 | |
| 27806 | 126 | fun str_of_token (Token (_, s, _)) = s; | 
| 127 | fun pos_of_token (Token (_, _, (pos, _))) = pos; | |
| 128 | ||
| 27887 | 129 | fun is_proper (Token (Space, _, _)) = false | 
| 130 | | is_proper (Token (Comment, _, _)) = false | |
| 131 | | is_proper _ = true; | |
| 132 | ||
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 133 | |
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 134 | (* stopper *) | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 135 | |
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 136 | fun mk_eof pos = Token (EOF, "", (pos, Position.none)); | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 137 | val eof = mk_eof Position.none; | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 138 | |
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 139 | fun is_eof (Token (EOF, _, _)) = true | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 140 | | is_eof _ = false; | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 141 | |
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 142 | val stopper = Scan.stopper (K eof) is_eof; | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 143 | |
| 0 | 144 | |
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
164diff
changeset | 145 | (* terminal arguments *) | 
| 0 | 146 | |
| 29156 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 147 | val terminal_kinds = | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 148 |  [("id", IdentSy),
 | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 149 |   ("longid", LongIdentSy),
 | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 150 |   ("var", VarSy),
 | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 151 |   ("tid", TFreeSy),
 | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 152 |   ("tvar", TVarSy),
 | 
| 45703 
c7a13ce60161
renamed inner syntax categories "num" to "num_token" and "xnum" to "xnum_token";
 wenzelm parents: 
45666diff
changeset | 153 |   ("num_token", NumSy),
 | 
| 29156 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 154 |   ("float_token", FloatSy),
 | 
| 45703 
c7a13ce60161
renamed inner syntax categories "num" to "num_token" and "xnum" to "xnum_token";
 wenzelm parents: 
45666diff
changeset | 155 |   ("xnum_token", XNumSy),
 | 
| 55033 | 156 |   ("str_token", StrSy),
 | 
| 55108 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 157 |   ("string_token", StringSy),
 | 
| 55033 | 158 |   ("cartouche", Cartouche)];
 | 
| 29156 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 159 | |
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 160 | val terminals = map #1 terminal_kinds; | 
| 20664 | 161 | val is_terminal = member (op =) terminals; | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
164diff
changeset | 162 | |
| 0 | 163 | |
| 27887 | 164 | (* markup *) | 
| 165 | ||
| 49821 
d15fe10593ff
clarified output token markup (see also bc22daeed49e);
 wenzelm parents: 
48992diff
changeset | 166 | fun literal_markup s = | 
| 52189 | 167 | if Symbol.is_ascii_identifier s orelse exists Symbol.is_letter (Symbol.explode s) | 
| 168 | then Markup.literal | |
| 169 | else Markup.delimiter; | |
| 49821 
d15fe10593ff
clarified output token markup (see also bc22daeed49e);
 wenzelm parents: 
48992diff
changeset | 170 | |
| 27887 | 171 | val token_kind_markup = | 
| 51612 
6a1e40f9dd55
added var_position in analogy to longid_position, for typing reports on input;
 wenzelm parents: 
50242diff
changeset | 172 | fn TFreeSy => Markup.tfree | 
| 55033 | 173 | | TVarSy => Markup.tvar | 
| 174 | | NumSy => Markup.numeral | |
| 50201 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 wenzelm parents: 
49821diff
changeset | 175 | | FloatSy => Markup.numeral | 
| 55033 | 176 | | XNumSy => Markup.numeral | 
| 177 | | StrSy => Markup.inner_string | |
| 55108 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 178 | | StringSy => Markup.inner_string | 
| 55033 | 179 | | Cartouche => Markup.inner_cartouche | 
| 50201 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 wenzelm parents: 
49821diff
changeset | 180 | | Comment => Markup.inner_comment | 
| 55033 | 181 | | _ => Markup.empty; | 
| 27887 | 182 | |
| 44736 | 183 | fun report_of_token (Token (kind, s, (pos, _))) = | 
| 49821 
d15fe10593ff
clarified output token markup (see also bc22daeed49e);
 wenzelm parents: 
48992diff
changeset | 184 | let val markup = if kind = Literal then literal_markup s else token_kind_markup kind | 
| 44736 | 185 | in (pos, markup) end; | 
| 27887 | 186 | |
| 39510 
d9f5f01faa1b
Syntax.read_asts error: report token ranges within message -- no side-effect here;
 wenzelm parents: 
39507diff
changeset | 187 | fun reported_token_range ctxt tok = | 
| 39168 
e3ac771235f7
report token range after inner parse error -- often provides important clues about misunderstanding concerning lexical phase;
 wenzelm parents: 
38474diff
changeset | 188 | if is_proper tok | 
| 50201 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 wenzelm parents: 
49821diff
changeset | 189 | then Context_Position.reported_text ctxt (pos_of_token tok) Markup.token_range "" | 
| 39510 
d9f5f01faa1b
Syntax.read_asts error: report token ranges within message -- no side-effect here;
 wenzelm parents: 
39507diff
changeset | 190 | else ""; | 
| 39168 
e3ac771235f7
report token range after inner parse error -- often provides important clues about misunderstanding concerning lexical phase;
 wenzelm parents: 
38474diff
changeset | 191 | |
| 27887 | 192 | |
| 18 | 193 | (* matching_tokens *) | 
| 0 | 194 | |
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 195 | fun matching_tokens (Token (Literal, x, _), Token (Literal, y, _)) = x = y | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 196 | | matching_tokens (Token (k, _, _), Token (k', _, _)) = k = k'; | 
| 0 | 197 | |
| 198 | ||
| 18 | 199 | (* valued_token *) | 
| 0 | 200 | |
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 201 | fun valued_token (Token (Literal, _, _)) = false | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 202 | | valued_token (Token (EOF, _, _)) = false | 
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 203 | | valued_token _ = true; | 
| 0 | 204 | |
| 205 | ||
| 18 | 206 | (* predef_term *) | 
| 0 | 207 | |
| 29156 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 208 | fun predef_term s = | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 209 | (case AList.lookup (op =) terminal_kinds s of | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 210 | SOME sy => SOME (Token (sy, s, Position.no_range)) | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 211 | | NONE => NONE); | 
| 0 | 212 | |
| 213 | ||
| 55108 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 214 | |
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 215 | (** string literals **) | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 216 | |
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 217 | fun explode_literal scan_body (str, pos) = | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 218 | (case Scan.read Symbol_Pos.stopper scan_body (Symbol_Pos.explode (str, pos)) of | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 219 | SOME ss => ss | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 220 | | _ => error (err_prefix ^ "malformed string literal " ^ quote str ^ Position.here pos)); | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 221 | |
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 222 | |
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 223 | (* string *) | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 224 | |
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 225 | val scan_string = Scan.trace (Symbol_Pos.scan_string_qq err_prefix) >> #2; | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 226 | val scan_string_body = Symbol_Pos.scan_string_qq err_prefix >> (#1 o #2); | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 227 | |
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 228 | fun implode_string ss = quote (implode (map (fn "\"" => "\\\"" | s => s) ss)); | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 229 | val explode_string = explode_literal scan_string_body; | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 230 | |
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 231 | |
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 232 | (* str *) | 
| 18 | 233 | |
| 14730 | 234 | val scan_chr = | 
| 55107 | 235 | $$ "\\" |-- $$$ "'" || | 
| 40525 
14a2e686bdac
eliminated slightly odd pervasive Symbol_Pos.symbol;
 wenzelm parents: 
40290diff
changeset | 236 | Scan.one | 
| 
14a2e686bdac
eliminated slightly odd pervasive Symbol_Pos.symbol;
 wenzelm parents: 
40290diff
changeset | 237 | ((fn s => s <> "\\" andalso s <> "'" andalso Symbol.is_regular s) o | 
| 
14a2e686bdac
eliminated slightly odd pervasive Symbol_Pos.symbol;
 wenzelm parents: 
40290diff
changeset | 238 | Symbol_Pos.symbol) >> single || | 
| 55107 | 239 | $$$ "'" --| Scan.ahead (~$$ "'"); | 
| 14730 | 240 | |
| 241 | val scan_str = | |
| 55106 | 242 | Scan.ahead ($$ "'" -- $$ "'") |-- | 
| 243 | !!! "unclosed string literal" | |
| 244 | ($$$ "'" @@@ $$$ "'" @@@ (Scan.repeat scan_chr >> flat) @@@ $$$ "'" @@@ $$$ "'"); | |
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 245 | |
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 246 | val scan_str_body = | 
| 55107 | 247 | Scan.ahead ($$ "'" |-- $$ "'") |-- | 
| 55106 | 248 | !!! "unclosed string literal" | 
| 249 | ($$ "'" |-- $$ "'" |-- (Scan.repeat scan_chr >> flat) --| $$ "'" --| $$ "'"); | |
| 14730 | 250 | |
| 55108 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 251 | fun implode_str ss = enclose "''" "''" (implode (map (fn "'" => "\\'" | s => s) ss)); | 
| 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 252 | val explode_str = explode_literal scan_str_body; | 
| 18 | 253 | |
| 254 | ||
| 27806 | 255 | |
| 18 | 256 | (** tokenize **) | 
| 257 | ||
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 258 | fun token_leq (Token (_, s1, _), Token (_, s2, _)) = s1 <= s2; | 
| 30573 | 259 | fun token kind ss = Token (kind, Symbol_Pos.content ss, Symbol_Pos.range ss); | 
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 260 | |
| 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 261 | fun tokenize lex xids syms = | 
| 18 | 262 | let | 
| 263 | val scan_xid = | |
| 55962 
fbd0e768bc8f
special identifier "__" (i.e. empty name with internal suffix) serves as wild-card for completion;
 wenzelm parents: 
55624diff
changeset | 264 | (if xids then $$$ "_" @@@ scan_id || scan_id else scan_id) || | 
| 
fbd0e768bc8f
special identifier "__" (i.e. empty name with internal suffix) serves as wild-card for completion;
 wenzelm parents: 
55624diff
changeset | 265 | $$$ "_" @@@ $$$ "_"; | 
| 18 | 266 | |
| 20096 | 267 | val scan_num = scan_hex || scan_bin || scan_int; | 
| 268 | ||
| 550 
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
 wenzelm parents: 
376diff
changeset | 269 | val scan_val = | 
| 26007 
3760d3ff4cce
basic scanners: produce symbol list instead of imploded string;
 wenzelm parents: 
24630diff
changeset | 270 | scan_tvar >> token TVarSy || | 
| 
3760d3ff4cce
basic scanners: produce symbol list instead of imploded string;
 wenzelm parents: 
24630diff
changeset | 271 | scan_var >> token VarSy || | 
| 
3760d3ff4cce
basic scanners: produce symbol list instead of imploded string;
 wenzelm parents: 
24630diff
changeset | 272 | scan_tid >> token TFreeSy || | 
| 28904 | 273 | scan_float >> token FloatSy || | 
| 26007 
3760d3ff4cce
basic scanners: produce symbol list instead of imploded string;
 wenzelm parents: 
24630diff
changeset | 274 | scan_num >> token NumSy || | 
| 27773 | 275 | $$$ "#" @@@ scan_num >> token XNumSy || | 
| 26007 
3760d3ff4cce
basic scanners: produce symbol list instead of imploded string;
 wenzelm parents: 
24630diff
changeset | 276 | scan_longid >> token LongIdentSy || | 
| 
3760d3ff4cce
basic scanners: produce symbol list instead of imploded string;
 wenzelm parents: 
24630diff
changeset | 277 | scan_xid >> token IdentSy; | 
| 18 | 278 | |
| 27800 
df444ddeff56
datatype token: maintain range, tuned representation;
 wenzelm parents: 
27773diff
changeset | 279 | val scan_lit = Scan.literal lex >> token Literal; | 
| 550 
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
 wenzelm parents: 
376diff
changeset | 280 | |
| 4703 | 281 | val scan_token = | 
| 55105 | 282 | Symbol_Pos.scan_cartouche err_prefix >> token Cartouche || | 
| 283 | Symbol_Pos.scan_comment err_prefix >> token Comment || | |
| 27887 | 284 | Scan.max token_leq scan_lit scan_val || | 
| 55108 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 285 | scan_string >> token StringSy || | 
| 27887 | 286 | scan_str >> token StrSy || | 
| 40525 
14a2e686bdac
eliminated slightly odd pervasive Symbol_Pos.symbol;
 wenzelm parents: 
40290diff
changeset | 287 | Scan.many1 (Symbol.is_blank o Symbol_Pos.symbol) >> token Space; | 
| 18 | 288 | in | 
| 27773 | 289 | (case Scan.error | 
| 30573 | 290 | (Scan.finite Symbol_Pos.stopper (Scan.repeat scan_token)) syms of | 
| 27887 | 291 | (toks, []) => toks | 
| 55108 
0b7a0c1fdf7e
inner syntax token language allows regular quoted strings;
 wenzelm parents: 
55107diff
changeset | 292 | | (_, ss) => | 
| 55624 | 293 |         error ("Inner lexical error" ^ Position.here (#1 (Symbol_Pos.range ss)) ^
 | 
| 294 |           Markup.markup Markup.no_report ("\nat " ^ quote (Symbol_Pos.content ss))))
 | |
| 295 | ||
| 18 | 296 | end; | 
| 297 | ||
| 298 | ||
| 299 | ||
| 300 | (** scan variables **) | |
| 301 | ||
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 302 | (* scan_indexname *) | 
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 303 | |
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 304 | local | 
| 18 | 305 | |
| 27773 | 306 | val scan_vname = | 
| 18 | 307 | let | 
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 308 | fun nat n [] = n | 
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 309 | | nat n (c :: cs) = nat (n * 10 + (ord c - ord "0")) cs; | 
| 18 | 310 | |
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 311 | fun idxname cs ds = (implode (rev cs), nat 0 ds); | 
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 312 | fun chop_idx [] ds = idxname [] ds | 
| 50242 
56b9c792a98b
support for sub-structured identifier syntax (inactive);
 wenzelm parents: 
50239diff
changeset | 313 | | chop_idx (cs as (_ :: "\\<^sub>" :: _)) ds = idxname cs ds | 
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 314 | | chop_idx (c :: cs) ds = | 
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 315 | if Symbol.is_digit c then chop_idx cs (c :: ds) | 
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 316 | else idxname (c :: cs) ds; | 
| 18 | 317 | |
| 50239 | 318 | val scan = | 
| 319 | (scan_id >> map Symbol_Pos.symbol) -- | |
| 55107 | 320 | Scan.optional ($$ "." |-- scan_nat >> (nat 0 o map Symbol_Pos.symbol)) ~1; | 
| 18 | 321 | in | 
| 27773 | 322 | scan >> | 
| 323 | (fn (cs, ~1) => chop_idx (rev cs) [] | |
| 324 | | (cs, i) => (implode cs, i)) | |
| 18 | 325 | end; | 
| 326 | ||
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 327 | in | 
| 18 | 328 | |
| 55107 | 329 | val scan_indexname = $$ "'" |-- scan_vname >> (fn (x, i) => ("'" ^ x, i)) || scan_vname;
 | 
| 15443 
07f78cc82a73
indexname function now parses type variables as well; changed input
 berghofe parents: 
14981diff
changeset | 330 | |
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 331 | end; | 
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 332 | |
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 333 | |
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 334 | (* indexname *) | 
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 335 | |
| 20313 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 336 | fun read_indexname s = | 
| 30573 | 337 | (case Scan.read Symbol_Pos.stopper scan_indexname (Symbol_Pos.explode (s, Position.none)) of | 
| 15531 | 338 | SOME xi => xi | 
| 20313 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 339 |   | _ => error ("Lexical error in variable name: " ^ quote s));
 | 
| 18 | 340 | |
| 341 | ||
| 4703 | 342 | (* read_var *) | 
| 18 | 343 | |
| 4703 | 344 | fun read_var str = | 
| 18 | 345 | let | 
| 346 | val scan = | |
| 55107 | 347 | $$ "?" |-- scan_indexname --| Scan.ahead (Scan.one Symbol_Pos.is_eof) | 
| 42476 | 348 | >> Syntax.var || | 
| 349 | Scan.many (Symbol.is_regular o Symbol_Pos.symbol) | |
| 350 | >> (Syntax.free o implode o map Symbol_Pos.symbol); | |
| 30573 | 351 | in the (Scan.read Symbol_Pos.stopper scan (Symbol_Pos.explode (str, Position.none))) end; | 
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 352 | |
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 353 | |
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 354 | (* read_variable *) | 
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 355 | |
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 356 | fun read_variable str = | 
| 55107 | 357 | let val scan = $$ "?" |-- scan_indexname || scan_indexname | 
| 30573 | 358 | in Scan.read Symbol_Pos.stopper scan (Symbol_Pos.explode (str, Position.none)) end; | 
| 4587 | 359 | |
| 360 | ||
| 20313 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 361 | (* read numbers *) | 
| 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 362 | |
| 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 363 | local | 
| 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 364 | |
| 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 365 | fun nat cs = | 
| 40525 
14a2e686bdac
eliminated slightly odd pervasive Symbol_Pos.symbol;
 wenzelm parents: 
40290diff
changeset | 366 | Option.map (#1 o Library.read_int o map Symbol_Pos.symbol) | 
| 30573 | 367 | (Scan.read Symbol_Pos.stopper scan_nat cs); | 
| 5860 | 368 | |
| 20313 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 369 | in | 
| 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 370 | |
| 30573 | 371 | fun read_nat s = nat (Symbol_Pos.explode (s, Position.none)); | 
| 20313 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 372 | |
| 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 373 | fun read_int s = | 
| 30573 | 374 | (case Symbol_Pos.explode (s, Position.none) of | 
| 27773 | 375 |     ("-", _) :: cs => Option.map ~ (nat cs)
 | 
| 20313 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 376 | | cs => nat cs); | 
| 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 377 | |
| 
bf9101cc4385
renamed Syntax.indexname to Syntax.read_indexname;
 wenzelm parents: 
20165diff
changeset | 378 | end; | 
| 5860 | 379 | |
| 380 | ||
| 20096 | 381 | (* read_xnum: hex/bin/decimal *) | 
| 9326 | 382 | |
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 383 | local | 
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 384 | |
| 20096 | 385 | val ten = ord "0" + 10; | 
| 386 | val a = ord "a"; | |
| 387 | val A = ord "A"; | |
| 35428 | 388 | val _ = a > A orelse raise Fail "Bad ASCII"; | 
| 20096 | 389 | |
| 390 | fun remap_hex c = | |
| 391 | let val x = ord c in | |
| 392 | if x >= a then chr (x - a + ten) | |
| 393 | else if x >= A then chr (x - A + ten) | |
| 394 | else c | |
| 395 | end; | |
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 396 | |
| 21781 | 397 | fun leading_zeros ["0"] = 0 | 
| 398 |   | leading_zeros ("0" :: cs) = 1 + leading_zeros cs
 | |
| 399 | | leading_zeros _ = 0; | |
| 400 | ||
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 401 | in | 
| 15965 
f422f8283491
Use of IntInf.int instead of int in most numeric simprocs; avoids
 paulson parents: 
15570diff
changeset | 402 | |
| 9326 | 403 | fun read_xnum str = | 
| 404 | let | |
| 20096 | 405 | val (sign, radix, digs) = | 
| 406 | (case Symbol.explode (perhaps (try (unprefix "#")) str) of | |
| 407 | "0" :: "x" :: cs => (1, 16, map remap_hex cs) | |
| 408 | | "0" :: "b" :: cs => (1, 2, cs) | |
| 409 | | "-" :: cs => (~1, 10, cs) | |
| 410 | | cs => (1, 10, cs)); | |
| 29156 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 411 | in | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 412 |    {radix = radix,
 | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 413 | leading_zeros = leading_zeros digs, | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 414 | value = sign * #1 (Library.read_radix_int radix digs)} | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 415 | end; | 
| 9326 | 416 | |
| 15991 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 417 | end; | 
| 
670f8e4b5a98
added read_variable: optional question mark on input;
 wenzelm parents: 
15965diff
changeset | 418 | |
| 28904 | 419 | fun read_float str = | 
| 420 | let | |
| 421 | val (sign, cs) = | |
| 29156 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 422 | (case Symbol.explode str of | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 423 | "-" :: cs => (~1, cs) | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 424 | | cs => (1, cs)); | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 425 | val (intpart, fracpart) = | 
| 28904 | 426 | (case take_prefix Symbol.is_digit cs of | 
| 29156 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 427 | (intpart, "." :: fracpart) => (intpart, fracpart) | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 428 | | _ => raise Fail "read_float"); | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 429 | in | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 430 |    {mant = sign * #1 (Library.read_int (intpart @ fracpart)),
 | 
| 
89f76a58a378
renamed terminal category "float" to "float_token", to avoid name
 wenzelm parents: 
28904diff
changeset | 431 | exp = length fracpart} | 
| 42046 
6341c23baf10
added Lexicon.encode_position, Lexicon.decode_position;
 wenzelm parents: 
40525diff
changeset | 432 | end; | 
| 
6341c23baf10
added Lexicon.encode_position, Lexicon.decode_position;
 wenzelm parents: 
40525diff
changeset | 433 | |
| 42290 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 434 | |
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 435 | (* marked logical entities *) | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 436 | |
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 437 | fun marker s = (prefix s, unprefix s); | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 438 | |
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 439 | val (mark_class, unmark_class) = marker "\\<^class>"; | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 440 | val (mark_type, unmark_type) = marker "\\<^type>"; | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 441 | val (mark_const, unmark_const) = marker "\\<^const>"; | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 442 | val (mark_fixed, unmark_fixed) = marker "\\<^fixed>"; | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 443 | |
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 444 | fun unmark {case_class, case_type, case_const, case_fixed, case_default} s =
 | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 445 | (case try unmark_class s of | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 446 | SOME c => case_class c | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 447 | | NONE => | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 448 | (case try unmark_type s of | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 449 | SOME c => case_type c | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 450 | | NONE => | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 451 | (case try unmark_const s of | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 452 | SOME c => case_const c | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 453 | | NONE => | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 454 | (case try unmark_fixed s of | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 455 | SOME c => case_fixed c | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 456 | | NONE => case_default s)))); | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 457 | |
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 458 | val is_marked = | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 459 |   unmark {case_class = K true, case_type = K true, case_const = K true,
 | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 460 | case_fixed = K true, case_default = K false}; | 
| 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 461 | |
| 42476 | 462 | val dummy_type = Syntax.const (mark_type "dummy"); | 
| 463 | val fun_type = Syntax.const (mark_type "fun"); | |
| 42290 
b1f544c84040
discontinued special treatment of structure Lexicon;
 wenzelm parents: 
42264diff
changeset | 464 | |
| 0 | 465 | end; |