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