author | wenzelm |
Thu, 19 Jan 2006 21:22:08 +0100 | |
changeset 18708 | 4b3dadb4fe33 |
parent 18678 | dd0c569fa43d |
child 18734 | f5ea6b0d3501 |
permissions | -rw-r--r-- |
5823 | 1 |
(* Title: Pure/Isar/attrib.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
5 |
Symbolic theorem attributes. |
|
6 |
*) |
|
7 |
||
8 |
signature BASIC_ATTRIB = |
|
9 |
sig |
|
10 |
val print_attributes: theory -> unit |
|
16458 | 11 |
val Attribute: bstring -> |
12 |
(Args.src -> theory attribute) * (Args.src -> ProofContext.context attribute) -> |
|
13 |
string -> unit |
|
5823 | 14 |
end; |
15 |
||
16 |
signature ATTRIB = |
|
17 |
sig |
|
18 |
include BASIC_ATTRIB |
|
18636 | 19 |
val rule: ('a -> thm -> thm) -> 'a attribute |
20 |
val declaration: (thm -> 'a -> 'a) -> 'a attribute |
|
15703 | 21 |
type src |
18636 | 22 |
val theory: Context.generic attribute -> theory attribute |
23 |
val context: Context.generic attribute -> ProofContext.context attribute |
|
24 |
val generic: theory attribute * ProofContext.context attribute -> Context.generic attribute |
|
25 |
val common: (src -> Context.generic attribute) -> |
|
26 |
(src -> theory attribute) * (src -> ProofContext.context attribute) |
|
5912 | 27 |
exception ATTRIB_FAIL of (string * Position.T) * exn |
16458 | 28 |
val intern: theory -> xstring -> string |
29 |
val intern_src: theory -> src -> src |
|
15703 | 30 |
val global_attribute_i: theory -> src -> theory attribute |
31 |
val global_attribute: theory -> src -> theory attribute |
|
32 |
val local_attribute_i: theory -> src -> ProofContext.context attribute |
|
33 |
val local_attribute: theory -> src -> ProofContext.context attribute |
|
34 |
val context_attribute_i: ProofContext.context -> Args.src -> ProofContext.context attribute |
|
35 |
val context_attribute: ProofContext.context -> Args.src -> ProofContext.context attribute |
|
7673
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
36 |
val undef_global_attribute: theory attribute |
15703 | 37 |
val undef_local_attribute: ProofContext.context attribute |
18636 | 38 |
val generic_attribute_i: theory -> src -> Context.generic attribute |
39 |
val generic_attribute: theory -> src -> Context.generic attribute |
|
17105
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
40 |
val map_specs: ('a -> 'b attribute) -> |
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
41 |
(('c * 'a list) * 'd) list -> (('c * 'b attribute list) * 'd) list |
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
42 |
val map_facts: ('a -> 'b attribute) -> |
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
43 |
(('c * 'a list) * ('d * 'a list) list) list -> |
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
44 |
(('c * 'b attribute list) * ('d * 'b attribute list) list) list |
15703 | 45 |
val crude_closure: ProofContext.context -> src -> src |
46 |
val add_attributes: (bstring * ((src -> theory attribute) * |
|
47 |
(src -> ProofContext.context attribute)) * string) list -> theory -> theory |
|
6091 | 48 |
val global_thm: theory * Args.T list -> thm * (theory * Args.T list) |
49 |
val global_thms: theory * Args.T list -> thm list * (theory * Args.T list) |
|
50 |
val global_thmss: theory * Args.T list -> thm list * (theory * Args.T list) |
|
16458 | 51 |
val local_thm: ProofContext.context * Args.T list -> |
52 |
thm * (ProofContext.context * Args.T list) |
|
53 |
val local_thms: ProofContext.context * Args.T list -> |
|
54 |
thm list * (ProofContext.context * Args.T list) |
|
55 |
val local_thmss: ProofContext.context * Args.T list -> |
|
56 |
thm list * (ProofContext.context * Args.T list) |
|
18636 | 57 |
val thm: Context.generic * Args.T list -> thm * (Context.generic * Args.T list) |
58 |
val thms: Context.generic * Args.T list -> thm list * (Context.generic * Args.T list) |
|
59 |
val thmss: Context.generic * Args.T list -> thm list * (Context.generic * Args.T list) |
|
15703 | 60 |
val syntax: ('a * Args.T list -> 'a attribute * ('a * Args.T list)) -> src -> 'a attribute |
61 |
val no_args: 'a attribute -> src -> 'a attribute |
|
62 |
val add_del_args: 'a attribute -> 'a attribute -> src -> 'a attribute |
|
18636 | 63 |
val attribute: Context.generic attribute -> src |
5823 | 64 |
end; |
65 |
||
66 |
structure Attrib: ATTRIB = |
|
67 |
struct |
|
68 |
||
18636 | 69 |
val rule = Drule.rule_attribute; |
70 |
val declaration = Drule.declaration_attribute; |
|
71 |
||
15703 | 72 |
type src = Args.src; |
73 |
||
5823 | 74 |
|
18636 | 75 |
|
76 |
(** generic attributes **) |
|
77 |
||
78 |
fun generic (global_att, local_att) = |
|
79 |
fn (Context.Theory thy, th) => apfst Context.Theory (global_att (thy, th)) |
|
80 |
| (Context.Proof ctxt, th) => apfst Context.Proof (local_att (ctxt, th)); |
|
81 |
||
82 |
fun theory att (thy, th) = apfst Context.the_theory (att (Context.Theory thy, th)); |
|
83 |
fun context att (ctxt, th) = apfst Context.the_proof (att (Context.Proof ctxt, th)); |
|
84 |
||
85 |
fun common att = (theory o att, context o att); |
|
86 |
||
87 |
||
88 |
||
5823 | 89 |
(** attributes theory data **) |
90 |
||
16458 | 91 |
(* datatype attributes *) |
5823 | 92 |
|
16458 | 93 |
structure AttributesData = TheoryDataFun |
94 |
(struct |
|
5823 | 95 |
val name = "Isar/attributes"; |
96 |
type T = |
|
16344 | 97 |
((((src -> theory attribute) * (src -> ProofContext.context attribute)) |
98 |
* string) * stamp) NameSpace.table; |
|
5823 | 99 |
|
16344 | 100 |
val empty = NameSpace.empty_table; |
6546 | 101 |
val copy = I; |
16458 | 102 |
val extend = I; |
5823 | 103 |
|
17496 | 104 |
fun merge _ tables = NameSpace.merge_tables (eq_snd (op =)) tables handle Symtab.DUPS dups => |
16344 | 105 |
error ("Attempt to merge different versions of attribute(s) " ^ commas_quote dups); |
5823 | 106 |
|
16344 | 107 |
fun print _ attribs = |
5823 | 108 |
let |
109 |
fun prt_attr (name, ((_, comment), _)) = Pretty.block |
|
6846 | 110 |
[Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment]; |
5823 | 111 |
in |
16344 | 112 |
[Pretty.big_list "attributes:" (map prt_attr (NameSpace.extern_table attribs))] |
9216 | 113 |
|> Pretty.chunks |> Pretty.writeln |
5823 | 114 |
end; |
16458 | 115 |
end); |
5823 | 116 |
|
18708 | 117 |
val _ = Context.add_setup AttributesData.init; |
5823 | 118 |
val print_attributes = AttributesData.print; |
7611 | 119 |
|
5823 | 120 |
|
15703 | 121 |
(* interning *) |
122 |
||
16458 | 123 |
val intern = NameSpace.intern o #1 o AttributesData.get; |
15703 | 124 |
val intern_src = Args.map_name o intern; |
125 |
||
126 |
||
5823 | 127 |
(* get global / local attributes *) |
128 |
||
5912 | 129 |
exception ATTRIB_FAIL of (string * Position.T) * exn; |
130 |
||
5823 | 131 |
fun gen_attribute which thy = |
132 |
let |
|
16344 | 133 |
val attrs = #2 (AttributesData.get thy); |
5879 | 134 |
fun attr src = |
16344 | 135 |
let val ((name, _), pos) = Args.dest_src src in |
17412 | 136 |
(case Symtab.lookup attrs name of |
15531 | 137 |
NONE => error ("Unknown attribute: " ^ quote name ^ Position.str_of pos) |
138 |
| SOME ((p, _), _) => transform_failure (curry ATTRIB_FAIL (name, pos)) (which p src)) |
|
5823 | 139 |
end; |
140 |
in attr end; |
|
141 |
||
15703 | 142 |
val global_attribute_i = gen_attribute fst; |
16458 | 143 |
fun global_attribute thy = global_attribute_i thy o intern_src thy; |
15703 | 144 |
|
145 |
val local_attribute_i = gen_attribute snd; |
|
16458 | 146 |
fun local_attribute thy = local_attribute_i thy o intern_src thy; |
15703 | 147 |
|
148 |
val context_attribute_i = local_attribute_i o ProofContext.theory_of; |
|
149 |
val context_attribute = local_attribute o ProofContext.theory_of; |
|
5823 | 150 |
|
7673
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
151 |
val undef_global_attribute: theory attribute = |
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
152 |
fn _ => error "attribute undefined in theory context"; |
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
153 |
|
15703 | 154 |
val undef_local_attribute: ProofContext.context attribute = |
7673
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
155 |
fn _ => error "attribute undefined in proof context"; |
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
156 |
|
18636 | 157 |
fun generic_attribute thy src = generic (global_attribute thy src, local_attribute thy src); |
158 |
fun generic_attribute_i thy src = generic (global_attribute_i thy src, local_attribute_i thy src); |
|
159 |
||
5823 | 160 |
|
17105
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
161 |
(* attributed declarations *) |
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
162 |
|
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
163 |
fun map_specs f = map (apfst (apsnd (map f))); |
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
164 |
fun map_facts f = map (apfst (apsnd (map f)) o apsnd (map (apsnd (map f)))); |
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
165 |
|
1b07a176a880
added map_specs/facts operators (from locale.ML);
wenzelm
parents:
16934
diff
changeset
|
166 |
|
15703 | 167 |
(* crude_closure *) |
168 |
||
169 |
(*Produce closure without knowing facts in advance! The following |
|
170 |
should work reasonably well for attribute parsers that do not peek |
|
171 |
at the thm structure.*) |
|
172 |
||
173 |
fun crude_closure ctxt src = |
|
18678 | 174 |
(try (fn () => context_attribute_i ctxt src (ctxt, Drule.asm_rl)) (); |
15703 | 175 |
Args.closure src); |
176 |
||
177 |
||
5823 | 178 |
(* add_attributes *) |
179 |
||
180 |
fun add_attributes raw_attrs thy = |
|
181 |
let |
|
16141 | 182 |
val new_attrs = raw_attrs |> map (fn (name, (f, g), comment) => |
16344 | 183 |
(name, (((f, g), comment), stamp ()))); |
16458 | 184 |
fun add attrs = NameSpace.extend_table (Sign.naming_of thy) (attrs, new_attrs) |
16344 | 185 |
handle Symtab.DUPS dups => |
186 |
error ("Duplicate declaration of attributes(s) " ^ commas_quote dups); |
|
187 |
in AttributesData.map add thy end; |
|
5823 | 188 |
|
5879 | 189 |
(*implicit version*) |
190 |
fun Attribute name att cmt = Context.>> (add_attributes [(name, att, cmt)]); |
|
5823 | 191 |
|
5879 | 192 |
|
193 |
||
194 |
(** attribute parsers **) |
|
195 |
||
196 |
(* tags *) |
|
5823 | 197 |
|
5879 | 198 |
fun tag x = Scan.lift (Args.name -- Scan.repeat Args.name) x; |
199 |
||
200 |
||
201 |
(* theorems *) |
|
202 |
||
18636 | 203 |
local |
204 |
||
15703 | 205 |
fun gen_thm theory_of attrib get pick = Scan.depend (fn st => |
18037 | 206 |
(Scan.ahead Args.alt_name -- Args.named_fact (get st o Fact) |
207 |
>> (fn (s, fact) => ("", Fact s, fact)) || |
|
208 |
Scan.ahead Args.name -- Args.named_fact (get st o Name) -- Args.thm_sel |
|
209 |
>> (fn ((name, fact), sel) => (name, NameSelection (name, sel), fact)) || |
|
210 |
Scan.ahead Args.name -- Args.named_fact (get st o Name) |
|
211 |
>> (fn (name, fact) => (name, Name name, fact))) -- |
|
212 |
Args.opt_attribs (intern (theory_of st)) |
|
213 |
>> (fn ((name, thmref, fact), srcs) => |
|
15703 | 214 |
let |
16498 | 215 |
val ths = PureThy.select_thm thmref fact; |
15703 | 216 |
val atts = map (attrib (theory_of st)) srcs; |
18418
bf448d999b7e
re-arranged tuples (theory * 'a) to ('a * theory) in Pure
haftmann
parents:
18243
diff
changeset
|
217 |
val (st', ths') = Thm.applys_attributes atts (st, ths); |
15703 | 218 |
in (st', pick name ths') end)); |
15456
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15117
diff
changeset
|
219 |
|
18636 | 220 |
val get_thms = Context.cases PureThy.get_thms ProofContext.get_thms; |
221 |
||
222 |
in |
|
223 |
||
15703 | 224 |
val global_thm = gen_thm I global_attribute_i PureThy.get_thms PureThy.single_thm; |
225 |
val global_thms = gen_thm I global_attribute_i PureThy.get_thms (K I); |
|
15570 | 226 |
val global_thmss = Scan.repeat global_thms >> List.concat; |
5879 | 227 |
|
15703 | 228 |
val local_thm = |
229 |
gen_thm ProofContext.theory_of local_attribute_i ProofContext.get_thms PureThy.single_thm; |
|
230 |
val local_thms = |
|
231 |
gen_thm ProofContext.theory_of local_attribute_i ProofContext.get_thms (K I); |
|
15570 | 232 |
val local_thmss = Scan.repeat local_thms >> List.concat; |
5879 | 233 |
|
18636 | 234 |
val thm = gen_thm Context.theory_of generic_attribute_i get_thms PureThy.single_thm; |
235 |
val thms = gen_thm Context.theory_of generic_attribute_i get_thms (K I); |
|
236 |
val thmss = Scan.repeat thms >> List.concat; |
|
237 |
||
238 |
end; |
|
239 |
||
5823 | 240 |
|
5879 | 241 |
|
242 |
(** attribute syntax **) |
|
5823 | 243 |
|
5879 | 244 |
fun syntax scan src (st, th) = |
8282 | 245 |
let val (st', f) = Args.syntax "attribute" scan src st |
5879 | 246 |
in f (st', th) end; |
247 |
||
248 |
fun no_args x = syntax (Scan.succeed x); |
|
5823 | 249 |
|
10034 | 250 |
fun add_del_args add del x = syntax |
251 |
(Scan.lift (Args.add >> K add || Args.del >> K del || Scan.succeed add)) x; |
|
8633 | 252 |
|
5823 | 253 |
|
254 |
||
18636 | 255 |
(** basic attributes **) |
5823 | 256 |
|
257 |
(* tags *) |
|
258 |
||
18636 | 259 |
fun tagged x = syntax (tag >> Drule.tag) x; |
260 |
fun untagged x = syntax (Scan.lift Args.name >> Drule.untag) x; |
|
6772 | 261 |
|
262 |
||
18636 | 263 |
(* rule composition *) |
5879 | 264 |
|
18636 | 265 |
val COMP_att = |
266 |
syntax (Scan.lift (Scan.optional (Args.bracks Args.nat) 1) -- thm |
|
267 |
>> (fn (i, B) => Drule.rule_attribute (fn _ => fn A => Drule.compose_single (A, i, B)))); |
|
5879 | 268 |
|
18636 | 269 |
val THEN_att = |
270 |
syntax (Scan.lift (Scan.optional (Args.bracks Args.nat) 1) -- thm |
|
271 |
>> (fn (i, B) => Drule.rule_attribute (fn _ => fn A => A RSN (i, B)))); |
|
5879 | 272 |
|
18636 | 273 |
val OF_att = |
274 |
syntax (thmss >> (fn Bs => Drule.rule_attribute (fn _ => fn A => Bs MRS A))); |
|
5879 | 275 |
|
276 |
||
15703 | 277 |
(* read_instantiate: named instantiation of type and term variables *) |
14718 | 278 |
|
15703 | 279 |
local |
5879 | 280 |
|
15703 | 281 |
fun is_tvar (x, _) = (case Symbol.explode x of "'" :: _ => true | _ => false); |
282 |
||
283 |
fun error_var msg xi = error (msg ^ Syntax.string_of_vname xi); |
|
284 |
||
15973 | 285 |
fun the_sort sorts xi = the (sorts xi) |
15703 | 286 |
handle Option.Option => error_var "No such type variable in theorem: " xi; |
10807 | 287 |
|
15973 | 288 |
fun the_type types xi = the (types xi) |
15703 | 289 |
handle Option.Option => error_var "No such variable in theorem: " xi; |
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
290 |
|
16458 | 291 |
fun unify_types thy types ((unifier, maxidx), (xi, u)) = |
15703 | 292 |
let |
293 |
val T = the_type types xi; |
|
294 |
val U = Term.fastype_of u; |
|
295 |
val maxidx' = Int.max (maxidx, Int.max (#2 xi, Term.maxidx_of_term u)); |
|
296 |
in |
|
16934 | 297 |
Sign.typ_unify thy (T, U) (unifier, maxidx') |
15703 | 298 |
handle Type.TUNIFY => error_var "Incompatible type for instantiation of " xi |
299 |
end; |
|
300 |
||
301 |
fun typ_subst env = apsnd (Term.typ_subst_TVars env); |
|
302 |
fun subst env = apsnd (Term.subst_TVars env); |
|
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
303 |
|
16458 | 304 |
fun instantiate thy envT env thm = |
15703 | 305 |
let |
15798
016f3be5a5ec
Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents:
15719
diff
changeset
|
306 |
val (_, sorts) = Drule.types_sorts thm; |
16458 | 307 |
fun prepT (a, T) = (Thm.ctyp_of thy (TVar (a, the_sort sorts a)), Thm.ctyp_of thy T); |
308 |
fun prep (xi, t) = pairself (Thm.cterm_of thy) (Var (xi, Term.fastype_of t), t); |
|
15703 | 309 |
in |
310 |
Drule.instantiate (map prepT (distinct envT), |
|
15798
016f3be5a5ec
Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents:
15719
diff
changeset
|
311 |
map prep (gen_distinct (fn ((xi, t), (yj, u)) => xi = yj andalso t aconv u) env)) thm |
15703 | 312 |
end; |
313 |
||
314 |
in |
|
315 |
||
18636 | 316 |
fun read_instantiate mixed_insts (generic, thm) = |
15703 | 317 |
let |
18636 | 318 |
val thy = Context.theory_of generic; |
319 |
val ctxt = Context.proof_of generic; |
|
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
320 |
|
17756 | 321 |
val (type_insts, term_insts) = List.partition (is_tvar o fst) (map snd mixed_insts); |
15703 | 322 |
val internal_insts = term_insts |> List.mapPartial |
323 |
(fn (xi, Args.Term t) => SOME (xi, t) |
|
324 |
| (_, Args.Name _) => NONE |
|
325 |
| (xi, _) => error_var "Term argument expected for " xi); |
|
326 |
val external_insts = term_insts |> List.mapPartial |
|
327 |
(fn (xi, Args.Name s) => SOME (xi, s) | _ => NONE); |
|
5879 | 328 |
|
15703 | 329 |
|
330 |
(* type instantiations *) |
|
5879 | 331 |
|
15703 | 332 |
val sorts = #2 (Drule.types_sorts thm); |
14718 | 333 |
|
15703 | 334 |
fun readT (xi, arg) = |
335 |
let |
|
336 |
val S = the_sort sorts xi; |
|
337 |
val T = |
|
338 |
(case arg of |
|
339 |
Args.Name s => ProofContext.read_typ ctxt s |
|
340 |
| Args.Typ T => T |
|
341 |
| _ => error_var "Type argument expected for " xi); |
|
10807 | 342 |
in |
16458 | 343 |
if Sign.of_sort thy (T, S) then (xi, T) |
15703 | 344 |
else error_var "Incompatible sort for typ instantiation of " xi |
10807 | 345 |
end; |
5879 | 346 |
|
15703 | 347 |
val type_insts' = map readT type_insts; |
16458 | 348 |
val thm' = instantiate thy type_insts' [] thm; |
15703 | 349 |
|
350 |
||
351 |
(* internal term instantiations *) |
|
352 |
||
353 |
val types' = #1 (Drule.types_sorts thm'); |
|
15798
016f3be5a5ec
Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents:
15719
diff
changeset
|
354 |
val unifier = map (apsnd snd) (Vartab.dest (#1 |
16458 | 355 |
(Library.foldl (unify_types thy types') ((Vartab.empty, 0), internal_insts)))); |
15703 | 356 |
|
357 |
val type_insts'' = map (typ_subst unifier) type_insts'; |
|
358 |
val internal_insts'' = map (subst unifier) internal_insts; |
|
16458 | 359 |
val thm'' = instantiate thy unifier internal_insts'' thm'; |
15703 | 360 |
|
361 |
||
362 |
(* external term instantiations *) |
|
363 |
||
364 |
val types'' = #1 (Drule.types_sorts thm''); |
|
365 |
||
366 |
val (xs, ss) = split_list external_insts; |
|
367 |
val Ts = map (the_type types'') xs; |
|
368 |
val (ts, inferred) = ProofContext.read_termTs ctxt (K false) |
|
369 |
(K NONE) (K NONE) (Drule.add_used thm'' []) (ss ~~ Ts); |
|
370 |
||
371 |
val type_insts''' = map (typ_subst inferred) type_insts''; |
|
372 |
val internal_insts''' = map (subst inferred) internal_insts''; |
|
5879 | 373 |
|
15703 | 374 |
val external_insts''' = xs ~~ ts; |
375 |
val term_insts''' = internal_insts''' @ external_insts'''; |
|
16458 | 376 |
val thm''' = instantiate thy inferred external_insts''' thm''; |
17184 | 377 |
|
15703 | 378 |
|
379 |
(* assign internalized values *) |
|
380 |
||
17184 | 381 |
val _ = |
382 |
mixed_insts |> List.app (fn (arg, (xi, _)) => |
|
383 |
if is_tvar xi then |
|
384 |
Args.assign (SOME (Args.Typ (the (AList.lookup (op =) type_insts''' xi)))) arg |
|
385 |
else |
|
386 |
Args.assign (SOME (Args.Term (the (AList.lookup (op =) term_insts''' xi)))) arg); |
|
15703 | 387 |
|
18636 | 388 |
in (generic, thm''' |> RuleCases.save thm) end; |
15703 | 389 |
|
390 |
end; |
|
391 |
||
392 |
||
393 |
(* where: named instantiation *) |
|
394 |
||
395 |
local |
|
396 |
||
397 |
val value = |
|
398 |
Args.internal_typ >> Args.Typ || |
|
399 |
Args.internal_term >> Args.Term || |
|
400 |
Args.name >> Args.Name; |
|
401 |
||
402 |
val inst = Args.var -- (Args.$$$ "=" |-- Args.ahead -- value) |
|
403 |
>> (fn (xi, (a, v)) => (a, (xi, v))); |
|
404 |
||
405 |
in |
|
5823 | 406 |
|
18636 | 407 |
val where_att = syntax (Args.and_list (Scan.lift inst) >> read_instantiate); |
5879 | 408 |
|
15703 | 409 |
end; |
5879 | 410 |
|
15703 | 411 |
|
412 |
(* of: positional instantiation (term arguments only) *) |
|
413 |
||
414 |
local |
|
5912 | 415 |
|
18636 | 416 |
fun read_instantiate' (args, concl_args) (generic, thm) = |
15703 | 417 |
let |
418 |
fun zip_vars _ [] = [] |
|
419 |
| zip_vars (_ :: xs) ((_, NONE) :: rest) = zip_vars xs rest |
|
420 |
| zip_vars ((x, _) :: xs) ((a, SOME t) :: rest) = (a, (x, t)) :: zip_vars xs rest |
|
421 |
| zip_vars [] _ = error "More instantiations than variables in theorem"; |
|
422 |
val insts = |
|
423 |
zip_vars (Drule.vars_of_terms [Thm.prop_of thm]) args @ |
|
424 |
zip_vars (Drule.vars_of_terms [Thm.concl_of thm]) concl_args; |
|
18636 | 425 |
in read_instantiate insts (generic, thm) end; |
5912 | 426 |
|
15703 | 427 |
val value = |
428 |
Args.internal_term >> Args.Term || |
|
429 |
Args.name >> Args.Name; |
|
430 |
||
431 |
val inst = Args.ahead -- Args.maybe value; |
|
10807 | 432 |
val concl = Args.$$$ "concl" -- Args.colon; |
5912 | 433 |
|
15703 | 434 |
val insts = |
435 |
Scan.repeat (Scan.unless concl inst) -- |
|
436 |
Scan.optional (concl |-- Scan.repeat inst) []; |
|
437 |
||
438 |
in |
|
5912 | 439 |
|
18636 | 440 |
val of_att = syntax (Scan.lift insts >> read_instantiate'); |
5912 | 441 |
|
15703 | 442 |
end; |
443 |
||
5912 | 444 |
|
13782
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
445 |
(* rename_abs *) |
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
446 |
|
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
447 |
fun rename_abs src = syntax |
15703 | 448 |
(Scan.lift (Scan.repeat (Args.maybe Args.name) >> (apsnd o Drule.rename_bvars'))) src; |
13782
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
449 |
|
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
450 |
|
7598 | 451 |
(* unfold / fold definitions *) |
452 |
||
18636 | 453 |
val unfolded = syntax (thmss >> (fn defs => Drule.rule_attribute (K (Tactic.rewrite_rule defs)))); |
454 |
val folded = syntax (thmss >> (fn defs => Drule.rule_attribute (K (Tactic.fold_rule defs)))); |
|
7598 | 455 |
|
456 |
||
8368 | 457 |
(* rule cases *) |
458 |
||
10528 | 459 |
fun consumes x = syntax (Scan.lift (Scan.optional Args.nat 1) >> RuleCases.consumes) x; |
8368 | 460 |
fun case_names x = syntax (Scan.lift (Scan.repeat1 Args.name) >> RuleCases.case_names) x; |
18236 | 461 |
fun case_conclusion x = |
462 |
syntax (Scan.lift (Args.name -- Scan.repeat Args.name) >> RuleCases.case_conclusion) x; |
|
8368 | 463 |
fun params x = syntax (Args.and_list1 (Scan.lift (Scan.repeat Args.name)) >> RuleCases.params) x; |
464 |
||
465 |
||
11770 | 466 |
(* rule_format *) |
467 |
||
15703 | 468 |
fun rule_format_att x = syntax (Args.mode "no_asm" |
469 |
>> (fn true => ObjectLogic.rule_format_no_asm | false => ObjectLogic.rule_format)) x; |
|
11770 | 470 |
|
471 |
||
5879 | 472 |
(* misc rules *) |
473 |
||
6091 | 474 |
fun standard x = no_args (Drule.rule_attribute (K Drule.standard)) x; |
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9902
diff
changeset
|
475 |
fun elim_format x = no_args (Drule.rule_attribute (K Tactic.make_elim)) x; |
9216 | 476 |
fun no_vars x = no_args (Drule.rule_attribute (K (#1 o Drule.freeze_thaw))) x; |
15926 | 477 |
fun eta_long x = no_args (Drule.rule_attribute (K (Drule.fconv_rule Drule.eta_long_conversion))) x; |
5879 | 478 |
|
479 |
||
15703 | 480 |
(* internal attribute *) |
481 |
||
15828 | 482 |
fun attribute att = Args.src (("Pure.attribute", [Args.mk_attribute att]), Position.none); |
15703 | 483 |
|
18636 | 484 |
fun internal_att x = syntax (Scan.lift Args.internal_attribute) x; |
15703 | 485 |
|
486 |
||
18636 | 487 |
(* theory setup *) |
5823 | 488 |
|
18636 | 489 |
val _ = Context.add_setup |
18708 | 490 |
(add_attributes |
18636 | 491 |
[("tagged", common tagged, "tagged theorem"), |
492 |
("untagged", common untagged, "untagged theorem"), |
|
493 |
("COMP", common COMP_att, "direct composition with rules (no lifting)"), |
|
494 |
("THEN", common THEN_att, "resolution with rule"), |
|
495 |
("OF", common OF_att, "rule applied to facts"), |
|
496 |
("where", common where_att, "named instantiation of theorem"), |
|
497 |
("of", common of_att, "rule applied to terms"), |
|
498 |
("rename_abs", common rename_abs, "rename bound variables in abstractions"), |
|
499 |
("unfolded", common unfolded, "unfolded definitions"), |
|
500 |
("folded", common folded, "folded definitions"), |
|
501 |
("standard", common standard, "result put into standard form"), |
|
502 |
("elim_format", common elim_format, "destruct rule turned into elimination rule format"), |
|
503 |
("no_vars", common no_vars, "frozen schematic vars"), |
|
504 |
("eta_long", common eta_long, "put theorem into eta long beta normal form"), |
|
505 |
("consumes", common consumes, "number of consumed facts"), |
|
506 |
("case_names", common case_names, "named rule cases"), |
|
507 |
("case_conclusion", common case_conclusion, "named conclusion of rule cases"), |
|
508 |
("params", common params, "named rule parameters"), |
|
509 |
("atomize", (no_args ObjectLogic.declare_atomize, no_args undef_local_attribute), |
|
510 |
"declaration of atomize rule"), |
|
511 |
("rulify", (no_args ObjectLogic.declare_rulify, no_args undef_local_attribute), |
|
512 |
"declaration of rulify rule"), |
|
513 |
("rule_format", common rule_format_att, "result put into standard rule format"), |
|
18708 | 514 |
("attribute", common internal_att, "internal attribute")]); |
5823 | 515 |
|
516 |
end; |
|
517 |
||
518 |
structure BasicAttrib: BASIC_ATTRIB = Attrib; |
|
519 |
open BasicAttrib; |