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