| author | wenzelm |
| Tue, 21 Sep 1999 17:28:02 +0200 | |
| changeset 7560 | 19c3be2d285c |
| parent 7472 | f1208505d837 |
| child 7784 | 228283fa5de4 |
| permissions | -rw-r--r-- |
| 18 | 1 |
(* Title: Pure/Syntax/lexicon.ML |
| 0 | 2 |
ID: $Id$ |
| 18 | 3 |
Author: Tobias Nipkow and Markus Wenzel, TU Muenchen |
| 0 | 4 |
|
| 4703 | 5 |
Lexer for the inner Isabelle syntax (terms and types). |
| 18 | 6 |
*) |
| 0 | 7 |
|
8 |
signature LEXICON0 = |
|
|
4247
9bba9251bb4d
added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents:
3828
diff
changeset
|
9 |
sig |
| 0 | 10 |
val is_identifier: string -> bool |
|
4247
9bba9251bb4d
added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents:
3828
diff
changeset
|
11 |
val implode_xstr: string list -> string |
|
9bba9251bb4d
added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents:
3828
diff
changeset
|
12 |
val explode_xstr: string -> string list |
| 4703 | 13 |
val scan_id: string list -> string * string list |
14 |
val scan_longid: string list -> string * string list |
|
15 |
val scan_var: string list -> string * string list |
|
16 |
val scan_tid: string list -> string * string list |
|
| 4902 | 17 |
val scan_tvar: string list -> string * string list |
| 4703 | 18 |
val scan_nat: string list -> string * string list |
19 |
val scan_int: string list -> string * string list |
|
| 18 | 20 |
val string_of_vname: indexname -> string |
|
2583
690835a06cf2
added string_of_vname' (treats neg. index as free);
wenzelm
parents:
2363
diff
changeset
|
21 |
val string_of_vname': indexname -> string |
| 4703 | 22 |
val indexname: string list -> indexname |
23 |
val read_var: string -> term |
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
24 |
val const: string -> term |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
25 |
val free: string -> term |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
26 |
val var: indexname -> term |
| 5260 | 27 |
val skolem: string -> string |
| 5286 | 28 |
val dest_skolem: string -> string |
| 5860 | 29 |
val read_nat: string -> int option |
|
4247
9bba9251bb4d
added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents:
3828
diff
changeset
|
30 |
end; |
| 0 | 31 |
|
32 |
signature LEXICON = |
|
|
4247
9bba9251bb4d
added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents:
3828
diff
changeset
|
33 |
sig |
| 18 | 34 |
include LEXICON0 |
35 |
val is_xid: string -> bool |
|
|
330
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
237
diff
changeset
|
36 |
val is_tid: string -> bool |
| 18 | 37 |
datatype token = |
38 |
Token of string | |
|
39 |
IdentSy of string | |
|
| 3828 | 40 |
LongIdentSy of string | |
| 18 | 41 |
VarSy of string | |
42 |
TFreeSy of string | |
|
43 |
TVarSy of string | |
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
44 |
NumSy of string | |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
45 |
StrSy of string | |
|
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
164
diff
changeset
|
46 |
EndToken |
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
47 |
val idT: typ |
| 3828 | 48 |
val longidT: typ |
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
49 |
val varT: typ |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
50 |
val tidT: typ |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
51 |
val tvarT: typ |
|
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
164
diff
changeset
|
52 |
val terminals: string list |
|
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
164
diff
changeset
|
53 |
val is_terminal: string -> bool |
| 18 | 54 |
val str_of_token: token -> string |
55 |
val display_token: token -> string |
|
56 |
val matching_tokens: token * token -> bool |
|
|
330
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
237
diff
changeset
|
57 |
val token_assoc: (token option * 'a list) list * token -> 'a list |
| 18 | 58 |
val valued_token: token -> bool |
|
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
164
diff
changeset
|
59 |
val predef_term: string -> token option |
| 4703 | 60 |
val tokenize: Scan.lexicon -> bool -> string list -> token list |
|
4247
9bba9251bb4d
added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents:
3828
diff
changeset
|
61 |
end; |
| 0 | 62 |
|
| 1507 | 63 |
structure Lexicon : LEXICON = |
| 0 | 64 |
struct |
65 |
||
|
4247
9bba9251bb4d
added implode_xstr: string list -> string, explode_xstr: string -> string list;
wenzelm
parents:
3828
diff
changeset
|
66 |
|
| 18 | 67 |
(** is_identifier etc. **) |
68 |
||
69 |
fun is_ident [] = false |
|
| 4703 | 70 |
| is_ident (c :: cs) = Symbol.is_letter c andalso forall Symbol.is_letdig cs; |
| 18 | 71 |
|
| 4703 | 72 |
val is_identifier = is_ident o Symbol.explode; |
| 18 | 73 |
|
74 |
fun is_xid s = |
|
| 4703 | 75 |
(case Symbol.explode s of |
| 18 | 76 |
"_" :: cs => is_ident cs |
77 |
| cs => is_ident cs); |
|
78 |
||
|
330
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
237
diff
changeset
|
79 |
fun is_tid s = |
| 4703 | 80 |
(case Symbol.explode s of |
| 18 | 81 |
"'" :: cs => is_ident cs |
82 |
| _ => false); |
|
83 |
||
| 0 | 84 |
|
85 |
||
| 4703 | 86 |
(** basic scanners **) |
87 |
||
88 |
val scan_letter_letdigs = Scan.one Symbol.is_letter -- Scan.any Symbol.is_letdig >> op ::; |
|
89 |
val scan_digits1 = Scan.any1 Symbol.is_digit; |
|
90 |
||
91 |
val scan_id = scan_letter_letdigs >> implode; |
|
92 |
val scan_longid = scan_id ^^ (Scan.repeat1 ($$ "." ^^ scan_id) >> implode); |
|
93 |
val scan_tid = $$ "'" ^^ scan_id; |
|
94 |
||
95 |
val scan_nat = scan_digits1 >> implode; |
|
| 5513 | 96 |
val scan_int = $$ "-" ^^ scan_nat || scan_nat; |
| 4703 | 97 |
|
98 |
val scan_id_nat = scan_id ^^ Scan.optional ($$ "." ^^ scan_nat) ""; |
|
99 |
val scan_var = $$ "?" ^^ scan_id_nat; |
|
| 4902 | 100 |
val scan_tvar = $$ "?" ^^ $$ "'" ^^ scan_id_nat; |
| 4703 | 101 |
|
102 |
||
103 |
||
| 18 | 104 |
(** string_of_vname **) |
| 0 | 105 |
|
| 18 | 106 |
fun string_of_vname (x, i) = |
107 |
let |
|
108 |
val si = string_of_int i; |
|
| 6962 | 109 |
val dot = if_none (try (Symbol.is_digit o last_elem o Symbol.explode) x) true; |
| 18 | 110 |
in |
| 4703 | 111 |
if dot then "?" ^ x ^ "." ^ si |
112 |
else if i = 0 then "?" ^ x |
|
113 |
else "?" ^ x ^ si |
|
| 18 | 114 |
end; |
| 0 | 115 |
|
| 4703 | 116 |
fun string_of_vname' (x, ~1) = x |
117 |
| string_of_vname' xi = string_of_vname xi; |
|
|
2583
690835a06cf2
added string_of_vname' (treats neg. index as free);
wenzelm
parents:
2363
diff
changeset
|
118 |
|
| 18 | 119 |
|
| 0 | 120 |
|
| 18 | 121 |
(** datatype token **) |
| 0 | 122 |
|
| 18 | 123 |
datatype token = |
124 |
Token of string | |
|
125 |
IdentSy of string | |
|
| 3828 | 126 |
LongIdentSy of string | |
| 18 | 127 |
VarSy of string | |
128 |
TFreeSy of string | |
|
129 |
TVarSy of string | |
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
130 |
NumSy of string | |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
131 |
StrSy of string | |
| 18 | 132 |
EndToken; |
| 0 | 133 |
|
134 |
||
|
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
164
diff
changeset
|
135 |
(* terminal arguments *) |
| 0 | 136 |
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
137 |
val idT = Type ("id", []);
|
| 3828 | 138 |
val longidT = Type ("longid", []);
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
139 |
val varT = Type ("var", []);
|
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
140 |
val tidT = Type ("tid", []);
|
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
141 |
val tvarT = Type ("tvar", []);
|
| 0 | 142 |
|
| 3828 | 143 |
val terminals = ["id", "longid", "var", "tid", "tvar", "xnum", "xstr"]; |
|
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
164
diff
changeset
|
144 |
|
|
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
164
diff
changeset
|
145 |
fun is_terminal s = s mem terminals; |
|
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
164
diff
changeset
|
146 |
|
| 0 | 147 |
|
| 18 | 148 |
(* str_of_token *) |
| 0 | 149 |
|
| 18 | 150 |
fun str_of_token (Token s) = s |
151 |
| str_of_token (IdentSy s) = s |
|
| 3828 | 152 |
| str_of_token (LongIdentSy s) = s |
| 18 | 153 |
| str_of_token (VarSy s) = s |
154 |
| str_of_token (TFreeSy s) = s |
|
155 |
| str_of_token (TVarSy s) = s |
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
156 |
| str_of_token (NumSy s) = s |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
157 |
| str_of_token (StrSy s) = s |
|
376
d3d01131470f
extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents:
330
diff
changeset
|
158 |
| str_of_token EndToken = "EOF"; |
| 0 | 159 |
|
| 18 | 160 |
|
161 |
(* display_token *) |
|
| 0 | 162 |
|
| 18 | 163 |
fun display_token (Token s) = quote s |
164 |
| display_token (IdentSy s) = "id(" ^ s ^ ")"
|
|
| 3828 | 165 |
| display_token (LongIdentSy s) = "longid(" ^ s ^ ")"
|
| 18 | 166 |
| display_token (VarSy s) = "var(" ^ s ^ ")"
|
|
330
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
237
diff
changeset
|
167 |
| display_token (TFreeSy s) = "tid(" ^ s ^ ")"
|
| 18 | 168 |
| display_token (TVarSy s) = "tvar(" ^ s ^ ")"
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
169 |
| display_token (NumSy s) = "xnum(" ^ s ^ ")"
|
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
170 |
| display_token (StrSy s) = "xstr(" ^ s ^ ")"
|
| 18 | 171 |
| display_token EndToken = ""; |
| 0 | 172 |
|
| 18 | 173 |
|
174 |
(* matching_tokens *) |
|
| 0 | 175 |
|
| 18 | 176 |
fun matching_tokens (Token x, Token y) = (x = y) |
177 |
| matching_tokens (IdentSy _, IdentSy _) = true |
|
| 3828 | 178 |
| matching_tokens (LongIdentSy _, LongIdentSy _) = true |
| 18 | 179 |
| matching_tokens (VarSy _, VarSy _) = true |
180 |
| matching_tokens (TFreeSy _, TFreeSy _) = true |
|
181 |
| matching_tokens (TVarSy _, TVarSy _) = true |
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
182 |
| matching_tokens (NumSy _, NumSy _) = true |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
183 |
| matching_tokens (StrSy _, StrSy _) = true |
| 18 | 184 |
| matching_tokens (EndToken, EndToken) = true |
185 |
| matching_tokens _ = false; |
|
| 0 | 186 |
|
187 |
||
|
376
d3d01131470f
extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents:
330
diff
changeset
|
188 |
(* token_assoc *) |
|
d3d01131470f
extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents:
330
diff
changeset
|
189 |
|
|
330
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
237
diff
changeset
|
190 |
fun token_assoc (list, key) = |
|
376
d3d01131470f
extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents:
330
diff
changeset
|
191 |
let |
|
d3d01131470f
extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents:
330
diff
changeset
|
192 |
fun assoc [] = [] |
|
d3d01131470f
extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents:
330
diff
changeset
|
193 |
| assoc ((keyi, xi) :: pairs) = |
|
d3d01131470f
extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents:
330
diff
changeset
|
194 |
if is_none keyi orelse matching_tokens (the keyi, key) then |
|
d3d01131470f
extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents:
330
diff
changeset
|
195 |
assoc pairs @ xi |
|
d3d01131470f
extended signature SCANNER by some basic scanners and type lexicon;
wenzelm
parents:
330
diff
changeset
|
196 |
else assoc pairs; |
|
330
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
237
diff
changeset
|
197 |
in assoc list end; |
|
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
237
diff
changeset
|
198 |
|
|
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
237
diff
changeset
|
199 |
|
| 18 | 200 |
(* valued_token *) |
| 0 | 201 |
|
| 18 | 202 |
fun valued_token (Token _) = false |
203 |
| valued_token (IdentSy _) = true |
|
| 3828 | 204 |
| valued_token (LongIdentSy _) = true |
| 18 | 205 |
| valued_token (VarSy _) = true |
206 |
| valued_token (TFreeSy _) = true |
|
207 |
| valued_token (TVarSy _) = true |
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
208 |
| valued_token (NumSy _) = true |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
209 |
| valued_token (StrSy _) = true |
| 18 | 210 |
| valued_token EndToken = false; |
| 0 | 211 |
|
212 |
||
| 18 | 213 |
(* predef_term *) |
| 0 | 214 |
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
215 |
fun predef_term "id" = Some (IdentSy "id") |
| 3828 | 216 |
| predef_term "longid" = Some (LongIdentSy "longid") |
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
217 |
| predef_term "var" = Some (VarSy "var") |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
218 |
| predef_term "tid" = Some (TFreeSy "tid") |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
219 |
| predef_term "tvar" = Some (TVarSy "tvar") |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
220 |
| predef_term "xnum" = Some (NumSy "xnum") |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
221 |
| predef_term "xstr" = Some (StrSy "xstr") |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
222 |
| predef_term _ = None; |
| 0 | 223 |
|
224 |
||
| 4703 | 225 |
(* xstr tokens *) |
| 18 | 226 |
|
| 4703 | 227 |
val scan_chr = |
228 |
$$ "\\" |-- Scan.one Symbol.not_eof || |
|
229 |
Scan.one (not_equal "'" andf Symbol.not_eof) || |
|
230 |
$$ "'" --| Scan.ahead (Scan.one (not_equal "'")); |
|
| 18 | 231 |
|
| 4703 | 232 |
val scan_str = |
233 |
$$ "'" |-- $$ "'" |-- |
|
| 4921 | 234 |
!! (fn (cs, _) => "Inner lexical error: malformed literal string at " ^ |
| 5112 | 235 |
quote ("''" ^ Symbol.beginning cs))
|
| 4921 | 236 |
(Scan.repeat scan_chr --| $$ "'" --| $$ "'"); |
| 18 | 237 |
|
| 0 | 238 |
|
| 4703 | 239 |
fun implode_xstr cs = enclose "''" "''" (implode (map (fn "'" => "\\'" | c => c) cs)); |
| 18 | 240 |
|
| 4703 | 241 |
fun explode_xstr str = |
| 5868 | 242 |
(case Scan.read Symbol.stopper scan_str (Symbol.explode str) of |
243 |
Some cs => cs |
|
244 |
| _ => error ("Inner lexical error: literal string expected at " ^ quote str));
|
|
| 18 | 245 |
|
246 |
||
247 |
||
248 |
(** tokenize **) |
|
249 |
||
| 2363 | 250 |
fun tokenize lex xids chs = |
| 18 | 251 |
let |
252 |
val scan_xid = |
|
253 |
if xids then $$ "_" ^^ scan_id || scan_id |
|
254 |
else scan_id; |
|
255 |
||
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
256 |
val scan_val = |
| 4902 | 257 |
scan_tvar >> pair TVarSy || |
| 4703 | 258 |
scan_var >> pair VarSy || |
259 |
scan_tid >> pair TFreeSy || |
|
| 5868 | 260 |
$$ "#" ^^ scan_int >> pair NumSy || |
| 3828 | 261 |
scan_longid >> pair LongIdentSy || |
| 18 | 262 |
scan_xid >> pair IdentSy; |
263 |
||
| 4703 | 264 |
val scan_lit = Scan.literal lex >> (pair Token o implode); |
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
265 |
|
| 4703 | 266 |
val scan_token = |
267 |
Scan.max (op <= o pairself snd) scan_lit scan_val >> (fn (tk, s) => Some (tk s)) || |
|
268 |
scan_str >> (Some o StrSy o implode_xstr) || |
|
269 |
Scan.one Symbol.is_blank >> K None; |
|
| 18 | 270 |
in |
| 4938 | 271 |
(case Scan.error (Scan.finite Symbol.stopper (Scan.repeat scan_token)) chs of |
| 4703 | 272 |
(toks, []) => mapfilter I toks @ [EndToken] |
273 |
| (_, cs) => error ("Inner lexical error at: " ^ quote (implode cs)))
|
|
| 18 | 274 |
end; |
275 |
||
276 |
||
277 |
||
278 |
(** scan variables **) |
|
279 |
||
280 |
(* scan_vname *) |
|
281 |
||
282 |
fun scan_vname chrs = |
|
283 |
let |
|
284 |
fun nat_of_chs n [] = n |
|
285 |
| nat_of_chs n (c :: cs) = nat_of_chs (n * 10 + (ord c - ord "0")) cs; |
|
286 |
||
| 4703 | 287 |
val nat = nat_of_chs 0; |
| 18 | 288 |
|
289 |
fun split_vname chs = |
|
| 4703 | 290 |
let val (cs, ds) = take_suffix Symbol.is_digit chs |
291 |
in (implode cs, nat ds) end |
|
| 18 | 292 |
|
293 |
val scan = |
|
| 4703 | 294 |
scan_letter_letdigs -- Scan.optional ($$ "." |-- scan_digits1 >> nat) ~1; |
| 18 | 295 |
in |
296 |
(case scan chrs of |
|
297 |
((cs, ~1), cs') => (split_vname cs, cs') |
|
298 |
| ((cs, i), cs') => ((implode cs, i), cs')) |
|
299 |
end; |
|
300 |
||
301 |
||
| 4703 | 302 |
(* indexname *) |
| 18 | 303 |
|
| 4703 | 304 |
fun indexname cs = |
| 5868 | 305 |
(case Scan.read Symbol.stopper scan_vname cs of |
306 |
Some xi => xi |
|
| 4703 | 307 |
| _ => error ("Lexical error in variable name: " ^ quote (implode cs)));
|
| 18 | 308 |
|
309 |
||
| 4703 | 310 |
(* read_var *) |
| 18 | 311 |
|
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
312 |
fun const c = Const (c, dummyT); |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
313 |
fun free x = Free (x, dummyT); |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
314 |
fun var xi = Var (xi, dummyT); |
|
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
315 |
|
| 4703 | 316 |
fun read_var str = |
| 18 | 317 |
let |
|
550
353eea6ec232
replaced id, var, tid, tvar by idT, varT, tidT, tvarT;
wenzelm
parents:
376
diff
changeset
|
318 |
fun tvar (x, i) = var ("'" ^ x, i);
|
| 18 | 319 |
|
320 |
val scan = |
|
| 4703 | 321 |
$$ "?" |-- $$ "'" |-- scan_vname >> tvar || |
322 |
$$ "?" |-- scan_vname >> var || |
|
323 |
Scan.any Symbol.not_eof >> (free o implode); |
|
| 5868 | 324 |
in the (Scan.read Symbol.stopper scan (Symbol.explode str)) end; |
| 4587 | 325 |
|
326 |
||
| 5260 | 327 |
(* variable kinds *) |
328 |
||
| 5286 | 329 |
val skolem = suffix "__"; |
330 |
val dest_skolem = unsuffix "__"; |
|
| 5260 | 331 |
|
332 |
||
| 5860 | 333 |
(* read_nat *) |
334 |
||
335 |
fun read_nat str = |
|
| 5868 | 336 |
apsome (#1 o Term.read_int) (Scan.read Symbol.stopper scan_digits1 (Symbol.explode str)); |
| 5860 | 337 |
|
338 |
||
| 0 | 339 |
end; |