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