author | haftmann |
Mon, 02 Oct 2006 23:00:51 +0200 | |
changeset 20835 | 27d049062b56 |
parent 20676 | 21e096f30c5d |
child 20926 | b2f67b947200 |
permissions | -rw-r--r-- |
1132
dfb29abcf3c2
added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff
changeset
|
1 |
(* Title: Pure/Thy/thm_database.ML |
dfb29abcf3c2
added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff
changeset
|
2 |
ID: $Id$ |
11895 | 3 |
Author: Markus Wenzel, TU Muenchen |
1132
dfb29abcf3c2
added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff
changeset
|
4 |
|
17170 | 5 |
ML toplevel interface to the theorem database. |
4023 | 6 |
*) |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1245
diff
changeset
|
7 |
|
6204 | 8 |
signature BASIC_THM_DATABASE = |
4023 | 9 |
sig |
10 |
val store_thm: string * thm -> thm |
|
7410 | 11 |
val store_thms: string * thm list -> thm list |
17170 | 12 |
val legacy_bindings: theory -> string |
13 |
val use_legacy_bindings: theory -> unit |
|
4023 | 14 |
end; |
1132
dfb29abcf3c2
added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff
changeset
|
15 |
|
6204 | 16 |
signature THM_DATABASE = |
17 |
sig |
|
18 |
include BASIC_THM_DATABASE |
|
7410 | 19 |
val qed_thms: thm list ref |
6204 | 20 |
val ml_store_thm: string * thm -> unit |
7410 | 21 |
val ml_store_thms: string * thm list -> unit |
14680 | 22 |
val ml_reserved: string list |
20676 | 23 |
val is_ml_reserved: string -> bool |
6204 | 24 |
val is_ml_identifier: string -> bool |
25 |
end; |
|
26 |
||
3627 | 27 |
structure ThmDatabase: THM_DATABASE = |
1221 | 28 |
struct |
1132
dfb29abcf3c2
added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff
changeset
|
29 |
|
4023 | 30 |
(** store theorems **) |
1132
dfb29abcf3c2
added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff
changeset
|
31 |
|
13279
8a722689a1c9
removed thms_containing (see pure_thy.ML and proof_context.ML);
wenzelm
parents:
11895
diff
changeset
|
32 |
(* store in theory and perform presentation *) |
1136
3910c96551d1
fixed bug in thms_containing; changed error/warning messages;
clasohm
parents:
1134
diff
changeset
|
33 |
|
4023 | 34 |
fun store_thm (name, thm) = |
7410 | 35 |
let val thm' = hd (PureThy.smart_store_thms (name, [thm])) |
6327 | 36 |
in Present.theorem name thm'; thm' end; |
1132
dfb29abcf3c2
added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff
changeset
|
37 |
|
7410 | 38 |
fun store_thms (name, thms) = |
39 |
let val thms' = PureThy.smart_store_thms (name, thms) |
|
40 |
in Present.theorems name thms'; thms' end; |
|
41 |
||
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1245
diff
changeset
|
42 |
|
4023 | 43 |
(* store on ML toplevel *) |
44 |
||
7410 | 45 |
val qed_thms: thm list ref = ref []; |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1245
diff
changeset
|
46 |
|
4023 | 47 |
val ml_reserved = |
48 |
["abstype", "and", "andalso", "as", "case", "do", "datatype", "else", |
|
49 |
"end", "exception", "fn", "fun", "handle", "if", "in", "infix", |
|
50 |
"infixr", "let", "local", "nonfix", "of", "op", "open", "orelse", |
|
51 |
"raise", "rec", "then", "type", "val", "with", "withtype", "while", |
|
52 |
"eqtype", "functor", "include", "sharing", "sig", "signature", |
|
53 |
"struct", "structure", "where"]; |
|
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1245
diff
changeset
|
54 |
|
20676 | 55 |
val is_ml_reserved = member (op =) ml_reserved; |
56 |
||
4023 | 57 |
fun is_ml_identifier name = |
20676 | 58 |
not (is_ml_reserved name) andalso Syntax.is_ascii_identifier name; |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1245
diff
changeset
|
59 |
|
7410 | 60 |
fun warn_ml name = |
61 |
if is_ml_identifier name then false |
|
7573 | 62 |
else if name = "" then true |
7410 | 63 |
else (warning ("Cannot bind theorem(s) " ^ quote name ^ " as ML value"); true); |
64 |
||
10914 | 65 |
val use_text_verbose = use_text Context.ml_output true; |
7854 | 66 |
|
4023 | 67 |
fun ml_store_thm (name, thm) = |
68 |
let val thm' = store_thm (name, thm) in |
|
7410 | 69 |
if warn_ml name then () |
13279
8a722689a1c9
removed thms_containing (see pure_thy.ML and proof_context.ML);
wenzelm
parents:
11895
diff
changeset
|
70 |
else (qed_thms := [thm']; |
8a722689a1c9
removed thms_containing (see pure_thy.ML and proof_context.ML);
wenzelm
parents:
11895
diff
changeset
|
71 |
use_text_verbose ("val " ^ name ^ " = hd (! ThmDatabase.qed_thms);")) |
7410 | 72 |
end; |
73 |
||
74 |
fun ml_store_thms (name, thms) = |
|
75 |
let val thms' = store_thms (name, thms) in |
|
76 |
if warn_ml name then () |
|
7854 | 77 |
else (qed_thms := thms'; use_text_verbose ("val " ^ name ^ " = ! ThmDatabase.qed_thms;")) |
1262
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1245
diff
changeset
|
78 |
end; |
8f40ff1299d8
added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents:
1245
diff
changeset
|
79 |
|
4023 | 80 |
|
17170 | 81 |
(* legacy bindings *) |
82 |
||
83 |
fun legacy_bindings thy = |
|
84 |
let |
|
85 |
val thy_name = Context.theory_name thy; |
|
86 |
val (space, thms) = PureThy.theorems_of thy; |
|
87 |
||
88 |
fun prune name = |
|
89 |
let |
|
90 |
val xname = NameSpace.extern space name; |
|
91 |
fun result prfx bname = |
|
92 |
if (prfx = "" orelse is_ml_identifier prfx) andalso is_ml_identifier bname andalso |
|
93 |
NameSpace.intern space xname = name then |
|
17412 | 94 |
SOME (prfx, (bname, xname, length (the (Symtab.lookup thms name)) = 1)) |
17170 | 95 |
else NONE; |
96 |
val names = NameSpace.unpack name; |
|
97 |
in |
|
19012 | 98 |
(case #2 (chop (length names - 2) names) of |
17170 | 99 |
[bname] => result "" bname |
100 |
| [prfx, bname] => result (if prfx = thy_name then "" else prfx) bname |
|
101 |
| _ => NONE) |
|
102 |
end; |
|
103 |
||
104 |
fun mk_struct "" = I |
|
105 |
| mk_struct prfx = enclose ("structure " ^ prfx ^ " =\nstruct\n") "\nend\n"; |
|
106 |
||
107 |
fun mk_thm (bname, xname, singleton) = |
|
108 |
"val " ^ bname ^ " = thm" ^ (if singleton then "" else "s") ^ " " ^ quote xname; |
|
109 |
in |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19012
diff
changeset
|
110 |
Symtab.keys thms |> map_filter prune |
18931 | 111 |
|> Symtab.make_list |> Symtab.dest |> sort_wrt #1 |
17170 | 112 |
|> map (fn (prfx, entries) => |
113 |
entries |> sort_wrt #1 |> map mk_thm |> cat_lines |> mk_struct prfx) |
|
114 |
|> cat_lines |
|
115 |
end; |
|
116 |
||
117 |
fun use_legacy_bindings thy = Context.use_mltext (legacy_bindings thy) true (SOME thy); |
|
118 |
||
1132
dfb29abcf3c2
added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff
changeset
|
119 |
end; |
6204 | 120 |
|
121 |
structure BasicThmDatabase: BASIC_THM_DATABASE = ThmDatabase; |
|
122 |
open BasicThmDatabase; |