src/HOL/ex/reflection_data.ML
author chaieb
Fri, 06 Jul 2007 16:09:26 +0200
changeset 23606 60950b22dcbf
parent 23545 2fddae6056ab
child 23647 89286c4e7928
permissions -rw-r--r--
Cleaned add and del attributes
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
23606
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    12
  val del: attribute
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    13
  val add: attribute 
23545
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
23606
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    31
val add = Thm.declaration_attribute (fn th => fn context => 
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    32
  context |> Data.map (Drule.add_rule th ))
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    33
23606
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    34
val del = Thm.declaration_attribute (fn th => fn context => 
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    35
  context |> Data.map (Drule.del_rule th ))
23545
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 *)
23606
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    38
(*
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    39
local
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    40
fun keyword k = Scan.lift (Args.$$$ k -- Args.colon) >> K ();
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    41
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    42
val constsN = "consts";
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    43
val addN = "add";
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    44
val delN = "del";
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    45
val any_keyword = keyword constsN || keyword addN || keyword delN;
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    46
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
    47
val terms = thms >> map (term_of o Drule.dest_term);
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    48
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    49
fun optional scan = Scan.optional scan [];
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    50
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    51
in
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    52
fun att_syntax src = src |> Attrib.syntax
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    53
 ((Scan.lift (Args.$$$ "del") |-- thms) >> del ||
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    54
  optional (keyword addN |-- thms) >> add)
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    55
end;
23606
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    56
*)
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    57
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    58
(* theory setup *)
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    59
 val setup =
23606
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    60
  Attrib.add_attributes [("reify", Attrib.add_del_args add del, "Reify data")];
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    61
end;