23545
|
1 |
(* Title: HOL/ex/reflection_data.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Amine Chaieb, TU Muenchen
|
|
4 |
|
|
5 |
Data for the reification and reflection Methods
|
|
6 |
*)
|
|
7 |
|
|
8 |
signature REIFY_DATA =
|
|
9 |
sig
|
|
10 |
type entry
|
|
11 |
val get: Proof.context -> entry
|
|
12 |
val del: thm list -> attribute
|
|
13 |
val add: thm list -> attribute
|
|
14 |
val setup: theory -> theory
|
|
15 |
end;
|
|
16 |
|
|
17 |
structure Reify_Data : REIFY_DATA =
|
|
18 |
struct
|
|
19 |
|
|
20 |
type entry = thm list;
|
|
21 |
|
|
22 |
structure Data = GenericDataFun
|
|
23 |
( val name = "Reify-Data";
|
|
24 |
type T = thm list
|
|
25 |
val empty = [];
|
|
26 |
val extend = I
|
|
27 |
fun merge _ = Library.merge Thm.eq_thm);
|
|
28 |
|
|
29 |
val get = Data.get o Context.Proof;
|
|
30 |
|
|
31 |
fun add ths = Thm.declaration_attribute (fn th => fn context =>
|
|
32 |
context |> Data.map (fn x => merge Thm.eq_thm (x,ths)))
|
|
33 |
|
|
34 |
fun del ths = Thm.declaration_attribute (fn th => fn context =>
|
|
35 |
context |> Data.map (fn x => subtract Thm.eq_thm x ths))
|
|
36 |
|
|
37 |
(* concrete syntax *)
|
|
38 |
local
|
|
39 |
fun keyword k = Scan.lift (Args.$$$ k -- Args.colon) >> K ();
|
|
40 |
|
|
41 |
val constsN = "consts";
|
|
42 |
val addN = "add";
|
|
43 |
val delN = "del";
|
|
44 |
val any_keyword = keyword constsN || keyword addN || keyword delN;
|
|
45 |
val thms = Scan.repeat (Scan.unless any_keyword Attrib.multi_thm) >> flat;
|
|
46 |
val terms = thms >> map (term_of o Drule.dest_term);
|
|
47 |
|
|
48 |
fun optional scan = Scan.optional scan [];
|
|
49 |
|
|
50 |
in
|
|
51 |
fun att_syntax src = src |> Attrib.syntax
|
|
52 |
((Scan.lift (Args.$$$ "del") |-- thms) >> del ||
|
|
53 |
optional (keyword addN |-- thms) >> add)
|
|
54 |
end;
|
|
55 |
|
|
56 |
|
|
57 |
(* theory setup *)
|
|
58 |
val setup =
|
|
59 |
Attrib.add_attributes [("reify", att_syntax, "Reify data")];
|
|
60 |
end;
|