411
|
1 |
(* Title: Pure/Thy/thy_syn.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
|
4 |
|
6206
|
5 |
Provide syntax for old-style theory files.
|
411
|
6 |
*)
|
|
7 |
|
6206
|
8 |
signature BASIC_THY_SYN =
|
|
9 |
sig
|
|
10 |
val delete_tmpfiles: bool ref
|
|
11 |
end;
|
|
12 |
|
411
|
13 |
signature THY_SYN =
|
3619
|
14 |
sig
|
6206
|
15 |
include BASIC_THY_SYN
|
3619
|
16 |
val add_syntax: string list ->
|
|
17 |
(string * (ThyParse.token list -> (string * string) * ThyParse.token list)) list
|
|
18 |
-> unit
|
6206
|
19 |
val get_lexicon: unit -> Scan.lexicon;
|
|
20 |
val load_thy: string -> string list -> unit
|
3619
|
21 |
end;
|
411
|
22 |
|
3619
|
23 |
structure ThySyn: THY_SYN =
|
411
|
24 |
struct
|
|
25 |
|
6206
|
26 |
|
3619
|
27 |
(* current syntax *)
|
|
28 |
|
|
29 |
val keywords = ref ThyParse.pure_keywords;
|
|
30 |
val sections = ref ThyParse.pure_sections;
|
|
31 |
|
|
32 |
fun make_syntax () =
|
|
33 |
ThyParse.make_syntax (! keywords) (!sections);
|
|
34 |
|
|
35 |
val syntax = ref (make_syntax ());
|
|
36 |
|
6206
|
37 |
fun get_lexicon () = ThyParse.get_lexicon (! syntax);
|
|
38 |
|
411
|
39 |
|
3619
|
40 |
(* augment syntax *)
|
|
41 |
|
|
42 |
fun add_syntax keys sects =
|
3620
|
43 |
(keywords := (keys union ! keywords);
|
3619
|
44 |
sections := sects @ ! sections;
|
|
45 |
syntax := make_syntax ());
|
|
46 |
|
|
47 |
|
6206
|
48 |
(* load_thy *)
|
|
49 |
|
|
50 |
val delete_tmpfiles = ref true;
|
3619
|
51 |
|
6206
|
52 |
fun load_thy name chs =
|
|
53 |
let
|
|
54 |
val tmp_path = File.tmp_path (ThyLoad.ml_path (name ^ "_thy"));
|
|
55 |
val txt_out = ThyParse.parse_thy (! syntax) chs;
|
|
56 |
in
|
|
57 |
File.write tmp_path txt_out;
|
6231
|
58 |
Symbol.use tmp_path;
|
6206
|
59 |
if ! delete_tmpfiles then File.rm tmp_path else ()
|
|
60 |
end;
|
|
61 |
|
411
|
62 |
|
|
63 |
end;
|
6206
|
64 |
|
|
65 |
|
|
66 |
structure BasicThySyn: BASIC_THY_SYN = ThySyn;
|
|
67 |
open BasicThySyn;
|