author | wenzelm |
Mon, 16 Mar 2009 18:24:30 +0100 | |
changeset 30549 | d2d7874648bd |
parent 30447 | 955190fa639b |
child 31723 | f5cafe803b55 |
permissions | -rw-r--r-- |
14620
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
1 |
(* Title: HOL/Import/proof_kernel.ML |
29265
5b4247055bd7
moved old add_term_vars, add_term_frees etc. to structure OldTerm;
wenzelm
parents:
28965
diff
changeset
|
2 |
Author: Sebastian Skalberg and Steven Obua, TU Muenchen |
14620
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
3 |
*) |
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
4 |
|
14516 | 5 |
signature ProofKernel = |
6 |
sig |
|
7 |
type hol_type |
|
8 |
type tag |
|
9 |
type term |
|
10 |
type thm |
|
11 |
type ('a,'b) subst |
|
24707 | 12 |
|
14516 | 13 |
type proof_info |
14 |
datatype proof = Proof of proof_info * proof_content |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
15 |
and proof_content |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
16 |
= PRefl of term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
17 |
| PInstT of proof * (hol_type,hol_type) subst |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
18 |
| PSubst of proof list * term * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
19 |
| PAbs of proof * term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
20 |
| PDisch of proof * term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
21 |
| PMp of proof * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
22 |
| PHyp of term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
23 |
| PAxm of string * term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
24 |
| PDef of string * string * term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
25 |
| PTmSpec of string * string list * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
26 |
| PTyDef of string * string * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
27 |
| PTyIntro of string * string * string * string * term * term * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
28 |
| POracle of tag * term list * term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
29 |
| PDisk |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
30 |
| PSpec of proof * term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
31 |
| PInst of proof * (term,term) subst |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
32 |
| PGen of proof * term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
33 |
| PGenAbs of proof * term option * term list |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
34 |
| PImpAS of proof * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
35 |
| PSym of proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
36 |
| PTrans of proof * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
37 |
| PComb of proof * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
38 |
| PEqMp of proof * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
39 |
| PEqImp of proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
40 |
| PExists of proof * term * term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
41 |
| PChoose of term * proof * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
42 |
| PConj of proof * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
43 |
| PConjunct1 of proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
44 |
| PConjunct2 of proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
45 |
| PDisj1 of proof * term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
46 |
| PDisj2 of proof * term |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
47 |
| PDisjCases of proof * proof * proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
48 |
| PNotI of proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
49 |
| PNotE of proof |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
50 |
| PContr of proof * term |
14516 | 51 |
|
52 |
exception PK of string * string |
|
53 |
||
14620
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
54 |
val get_proof_dir: string -> theory -> string option |
17657 | 55 |
val disambiguate_frees : Thm.thm -> Thm.thm |
14516 | 56 |
val debug : bool ref |
57 |
val disk_info_of : proof -> (string * string) option |
|
58 |
val set_disk_info_of : proof -> string -> string -> unit |
|
59 |
val mk_proof : proof_content -> proof |
|
60 |
val content_of : proof -> proof_content |
|
61 |
val import_proof : string -> string -> theory -> (theory -> term) option * (theory -> proof) |
|
62 |
||
63 |
val rewrite_hol4_term: Term.term -> theory -> Thm.thm |
|
64 |
||
65 |
val type_of : term -> hol_type |
|
66 |
||
67 |
val get_thm : string -> string -> theory -> (theory * thm option) |
|
68 |
val get_def : string -> string -> term -> theory -> (theory * thm option) |
|
69 |
val get_axiom: string -> string -> theory -> (theory * thm option) |
|
70 |
||
71 |
val store_thm : string -> string -> thm -> theory -> theory * thm |
|
72 |
||
73 |
val to_isa_thm : thm -> (term * term) list * Thm.thm |
|
74 |
val to_isa_term: term -> Term.term |
|
19064 | 75 |
val to_hol_thm : Thm.thm -> thm |
14516 | 76 |
|
77 |
val REFL : term -> theory -> theory * thm |
|
78 |
val ASSUME : term -> theory -> theory * thm |
|
79 |
val INST_TYPE : (hol_type,hol_type) subst -> thm -> theory -> theory * thm |
|
80 |
val INST : (term,term)subst -> thm -> theory -> theory * thm |
|
81 |
val EQ_MP : thm -> thm -> theory -> theory * thm |
|
82 |
val EQ_IMP_RULE : thm -> theory -> theory * thm |
|
83 |
val SUBST : thm list -> term -> thm -> theory -> theory * thm |
|
84 |
val DISJ_CASES : thm -> thm -> thm -> theory -> theory * thm |
|
85 |
val DISJ1: thm -> term -> theory -> theory * thm |
|
86 |
val DISJ2: term -> thm -> theory -> theory * thm |
|
87 |
val IMP_ANTISYM: thm -> thm -> theory -> theory * thm |
|
88 |
val SYM : thm -> theory -> theory * thm |
|
89 |
val MP : thm -> thm -> theory -> theory * thm |
|
90 |
val GEN : term -> thm -> theory -> theory * thm |
|
91 |
val CHOOSE : term -> thm -> thm -> theory -> theory * thm |
|
92 |
val EXISTS : term -> term -> thm -> theory -> theory * thm |
|
93 |
val ABS : term -> thm -> theory -> theory * thm |
|
94 |
val GEN_ABS : term option -> term list -> thm -> theory -> theory * thm |
|
95 |
val TRANS : thm -> thm -> theory -> theory * thm |
|
96 |
val CCONTR : term -> thm -> theory -> theory * thm |
|
97 |
val CONJ : thm -> thm -> theory -> theory * thm |
|
98 |
val CONJUNCT1: thm -> theory -> theory * thm |
|
99 |
val CONJUNCT2: thm -> theory -> theory * thm |
|
100 |
val NOT_INTRO: thm -> theory -> theory * thm |
|
101 |
val NOT_ELIM : thm -> theory -> theory * thm |
|
102 |
val SPEC : term -> thm -> theory -> theory * thm |
|
103 |
val COMB : thm -> thm -> theory -> theory * thm |
|
104 |
val DISCH: term -> thm -> theory -> theory * thm |
|
105 |
||
106 |
val type_introduction: string -> string -> string -> string -> string -> term * term -> thm -> theory -> theory * thm |
|
107 |
||
108 |
val new_definition : string -> string -> term -> theory -> theory * thm |
|
109 |
val new_specification : string -> string -> string list -> thm -> theory -> theory * thm |
|
110 |
val new_type_definition : string -> string -> string -> thm -> theory -> theory * thm |
|
111 |
val new_axiom : string -> term -> theory -> theory * thm |
|
112 |
||
24707 | 113 |
val prin : term -> unit |
114 |
val protect_factname : string -> string |
|
19067 | 115 |
val replay_protect_varname : string -> string -> unit |
19068 | 116 |
val replay_add_dump : string -> theory -> theory |
14516 | 117 |
end |
118 |
||
119 |
structure ProofKernel :> ProofKernel = |
|
120 |
struct |
|
121 |
type hol_type = Term.typ |
|
122 |
type term = Term.term |
|
123 |
datatype tag = Tag of string list |
|
124 |
type ('a,'b) subst = ('a * 'b) list |
|
125 |
datatype thm = HOLThm of (Term.term * Term.term) list * Thm.thm |
|
126 |
||
24707 | 127 |
fun hthm2thm (HOLThm (_, th)) = th |
17324 | 128 |
|
19064 | 129 |
fun to_hol_thm th = HOLThm ([], th) |
17328 | 130 |
|
19068 | 131 |
val replay_add_dump = add_dump |
132 |
fun add_dump s thy = (ImportRecorder.add_dump s; replay_add_dump s thy) |
|
133 |
||
14516 | 134 |
datatype proof_info |
135 |
= Info of {disk_info: (string * string) option ref} |
|
24707 | 136 |
|
14516 | 137 |
datatype proof = Proof of proof_info * proof_content |
138 |
and proof_content |
|
139 |
= PRefl of term |
|
140 |
| PInstT of proof * (hol_type,hol_type) subst |
|
141 |
| PSubst of proof list * term * proof |
|
142 |
| PAbs of proof * term |
|
143 |
| PDisch of proof * term |
|
144 |
| PMp of proof * proof |
|
145 |
| PHyp of term |
|
146 |
| PAxm of string * term |
|
147 |
| PDef of string * string * term |
|
148 |
| PTmSpec of string * string list * proof |
|
149 |
| PTyDef of string * string * proof |
|
150 |
| PTyIntro of string * string * string * string * term * term * proof |
|
151 |
| POracle of tag * term list * term |
|
152 |
| PDisk |
|
153 |
| PSpec of proof * term |
|
154 |
| PInst of proof * (term,term) subst |
|
155 |
| PGen of proof * term |
|
156 |
| PGenAbs of proof * term option * term list |
|
157 |
| PImpAS of proof * proof |
|
158 |
| PSym of proof |
|
159 |
| PTrans of proof * proof |
|
160 |
| PComb of proof * proof |
|
161 |
| PEqMp of proof * proof |
|
162 |
| PEqImp of proof |
|
163 |
| PExists of proof * term * term |
|
164 |
| PChoose of term * proof * proof |
|
165 |
| PConj of proof * proof |
|
166 |
| PConjunct1 of proof |
|
167 |
| PConjunct2 of proof |
|
168 |
| PDisj1 of proof * term |
|
169 |
| PDisj2 of proof * term |
|
170 |
| PDisjCases of proof * proof * proof |
|
171 |
| PNotI of proof |
|
172 |
| PNotE of proof |
|
173 |
| PContr of proof * term |
|
174 |
||
175 |
exception PK of string * string |
|
176 |
fun ERR f mesg = PK (f,mesg) |
|
177 |
||
24707 | 178 |
fun print_exn e = |
14516 | 179 |
case e of |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
180 |
PK (m,s) => (writeln ("PK (" ^ m ^ "): " ^ s); raise e) |
17959 | 181 |
| _ => OldGoals.print_exn e |
14516 | 182 |
|
183 |
(* Compatibility. *) |
|
184 |
||
19264 | 185 |
val string_of_mixfix = Pretty.string_of o Syntax.pretty_mixfix; |
186 |
||
14685 | 187 |
fun mk_syn thy c = |
16427 | 188 |
if Syntax.is_identifier c andalso not (Syntax.is_keyword (Sign.syn_of thy) c) then NoSyn |
14685 | 189 |
else Syntax.literal c |
14516 | 190 |
|
14673 | 191 |
fun quotename c = |
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
27187
diff
changeset
|
192 |
if Syntax.is_identifier c andalso not (OuterKeyword.is_keyword c) then c else quote c |
14516 | 193 |
|
17652 | 194 |
fun simple_smart_string_of_cterm ct = |
195 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
196 |
val thy = Thm.theory_of_cterm ct; |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
197 |
val {t,T,...} = rep_cterm ct |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
198 |
(* Hack to avoid parse errors with Trueprop *) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
199 |
val ct = (cterm_of thy (HOLogic.dest_Trueprop t) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
200 |
handle TERM _ => ct) |
17652 | 201 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
202 |
quote( |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
203 |
PrintMode.setmp [] ( |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
204 |
Library.setmp show_brackets false ( |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
205 |
Library.setmp show_all_types true ( |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
206 |
Library.setmp Syntax.ambiguity_is_error false ( |
26928 | 207 |
Library.setmp show_sorts true Display.string_of_cterm)))) |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
208 |
ct) |
17652 | 209 |
end |
210 |
||
19064 | 211 |
exception SMART_STRING |
212 |
||
14516 | 213 |
fun smart_string_of_cterm ct = |
214 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
215 |
val thy = Thm.theory_of_cterm ct |
24707 | 216 |
val ctxt = ProofContext.init thy |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
217 |
val {t,T,...} = rep_cterm ct |
14516 | 218 |
(* Hack to avoid parse errors with Trueprop *) |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
219 |
val ct = (cterm_of thy (HOLogic.dest_Trueprop t) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
220 |
handle TERM _ => ct) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
221 |
fun match u = t aconv u |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
222 |
fun G 0 = Library.setmp show_types true (Library.setmp show_sorts true) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
223 |
| G 1 = Library.setmp show_brackets true (G 0) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
224 |
| G 2 = Library.setmp show_all_types true (G 0) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
225 |
| G 3 = Library.setmp show_brackets true (G 2) |
24707 | 226 |
| G _ = raise SMART_STRING |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
227 |
fun F n = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
228 |
let |
26928 | 229 |
val str = Library.setmp show_brackets false (G n Display.string_of_cterm) ct |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
230 |
val u = Syntax.parse_term ctxt str |
24707 | 231 |
|> TypeInfer.constrain T |> Syntax.check_term ctxt |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
232 |
in |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
233 |
if match u |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
234 |
then quote str |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
235 |
else F (n+1) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
236 |
end |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
237 |
handle ERROR mesg => F (n+1) |
27187 | 238 |
| SMART_STRING => error ("smart_string failed for: "^(G 0 Display.string_of_cterm ct)) |
14516 | 239 |
in |
24634 | 240 |
PrintMode.setmp [] (Library.setmp Syntax.ambiguity_is_error true F) 0 |
14516 | 241 |
end |
18678 | 242 |
handle ERROR mesg => simple_smart_string_of_cterm ct |
24707 | 243 |
|
14516 | 244 |
val smart_string_of_thm = smart_string_of_cterm o cprop_of |
245 |
||
26928 | 246 |
fun prth th = writeln (PrintMode.setmp [] Display.string_of_thm th) |
247 |
fun prc ct = writeln (PrintMode.setmp [] Display.string_of_cterm ct) |
|
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26928
diff
changeset
|
248 |
fun prin t = writeln (PrintMode.setmp [] (fn () => Syntax.string_of_term_global (the_context ()) t) ()); |
14516 | 249 |
fun pth (HOLThm(ren,thm)) = |
250 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
251 |
(*val _ = writeln "Renaming:" |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
252 |
val _ = app (fn(v,w) => (prin v; writeln " -->"; prin w)) ren*) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
253 |
val _ = prth thm |
14516 | 254 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
255 |
() |
14516 | 256 |
end |
257 |
||
258 |
fun disk_info_of (Proof(Info{disk_info,...},_)) = !disk_info |
|
15531 | 259 |
fun mk_proof p = Proof(Info{disk_info = ref NONE},p) |
14516 | 260 |
fun content_of (Proof(_,p)) = p |
261 |
||
262 |
fun set_disk_info_of (Proof(Info{disk_info,...},_)) thyname thmname = |
|
15531 | 263 |
disk_info := SOME(thyname,thmname) |
14516 | 264 |
|
265 |
structure Lib = |
|
266 |
struct |
|
267 |
||
268 |
fun assoc x = |
|
269 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
270 |
fun F [] = raise PK("Lib.assoc","Not found") |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
271 |
| F ((x',y)::rest) = if x = x' |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
272 |
then y |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
273 |
else F rest |
14516 | 274 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
275 |
F |
14516 | 276 |
end |
24707 | 277 |
fun i mem L = |
278 |
let fun itr [] = false |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
279 |
| itr (a::rst) = i=a orelse itr rst |
14516 | 280 |
in itr L end; |
24707 | 281 |
|
14516 | 282 |
fun [] union S = S |
283 |
| S union [] = S |
|
29289 | 284 |
| (a::rst) union S2 = rst union (insert (op =) a S2) |
24707 | 285 |
|
14516 | 286 |
fun implode_subst [] = [] |
287 |
| implode_subst (x::r::rest) = ((x,r)::(implode_subst rest)) |
|
288 |
| implode_subst _ = raise ERR "implode_subst" "malformed substitution list" |
|
289 |
||
290 |
end |
|
291 |
open Lib |
|
292 |
||
293 |
structure Tag = |
|
294 |
struct |
|
295 |
val empty_tag = Tag [] |
|
296 |
fun read name = Tag [name] |
|
297 |
fun merge (Tag tag1) (Tag tag2) = Tag (Lib.union(tag1,tag2)) |
|
298 |
end |
|
299 |
||
24707 | 300 |
(* Actual code. *) |
14516 | 301 |
|
302 |
fun get_segment thyname l = (Lib.assoc "s" l |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
303 |
handle PK _ => thyname) |
14518
c3019a66180f
Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents:
14516
diff
changeset
|
304 |
val get_name : (string * string) list -> string = Lib.assoc "n" |
14516 | 305 |
|
306 |
local |
|
307 |
open LazyScan |
|
308 |
infix 7 |-- --| |
|
309 |
infix 5 :-- -- ^^ |
|
310 |
infix 3 >> |
|
311 |
infix 0 || |
|
312 |
in |
|
313 |
exception XML of string |
|
314 |
||
315 |
datatype xml = Elem of string * (string * string) list * xml list |
|
316 |
datatype XMLtype = XMLty of xml | FullType of hol_type |
|
317 |
datatype XMLterm = XMLtm of xml | FullTerm of term |
|
318 |
||
319 |
fun pair x y = (x,y) |
|
320 |
||
321 |
fun scan_id toks = |
|
322 |
let |
|
323 |
val (x,toks2) = one Char.isAlpha toks |
|
324 |
val (xs,toks3) = any Char.isAlphaNum toks2 |
|
325 |
in |
|
326 |
(String.implode (x::xs),toks3) |
|
327 |
end |
|
328 |
||
329 |
fun scan_string str c = |
|
330 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
331 |
fun F [] toks = (c,toks) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
332 |
| F (c::cs) toks = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
333 |
case LazySeq.getItem toks of |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
334 |
SOME(c',toks') => |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
335 |
if c = c' |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
336 |
then F cs toks' |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
337 |
else raise SyntaxError |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
338 |
| NONE => raise SyntaxError |
14516 | 339 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
340 |
F (String.explode str) |
14516 | 341 |
end |
342 |
||
343 |
local |
|
344 |
val scan_entity = |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
345 |
(scan_string "amp;" #"&") |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
346 |
|| scan_string "quot;" #"\"" |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
347 |
|| scan_string "gt;" #">" |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
348 |
|| scan_string "lt;" #"<" |
14620
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
349 |
|| scan_string "apos;" #"'" |
14516 | 350 |
in |
351 |
fun scan_nonquote toks = |
|
352 |
case LazySeq.getItem toks of |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
353 |
SOME (c,toks') => |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
354 |
(case c of |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
355 |
#"\"" => raise SyntaxError |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
356 |
| #"&" => scan_entity toks' |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
357 |
| c => (c,toks')) |
15531 | 358 |
| NONE => raise SyntaxError |
14516 | 359 |
end |
360 |
||
361 |
val scan_string = $$ #"\"" |-- repeat scan_nonquote --| $$ #"\"" >> |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
362 |
String.implode |
14516 | 363 |
|
364 |
val scan_attribute = scan_id -- $$ #"=" |-- scan_string |
|
365 |
||
366 |
val scan_start_of_tag = $$ #"<" |-- scan_id -- |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
367 |
repeat ($$ #" " |-- scan_attribute) |
14516 | 368 |
|
14518
c3019a66180f
Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents:
14516
diff
changeset
|
369 |
(* The evaluation delay introduced through the 'toks' argument is needed |
c3019a66180f
Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents:
14516
diff
changeset
|
370 |
for the sake of the SML/NJ (110.9.1) compiler. Either that or an explicit |
c3019a66180f
Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents:
14516
diff
changeset
|
371 |
type :-( *) |
c3019a66180f
Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents:
14516
diff
changeset
|
372 |
fun scan_end_of_tag toks = ($$ #"/" |-- $$ #">" |-- succeed []) toks |
c3019a66180f
Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents:
14516
diff
changeset
|
373 |
|
14516 | 374 |
val scan_end_tag = $$ #"<" |-- $$ #"/" |-- scan_id --| $$ #">" |
375 |
||
376 |
fun scan_children id = $$ #">" |-- repeat scan_tag -- scan_end_tag >> |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
377 |
(fn (chldr,id') => if id = id' |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
378 |
then chldr |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
379 |
else raise XML "Tag mismatch") |
14516 | 380 |
and scan_tag toks = |
381 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
382 |
val ((id,atts),toks2) = scan_start_of_tag toks |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
383 |
val (chldr,toks3) = (scan_children id || scan_end_of_tag) toks2 |
14516 | 384 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
385 |
(Elem (id,atts,chldr),toks3) |
14516 | 386 |
end |
387 |
end |
|
388 |
||
389 |
val type_of = Term.type_of |
|
390 |
||
391 |
val boolT = Type("bool",[]) |
|
392 |
val propT = Type("prop",[]) |
|
393 |
||
394 |
fun mk_defeq name rhs thy = |
|
395 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
396 |
val ty = type_of rhs |
14516 | 397 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
398 |
Logic.mk_equals (Const(Sign.intern_const thy name,ty),rhs) |
14516 | 399 |
end |
400 |
||
401 |
fun mk_teq name rhs thy = |
|
402 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
403 |
val ty = type_of rhs |
14516 | 404 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
405 |
HOLogic.mk_eq (Const(Sign.intern_const thy name,ty),rhs) |
14516 | 406 |
end |
407 |
||
408 |
fun intern_const_name thyname const thy = |
|
409 |
case get_hol4_const_mapping thyname const thy of |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
410 |
SOME (_,cname,_) => cname |
15531 | 411 |
| NONE => (case get_hol4_const_renaming thyname const thy of |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
412 |
SOME cname => Sign.intern_const thy (thyname ^ "." ^ cname) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
413 |
| NONE => Sign.intern_const thy (thyname ^ "." ^ const)) |
14516 | 414 |
|
415 |
fun intern_type_name thyname const thy = |
|
416 |
case get_hol4_type_mapping thyname const thy of |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
417 |
SOME (_,cname) => cname |
17894 | 418 |
| NONE => Sign.intern_const thy (thyname ^ "." ^ const) |
14516 | 419 |
|
420 |
fun mk_vartype name = TFree(name,["HOL.type"]) |
|
421 |
fun mk_thy_type thy Thy Tyop Args = Type(intern_type_name Thy Tyop thy,Args) |
|
422 |
||
423 |
val mk_var = Free |
|
424 |
||
425 |
fun dom_rng (Type("fun",[dom,rng])) = (dom,rng) |
|
426 |
| dom_rng _ = raise ERR "dom_rng" "Not a functional type" |
|
427 |
||
16486 | 428 |
fun mk_thy_const thy Thy Nam Ty = Const(intern_const_name Thy Nam thy,Ty) |
14516 | 429 |
|
24707 | 430 |
local |
431 |
fun get_const sg thyname name = |
|
17894 | 432 |
(case Sign.const_type sg name of |
433 |
SOME ty => Const (name, ty) |
|
434 |
| NONE => raise ERR "get_type" (name ^ ": No such constant")) |
|
14516 | 435 |
in |
16486 | 436 |
fun prim_mk_const thy Thy Nam = |
14516 | 437 |
let |
17894 | 438 |
val name = intern_const_name Thy Nam thy |
439 |
val cmaps = HOL4ConstMaps.get thy |
|
14516 | 440 |
in |
17894 | 441 |
case StringPair.lookup cmaps (Thy,Nam) of |
442 |
SOME(_,_,SOME ty) => Const(name,ty) |
|
443 |
| _ => get_const thy Thy name |
|
14516 | 444 |
end |
445 |
end |
|
446 |
||
447 |
fun mk_comb(f,a) = f $ a |
|
448 |
||
449 |
(* Needed for HOL Light *) |
|
450 |
fun protect_tyvarname s = |
|
451 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
452 |
fun no_quest s = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
453 |
if Char.contains s #"?" |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
454 |
then String.translate (fn #"?" => "q_" | c => Char.toString c) s |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
455 |
else s |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
456 |
fun beg_prime s = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
457 |
if String.isPrefix "'" s |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
458 |
then s |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
459 |
else "'" ^ s |
14516 | 460 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
461 |
s |> no_quest |> beg_prime |
14516 | 462 |
end |
17440
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
463 |
|
17444 | 464 |
val protected_varnames = ref (Symtab.empty:string Symtab.table) |
24630
351a308ab58d
simplified type int (eliminated IntInf.int, integer);
wenzelm
parents:
22709
diff
changeset
|
465 |
val invented_isavar = ref 0 |
17444 | 466 |
|
17490 | 467 |
fun innocent_varname s = Syntax.is_identifier s andalso not (String.isPrefix "u_" s) |
468 |
||
18678 | 469 |
val check_name_thy = theory "Main" |
17592 | 470 |
|
18678 | 471 |
fun valid_boundvarname s = |
24707 | 472 |
can (fn () => Syntax.read_term_global check_name_thy ("SOME "^s^". True")) (); |
18678 | 473 |
|
474 |
fun valid_varname s = |
|
24707 | 475 |
can (fn () => Syntax.read_term_global check_name_thy s) (); |
17490 | 476 |
|
14516 | 477 |
fun protect_varname s = |
17490 | 478 |
if innocent_varname s andalso valid_varname s then s else |
17444 | 479 |
case Symtab.lookup (!protected_varnames) s of |
480 |
SOME t => t |
|
24707 | 481 |
| NONE => |
17444 | 482 |
let |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
483 |
val _ = inc invented_isavar |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
484 |
val t = "u_" ^ string_of_int (!invented_isavar) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
485 |
val _ = ImportRecorder.protect_varname s t |
17444 | 486 |
val _ = protected_varnames := Symtab.update (s, t) (!protected_varnames) |
487 |
in |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
488 |
t |
17444 | 489 |
end |
14516 | 490 |
|
19067 | 491 |
exception REPLAY_PROTECT_VARNAME of string*string*string |
492 |
||
24707 | 493 |
fun replay_protect_varname s t = |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
494 |
case Symtab.lookup (!protected_varnames) s of |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
495 |
SOME t' => raise REPLAY_PROTECT_VARNAME (s, t, t') |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
496 |
| NONE => |
19067 | 497 |
let |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
498 |
val _ = inc invented_isavar |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
499 |
val t = "u_" ^ string_of_int (!invented_isavar) |
19067 | 500 |
val _ = protected_varnames := Symtab.update (s, t) (!protected_varnames) |
501 |
in |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
502 |
() |
24707 | 503 |
end |
504 |
||
17490 | 505 |
fun protect_boundvarname s = if innocent_varname s andalso valid_boundvarname s then s else "u" |
17440
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
506 |
|
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
507 |
fun mk_lambda (v as Free (x, T)) t = Abs (protect_boundvarname x, T, abstract_over (v, t)) |
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
508 |
| mk_lambda (v as Var ((x, _), T)) t = Abs (protect_boundvarname x, T, abstract_over (v, t)) |
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
509 |
| mk_lambda v t = raise TERM ("lambda", [v, t]); |
24707 | 510 |
|
511 |
fun replacestr x y s = |
|
17440
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
512 |
let |
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
513 |
val xl = explode x |
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
514 |
val yl = explode y |
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
515 |
fun isprefix [] ys = true |
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
516 |
| isprefix (x::xs) (y::ys) = if x = y then isprefix xs ys else false |
24707 | 517 |
| isprefix _ _ = false |
17440
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
518 |
fun isp s = isprefix xl s |
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
519 |
fun chg s = yl@(List.drop (s, List.length xl)) |
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
520 |
fun r [] = [] |
24707 | 521 |
| r (S as (s::ss)) = if isp S then r (chg S) else s::(r ss) |
17440
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
522 |
in |
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
523 |
implode(r (explode s)) |
24707 | 524 |
end |
17440
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
525 |
|
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
526 |
fun protect_factname s = replacestr "." "_dot_" s |
24707 | 527 |
fun unprotect_factname s = replacestr "_dot_" "." s |
17440
df77edc4f5d0
fixed HOL-light/Isabelle syntax incompatability via more protect_xxx functions
obua
parents:
17412
diff
changeset
|
528 |
|
17322 | 529 |
val ty_num_prefix = "N_" |
530 |
||
531 |
fun startsWithDigit s = Char.isDigit (hd (String.explode s)) |
|
532 |
||
24707 | 533 |
fun protect_tyname tyn = |
17322 | 534 |
let |
24707 | 535 |
val tyn' = |
536 |
if String.isPrefix ty_num_prefix tyn then raise (ERR "protect_ty_name" ("type name '"^tyn^"' is reserved")) else |
|
17322 | 537 |
(if startsWithDigit tyn then ty_num_prefix^tyn else tyn) |
538 |
in |
|
539 |
tyn' |
|
540 |
end |
|
541 |
||
24707 | 542 |
fun protect_constname tcn = tcn |
17444 | 543 |
(* if tcn = ".." then "dotdot" |
544 |
else if tcn = "==" then "eqeq" |
|
545 |
else tcn*) |
|
17322 | 546 |
|
14516 | 547 |
structure TypeNet = |
548 |
struct |
|
17322 | 549 |
|
14516 | 550 |
fun get_type_from_index thy thyname types is = |
551 |
case Int.fromString is of |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
552 |
SOME i => (case Array.sub(types,i) of |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
553 |
FullType ty => ty |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
554 |
| XMLty xty => |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
555 |
let |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
556 |
val ty = get_type_from_xml thy thyname types xty |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
557 |
val _ = Array.update(types,i,FullType ty) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
558 |
in |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
559 |
ty |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
560 |
end) |
14516 | 561 |
| NONE => raise ERR "get_type_from_index" "Bad index" |
562 |
and get_type_from_xml thy thyname types = |
|
563 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
564 |
fun gtfx (Elem("tyi",[("i",iS)],[])) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
565 |
get_type_from_index thy thyname types iS |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
566 |
| gtfx (Elem("tyc",atts,[])) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
567 |
mk_thy_type thy |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
568 |
(get_segment thyname atts) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
569 |
(protect_tyname (get_name atts)) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
570 |
[] |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
571 |
| gtfx (Elem("tyv",[("n",s)],[])) = mk_vartype (protect_tyvarname s) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
572 |
| gtfx (Elem("tya",[],(Elem("tyc",atts,[]))::tys)) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
573 |
mk_thy_type thy |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
574 |
(get_segment thyname atts) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
575 |
(protect_tyname (get_name atts)) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
576 |
(map gtfx tys) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
577 |
| gtfx _ = raise ERR "get_type" "Bad type" |
14516 | 578 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
579 |
gtfx |
14516 | 580 |
end |
581 |
||
582 |
fun input_types thyname (Elem("tylist",[("i",i)],xtys)) = |
|
583 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
584 |
val types = Array.array(valOf (Int.fromString i),XMLty (Elem("",[],[]))) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
585 |
fun IT _ [] = () |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
586 |
| IT n (xty::xtys) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
587 |
(Array.update(types,n,XMLty xty); |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
588 |
IT (n+1) xtys) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
589 |
val _ = IT 0 xtys |
14516 | 590 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
591 |
types |
14516 | 592 |
end |
593 |
| input_types _ _ = raise ERR "input_types" "Bad type list" |
|
594 |
end |
|
595 |
||
596 |
structure TermNet = |
|
597 |
struct |
|
17322 | 598 |
|
14516 | 599 |
fun get_term_from_index thy thyname types terms is = |
600 |
case Int.fromString is of |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
601 |
SOME i => (case Array.sub(terms,i) of |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
602 |
FullTerm tm => tm |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
603 |
| XMLtm xtm => |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
604 |
let |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
605 |
val tm = get_term_from_xml thy thyname types terms xtm |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
606 |
val _ = Array.update(terms,i,FullTerm tm) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
607 |
in |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
608 |
tm |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
609 |
end) |
14516 | 610 |
| NONE => raise ERR "get_term_from_index" "Bad index" |
611 |
and get_term_from_xml thy thyname types terms = |
|
612 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
613 |
fun get_type [] = NONE |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
614 |
| get_type [ty] = SOME (TypeNet.get_type_from_xml thy thyname types ty) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
615 |
| get_type _ = raise ERR "get_term" "Bad type" |
14516 | 616 |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
617 |
fun gtfx (Elem("tmv",[("n",name),("t",tyi)],[])) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
618 |
mk_var(protect_varname name,TypeNet.get_type_from_index thy thyname types tyi) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
619 |
| gtfx (Elem("tmc",atts,[])) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
620 |
let |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
621 |
val segment = get_segment thyname atts |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
622 |
val name = protect_constname(get_name atts) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
623 |
in |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
624 |
mk_thy_const thy segment name (TypeNet.get_type_from_index thy thyname types (Lib.assoc "t" atts)) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
625 |
handle PK _ => prim_mk_const thy segment name |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
626 |
end |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
627 |
| gtfx (Elem("tma",[("f",tmf),("a",tma)],[])) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
628 |
let |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
629 |
val f = get_term_from_index thy thyname types terms tmf |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
630 |
val a = get_term_from_index thy thyname types terms tma |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
631 |
in |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
632 |
mk_comb(f,a) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
633 |
end |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
634 |
| gtfx (Elem("tml",[("x",tmx),("a",tma)],[])) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
635 |
let |
24707 | 636 |
val x = get_term_from_index thy thyname types terms tmx |
17490 | 637 |
val a = get_term_from_index thy thyname types terms tma |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
638 |
in |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
639 |
mk_lambda x a |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
640 |
end |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
641 |
| gtfx (Elem("tmi",[("i",iS)],[])) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
642 |
get_term_from_index thy thyname types terms iS |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
643 |
| gtfx (Elem(tag,_,_)) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
644 |
raise ERR "get_term" ("Not a term: "^tag) |
14516 | 645 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
646 |
gtfx |
14516 | 647 |
end |
648 |
||
649 |
fun input_terms thyname types (Elem("tmlist",[("i",i)],xtms)) = |
|
650 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
651 |
val terms = Array.array(valOf(Int.fromString i),XMLtm (Elem("",[],[]))) |
14516 | 652 |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
653 |
fun IT _ [] = () |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
654 |
| IT n (xtm::xtms) = |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
655 |
(Array.update(terms,n,XMLtm xtm); |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
656 |
IT (n+1) xtms) |
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
657 |
val _ = IT 0 xtms |
14516 | 658 |
in |
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26343
diff
changeset
|
659 |
terms |
14516 | 660 |
end |
661 |
| input_terms _ _ _ = raise ERR "input_terms" "Bad term list" |
|
662 |
end |
|
663 |
||
664 |
fun get_proof_dir (thyname:string) thy = |
|
665 |
let |
|
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm |