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