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