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