author | wenzelm |
Mon, 14 Nov 1994 11:57:32 +0100 | |
changeset 710 | 53fef17a729a |
parent 656 | ec05d2fdfeee |
child 759 | e0b172d01c37 |
permissions | -rw-r--r-- |
389 | 1 |
(* Title: Pure/Thy/thy_parse.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
5 |
The parser for theory files. |
|
6 |
*) |
|
7 |
||
8 |
infix 5 -- --$$ $$-- ^^; |
|
9 |
infix 3 >>; |
|
10 |
infix 0 ||; |
|
11 |
||
12 |
signature THY_PARSE = |
|
13 |
sig |
|
14 |
type token |
|
15 |
val !! : ('a -> 'b * 'c) -> 'a -> 'b * 'c |
|
16 |
val >> : ('a -> 'b * 'c) * ('b -> 'd) -> 'a -> 'd * 'c |
|
17 |
val || : ('a -> 'b) * ('a -> 'b) -> 'a -> 'b |
|
18 |
val -- : ('a -> 'b * 'c) * ('c -> 'd * 'e) -> 'a -> ('b * 'd) * 'e |
|
19 |
val ^^ : ('a -> string * 'b) * ('b -> string * 'c) -> 'a -> string * 'c |
|
20 |
val $$ : string -> token list -> string * token list |
|
21 |
val $$-- : string * (token list -> 'b * 'c) -> token list -> 'b * 'c |
|
22 |
val --$$ : ('a -> 'b * token list) * string -> 'a -> 'b * token list |
|
23 |
val ident: token list -> string * token list |
|
24 |
val long_ident: token list -> string * token list |
|
25 |
val long_id: token list -> string * token list |
|
26 |
val type_var: token list -> string * token list |
|
636 | 27 |
val type_args: token list -> string list * token list |
389 | 28 |
val nat: token list -> string * token list |
29 |
val string: token list -> string * token list |
|
30 |
val verbatim: token list -> string * token list |
|
31 |
val empty: 'a -> 'b list * 'a |
|
32 |
val optional: ('a -> 'b * 'a) -> 'b -> 'a -> 'b * 'a |
|
33 |
val repeat: ('a -> 'b * 'a) -> 'a -> 'b list * 'a |
|
34 |
val repeat1: ('a -> 'b * 'a) -> 'a -> 'b list * 'a |
|
35 |
val enum: string -> (token list -> 'a * token list) |
|
36 |
-> token list -> 'a list * token list |
|
37 |
val enum1: string -> (token list -> 'a * token list) |
|
38 |
-> token list -> 'a list * token list |
|
39 |
val list: (token list -> 'a * token list) |
|
40 |
-> token list -> 'a list * token list |
|
41 |
val list1: (token list -> 'a * token list) |
|
42 |
-> token list -> 'a list * token list |
|
43 |
val name: token list -> string * token list |
|
44 |
val sort: token list -> string * token list |
|
451 | 45 |
val opt_infix: token list -> string * token list |
46 |
val opt_mixfix: token list -> string * token list |
|
636 | 47 |
val opt_witness: token list -> string * token list |
389 | 48 |
type syntax |
49 |
val make_syntax: string list -> |
|
50 |
(string * (token list -> (string * string) * token list)) list -> syntax |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
51 |
val parse_thy: syntax -> string -> string -> string |
389 | 52 |
val section: string -> string -> (token list -> string * token list) |
53 |
-> (string * (token list -> (string * string) * token list)) |
|
54 |
val axm_section: string -> string |
|
55 |
-> (token list -> (string * string list) * token list) |
|
56 |
-> (string * (token list -> (string * string) * token list)) |
|
57 |
val pure_keywords: string list |
|
58 |
val pure_sections: |
|
59 |
(string * (token list -> (string * string) * token list)) list |
|
570
6333c181a3f7
Pure/Thy/thy_parse/THY_PARSE: deleted duplicate specifications of parens,
lcp
parents:
558
diff
changeset
|
60 |
(*items for building strings*) |
710 | 61 |
val cat: string -> string -> string |
656 | 62 |
val parens: string -> string |
63 |
val brackets: string -> string |
|
64 |
val mk_list: string list -> string |
|
65 |
val mk_big_list: string list -> string |
|
66 |
val mk_pair: string * string -> string |
|
67 |
val mk_triple: string * string * string -> string |
|
68 |
val strip_quotes: string -> string |
|
389 | 69 |
end; |
70 |
||
414 | 71 |
functor ThyParseFun(structure Symtab: SYMTAB and ThyScan: THY_SCAN): THY_PARSE = |
389 | 72 |
struct |
73 |
||
74 |
open ThyScan; |
|
75 |
||
76 |
||
77 |
(** parser toolbox **) |
|
78 |
||
79 |
type token = token_kind * string * int; |
|
80 |
||
81 |
||
82 |
(* errors *) |
|
83 |
||
84 |
exception SYNTAX_ERROR of string * string * int; |
|
85 |
||
86 |
fun syn_err s1 s2 n = raise SYNTAX_ERROR (s1, s2, n); |
|
87 |
||
88 |
fun eof_err () = error "Unexpected end-of-file"; |
|
89 |
||
570
6333c181a3f7
Pure/Thy/thy_parse/THY_PARSE: deleted duplicate specifications of parens,
lcp
parents:
558
diff
changeset
|
90 |
(*Similar to Prolog's cut: reports any syntax error instead of backtracking |
6333c181a3f7
Pure/Thy/thy_parse/THY_PARSE: deleted duplicate specifications of parens,
lcp
parents:
558
diff
changeset
|
91 |
through a superior || *) |
389 | 92 |
fun !! parse toks = parse toks |
93 |
handle SYNTAX_ERROR (s1, s2, n) => error ("Syntax error on line " ^ |
|
94 |
string_of_int n ^ ": " ^ s1 ^ " expected and " ^ s2 ^ " was found"); |
|
95 |
||
96 |
||
97 |
(* parser combinators *) |
|
98 |
||
99 |
fun (parse >> f) toks = apfst f (parse toks); |
|
100 |
||
101 |
fun (parse1 || parse2) toks = |
|
102 |
parse1 toks handle SYNTAX_ERROR _ => parse2 toks; |
|
103 |
||
104 |
fun (parse1 -- parse2) toks = |
|
105 |
let |
|
106 |
val (x, toks') = parse1 toks; |
|
107 |
val (y, toks'') = parse2 toks'; |
|
108 |
in |
|
109 |
((x, y), toks'') |
|
110 |
end; |
|
111 |
||
112 |
fun (parse1 ^^ parse2) = parse1 -- parse2 >> op ^; |
|
113 |
||
114 |
||
115 |
(* generic parsers *) |
|
116 |
||
117 |
fun $$ a ((k, b, n) :: toks) = |
|
118 |
if k = Keyword andalso a = b then (a, toks) |
|
119 |
else syn_err (quote a) (quote b) n |
|
120 |
| $$ _ [] = eof_err (); |
|
121 |
||
122 |
fun (a $$-- parse) = $$ a -- parse >> #2; |
|
123 |
||
124 |
fun (parse --$$ a) = parse -- $$ a >> #1; |
|
125 |
||
126 |
||
127 |
fun kind k1 ((k2, s, n) :: toks) = |
|
128 |
if k1 = k2 then (s, toks) |
|
129 |
else syn_err (name_of_kind k1) (quote s) n |
|
130 |
| kind _ [] = eof_err (); |
|
131 |
||
132 |
val ident = kind Ident; |
|
133 |
val long_ident = kind LongIdent; |
|
134 |
val long_id = ident || long_ident; |
|
135 |
val type_var = kind TypeVar >> quote; |
|
136 |
val nat = kind Nat; |
|
137 |
val string = kind String; |
|
138 |
val verbatim = kind Verbatim; |
|
139 |
val eof = kind EOF; |
|
140 |
||
141 |
fun empty toks = ([], toks); |
|
142 |
||
143 |
fun optional parse def = parse || empty >> K def; |
|
144 |
||
145 |
fun repeat parse toks = (parse -- repeat parse >> op :: || empty) toks; |
|
146 |
fun repeat1 parse = parse -- repeat parse >> op ::; |
|
147 |
||
148 |
fun enum1 sep parse = parse -- repeat (sep $$-- parse) >> op ::; |
|
149 |
fun enum sep parse = enum1 sep parse || empty; |
|
150 |
||
151 |
val list = enum ","; |
|
152 |
val list1 = enum1 ","; |
|
153 |
||
154 |
||
155 |
||
156 |
(** theory parsers **) |
|
157 |
||
158 |
(* misc utilities *) |
|
159 |
||
160 |
fun cat s1 s2 = s1 ^ " " ^ s2; |
|
161 |
||
558 | 162 |
val parens = enclose "(" ")"; |
163 |
val brackets = enclose "[" "]"; |
|
389 | 164 |
|
165 |
val mk_list = brackets o commas; |
|
166 |
val mk_big_list = brackets o space_implode ",\n "; |
|
167 |
||
558 | 168 |
fun mk_pair (x, y) = parens (commas [x, y]); |
169 |
fun mk_triple (x, y, z) = parens (commas [x, y, z]); |
|
389 | 170 |
fun mk_triple1 ((x, y), z) = mk_triple (x, y, z); |
171 |
fun mk_triple2 (x, (y, z)) = mk_triple (x, y, z); |
|
172 |
||
173 |
val split_decls = flat o map (fn (xs, y) => map (rpair y) xs); |
|
174 |
||
175 |
fun strip_quotes str = |
|
176 |
implode (tl (take (size str - 1, explode str))); |
|
177 |
||
178 |
||
179 |
(* names *) |
|
180 |
||
181 |
val name = ident >> quote || string; |
|
182 |
val names = list name; |
|
183 |
val names1 = list1 name; |
|
184 |
val name_list = names >> mk_list; |
|
185 |
val name_list1 = names1 >> mk_list; |
|
186 |
||
187 |
||
188 |
(* classes *) |
|
189 |
||
190 |
val subclass = name -- optional ("<" $$-- !! name_list1) "[]"; |
|
191 |
||
558 | 192 |
val class_decls = repeat1 (subclass >> mk_pair) >> mk_big_list; |
389 | 193 |
|
194 |
||
195 |
(* arities *) |
|
196 |
||
197 |
val sort = |
|
198 |
name >> brackets || |
|
199 |
"{" $$-- name_list --$$ "}"; |
|
200 |
||
201 |
val sort_list1 = list1 sort >> mk_list; |
|
202 |
||
203 |
||
204 |
val arity = optional ("(" $$-- !! (sort_list1 --$$")")) "[]" -- sort; |
|
205 |
||
206 |
val arity_decls = repeat1 (names1 --$$ "::" -- !! arity) |
|
207 |
>> (mk_big_list o map mk_triple2 o split_decls); |
|
208 |
||
209 |
||
210 |
(* mixfix annotations *) |
|
211 |
||
212 |
val infxl = "infixl" $$-- !! nat >> cat "Infixl"; |
|
213 |
val infxr = "infixr" $$-- !! nat >> cat "Infixr"; |
|
214 |
||
215 |
val binder = "binder" $$-- !! (string -- nat) >> (cat "Binder" o mk_pair); |
|
216 |
||
217 |
val opt_pris = optional ("[" $$-- !! (list nat --$$ "]")) [] >> mk_list; |
|
218 |
||
219 |
val mixfix = string -- !! (opt_pris -- optional nat "max_pri") |
|
220 |
>> (cat "Mixfix" o mk_triple2); |
|
221 |
||
558 | 222 |
fun opt_syn fx = optional ("(" $$-- fx --$$ ")") "NoSyn"; |
389 | 223 |
|
224 |
val opt_infix = opt_syn (infxl || infxr); |
|
225 |
val opt_mixfix = opt_syn (mixfix || infxl || infxr || binder); |
|
226 |
||
227 |
||
228 |
(* types *) |
|
229 |
||
230 |
fun mk_old_type_decl ((ts, n), syn) = |
|
231 |
map (fn t => (mk_triple (t, n, syn), false)) ts; |
|
232 |
||
233 |
fun mk_type_decl (((xs, t), None), syn) = |
|
234 |
[(mk_triple (t, string_of_int (length xs), syn), false)] |
|
235 |
| mk_type_decl (((xs, t), Some rhs), syn) = |
|
558 | 236 |
[(parens (commas [t, mk_list xs, rhs, syn]), true)]; |
389 | 237 |
|
238 |
fun mk_type_decls tys = |
|
414 | 239 |
"|> add_types\n" ^ mk_big_list (keyfilter tys false) ^ "\n\n\ |
240 |
\|> add_tyabbrs\n" ^ mk_big_list (keyfilter tys true); |
|
389 | 241 |
|
242 |
||
425 | 243 |
val old_type_decl = names1 -- nat -- opt_infix >> mk_old_type_decl; |
389 | 244 |
|
245 |
val type_args = |
|
246 |
type_var >> (fn x => [x]) || |
|
247 |
"(" $$-- !! (list1 type_var --$$ ")") || |
|
248 |
empty >> K []; |
|
249 |
||
250 |
val type_decl = type_args -- name -- optional ("=" $$-- !! string >> Some) None |
|
251 |
-- opt_infix >> mk_type_decl; |
|
252 |
||
253 |
val type_decls = repeat1 (old_type_decl || type_decl) |
|
254 |
>> (rpair "" o mk_type_decls o flat); |
|
255 |
||
256 |
||
257 |
(* consts *) |
|
258 |
||
259 |
val const_decls = repeat1 (names1 --$$ "::" -- !! (string -- opt_mixfix)) |
|
260 |
>> (mk_big_list o map mk_triple2 o split_decls); |
|
261 |
||
262 |
||
263 |
(* translations *) |
|
264 |
||
265 |
val trans_pat = |
|
266 |
optional ("(" $$-- !! (name --$$ ")")) "\"logic\"" -- string >> mk_pair; |
|
267 |
||
268 |
val trans_arrow = |
|
269 |
$$ "=>" >> K " |-> " || |
|
270 |
$$ "<=" >> K " <-| " || |
|
271 |
$$ "==" >> K " <-> "; |
|
272 |
||
273 |
val trans_decls = repeat1 (trans_pat ^^ !! (trans_arrow ^^ trans_pat)) |
|
274 |
>> mk_big_list; |
|
275 |
||
276 |
||
277 |
(* ML translations *) |
|
278 |
||
279 |
val trfun_defs = |
|
280 |
" val parse_ast_translation = [];\n\ |
|
281 |
\ val parse_translation = [];\n\ |
|
282 |
\ val print_translation = [];\n\ |
|
283 |
\ val print_ast_translation = [];"; |
|
284 |
||
285 |
val trfun_args = |
|
286 |
"(parse_ast_translation, parse_translation, \ |
|
287 |
\print_translation, print_ast_translation)"; |
|
288 |
||
289 |
fun mk_mltrans txt = |
|
290 |
"let\n" |
|
291 |
^ trfun_defs ^ "\n" |
|
292 |
^ txt ^ "\n\ |
|
293 |
\in\n\ |
|
294 |
\ " ^ trfun_args ^ "\n\ |
|
295 |
\end"; |
|
296 |
||
297 |
val mltrans = verbatim >> mk_mltrans; |
|
298 |
||
299 |
||
300 |
(* axioms *) |
|
301 |
||
302 |
val mk_axms = mk_big_list o map (mk_pair o apfst quote); |
|
303 |
||
304 |
fun mk_axiom_decls axms = (mk_axms axms, map fst axms); |
|
305 |
||
306 |
val axiom_decls = repeat1 (ident -- !! string) >> mk_axiom_decls; |
|
307 |
||
308 |
||
309 |
(* axclass *) |
|
310 |
||
311 |
fun mk_axclass_decl ((c, cs), axms) = |
|
312 |
(mk_pair (c, cs) ^ "\n" ^ mk_axms axms, |
|
313 |
(strip_quotes c ^ "I") :: map fst axms); |
|
314 |
||
315 |
val axclass_decl = subclass -- repeat (ident -- !! string) >> mk_axclass_decl; |
|
316 |
||
317 |
||
451 | 318 |
(* instance *) |
389 | 319 |
|
425 | 320 |
fun mk_witness (axths, opt_tac) = |
389 | 321 |
mk_list (keyfilter axths false) ^ "\n" ^ |
322 |
mk_list (keyfilter axths true) ^ "\n" ^ |
|
323 |
opt_tac; |
|
324 |
||
325 |
val axm_or_thm = |
|
326 |
string >> rpair false || |
|
327 |
long_id >> rpair true; |
|
328 |
||
451 | 329 |
|
425 | 330 |
val opt_witness = |
389 | 331 |
optional ("(" $$-- list1 axm_or_thm --$$ ")") [] -- |
558 | 332 |
optional (verbatim >> (parens o cat "Some" o parens)) "None" |
425 | 333 |
>> mk_witness; |
334 |
||
335 |
val instance_decl = |
|
636 | 336 |
(name --$$ "<" -- name >> (pair "|> AxClass.add_inst_subclass" o mk_pair) || |
337 |
name --$$ "::" -- arity >> (pair "|> AxClass.add_inst_arity" o mk_triple2)) |
|
451 | 338 |
-- opt_witness |
339 |
>> (fn ((x, y), z) => (cat_lines [x, y, z], "")); |
|
389 | 340 |
|
341 |
||
342 |
||
343 |
(** theory syntax **) |
|
344 |
||
345 |
type syntax = |
|
346 |
lexicon * (token list -> (string * string) * token list) Symtab.table; |
|
347 |
||
348 |
fun make_syntax keywords sects = |
|
451 | 349 |
(make_lexicon (map fst sects @ keywords), |
350 |
Symtab.make sects handle Symtab.DUPS dups => |
|
351 |
error ("Duplicate sections in theory file syntax: " ^ commas_quote dups)); |
|
389 | 352 |
|
353 |
||
354 |
(* header *) |
|
355 |
||
356 |
fun mk_header (thy_name, bases) = |
|
586
201e115d8031
renamed base_on into mk_base and moved it to the beginning of the generated
clasohm
parents:
570
diff
changeset
|
357 |
(thy_name, "mk_base " ^ mk_list bases ^ " " ^ quote thy_name); |
389 | 358 |
|
359 |
val base = |
|
360 |
ident >> (cat "Thy" o quote) || |
|
361 |
string >> cat "File"; |
|
362 |
||
363 |
val header = ident --$$ "=" -- enum1 "+" base >> mk_header; |
|
364 |
||
365 |
||
366 |
(* extension *) |
|
367 |
||
368 |
fun mk_extension (txts, mltxt) = |
|
369 |
let |
|
370 |
val cat_sects = space_implode "\n\n" o filter_out (equal ""); |
|
371 |
val (extxts, postxts) = split_list txts; |
|
372 |
in |
|
373 |
(cat_sects extxts, cat_sects postxts, mltxt) |
|
374 |
end; |
|
375 |
||
376 |
fun sect tab ((Keyword, s, n) :: toks) = |
|
377 |
(case Symtab.lookup (tab, s) of |
|
378 |
Some parse => !! parse toks |
|
379 |
| None => syn_err "section" s n) |
|
380 |
| sect _ ((_, s, n) :: _) = syn_err "section" s n |
|
381 |
| sect _ [] = eof_err (); |
|
382 |
||
383 |
fun extension sectab = "+" $$-- !! (repeat (sect sectab) --$$ "end") -- |
|
384 |
optional ("ML" $$-- verbatim) "" >> mk_extension; |
|
385 |
||
386 |
||
387 |
(* theory definition *) |
|
388 |
||
558 | 389 |
fun mk_structure tname ((thy_name, old_thys), opt_txts) = |
390 |
if thy_name <> tname then |
|
391 |
error ("Filename \"" ^ tname ^ ".thy\" and theory name " |
|
392 |
^ quote thy_name ^ " are different") |
|
393 |
else |
|
394 |
(case opt_txts of |
|
395 |
Some (extxt, postxt, mltxt) => |
|
587
3ba470399605
renamed temporary variable 'base' to 'thy' in mk_structure
clasohm
parents:
586
diff
changeset
|
396 |
"val thy = " ^ old_thys ^ " true;\n\n\ |
586
201e115d8031
renamed base_on into mk_base and moved it to the beginning of the generated
clasohm
parents:
570
diff
changeset
|
397 |
\structure " ^ thy_name ^ " =\n\ |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
398 |
\struct\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
399 |
\\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
400 |
\local\n" |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
401 |
^ trfun_defs ^ "\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
402 |
\in\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
403 |
\\n" |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
404 |
^ mltxt ^ "\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
405 |
\\n\ |
587
3ba470399605
renamed temporary variable 'base' to 'thy' in mk_structure
clasohm
parents:
586
diff
changeset
|
406 |
\val thy = thy\n\n\ |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
407 |
\|> add_trfuns\n" |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
408 |
^ trfun_args ^ "\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
409 |
\\n" |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
410 |
^ extxt ^ "\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
411 |
\\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
412 |
\|> add_thyname " ^ quote thy_name ^ ";\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
413 |
\\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
414 |
\\n" |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
415 |
^ postxt ^ "\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
416 |
\\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
417 |
\end;\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
418 |
\end;\n" |
558 | 419 |
| None => |
587
3ba470399605
renamed temporary variable 'base' to 'thy' in mk_structure
clasohm
parents:
586
diff
changeset
|
420 |
"val thy = " ^ old_thys ^ " false;\n\n\ |
586
201e115d8031
renamed base_on into mk_base and moved it to the beginning of the generated
clasohm
parents:
570
diff
changeset
|
421 |
\structure " ^ thy_name ^ " =\n\ |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
422 |
\struct\n\ |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
423 |
\\n\ |
587
3ba470399605
renamed temporary variable 'base' to 'thy' in mk_structure
clasohm
parents:
586
diff
changeset
|
424 |
\val thy = thy\n\ |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
425 |
\\n\ |
558 | 426 |
\end;\n"); |
389 | 427 |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
428 |
fun theory_defn sectab tname = |
389 | 429 |
header -- optional (extension sectab >> Some) None -- eof |
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
430 |
>> (mk_structure tname o #1); |
389 | 431 |
|
476
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
432 |
fun parse_thy (lex, sectab) tname str = |
836cad329311
added check for concistency of filename and theory name;
clasohm
parents:
451
diff
changeset
|
433 |
#1 (!! (theory_defn sectab tname) (tokenize lex str)); |
389 | 434 |
|
435 |
||
436 |
(* standard sections *) |
|
437 |
||
438 |
fun mk_val ax = "val " ^ ax ^ " = get_axiom thy " ^ quote ax ^ ";"; |
|
439 |
||
440 |
fun mk_axm_sect pretxt (txt, axs) = |
|
441 |
(pretxt ^ "\n" ^ txt, cat_lines (map mk_val axs)); |
|
442 |
||
443 |
fun axm_section name pretxt parse = |
|
444 |
(name, parse >> mk_axm_sect pretxt); |
|
445 |
||
446 |
fun section name pretxt parse = |
|
447 |
axm_section name pretxt (parse >> rpair []); |
|
448 |
||
449 |
||
450 |
val pure_keywords = |
|
451 | 451 |
["end", "ML", "mixfix", "infixr", "infixl", "binder", "=", "+", ",", "<", |
452 |
"{", "}", "(", ")", "[", "]", "::", "==", "=>", "<="]; |
|
389 | 453 |
|
454 |
val pure_sections = |
|
414 | 455 |
[section "classes" "|> add_classes" class_decls, |
456 |
section "default" "|> add_defsort" sort, |
|
389 | 457 |
("types", type_decls), |
414 | 458 |
section "arities" "|> add_arities" arity_decls, |
459 |
section "consts" "|> add_consts" const_decls, |
|
460 |
section "syntax" "|> add_syntax" const_decls, |
|
461 |
section "translations" "|> add_trrules" trans_decls, |
|
462 |
section "MLtrans" "|> add_trfuns" mltrans, |
|
389 | 463 |
("MLtext", verbatim >> rpair ""), |
414 | 464 |
axm_section "rules" "|> add_axioms" axiom_decls, |
558 | 465 |
axm_section "defs" "|> add_defs" axiom_decls, |
636 | 466 |
axm_section "axclass" "|> AxClass.add_axclass" axclass_decl, |
451 | 467 |
("instance", instance_decl)]; |
389 | 468 |
|
469 |
||
470 |
end; |
|
471 |