src/HOL/ex/reflection_data.ML
author haftmann
Mon, 21 Jan 2008 08:43:29 +0100
changeset 25929 6bfef23e26be
parent 24045 bead02a55952
child 25979 3297781f8141
permissions -rw-r--r--
avoiding direct references to numeral presentation
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
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
     5
Data for the reification and reflection methods.
23545
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
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    10
  type entry = thm list * thm list
23545
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
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
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
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    20
type entry = thm list * thm list;
23545
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
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    23
(
23647
89286c4e7928 Context data now consist of eqations for reification and equations for correctness theorems for reflection; Added attribute reflection to store correctness theorems to be trued by default
chaieb
parents: 23606
diff changeset
    24
  type T = entry
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    25
  val empty = ([], [])
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    26
  val extend = I
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    27
  fun merge _ = pairself Thm.merge_thms
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    28
);
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    29
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    30
val get = Data.get o Context.Proof;
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    31
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    32
val add = Thm.declaration_attribute (fn th => fn context =>
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    33
  context |> Data.map (apfst (Thm.add_thm th)))
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    34
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    35
val del = Thm.declaration_attribute (fn th => fn context =>
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    36
  context |> Data.map (apfst (Thm.del_thm th)))
23647
89286c4e7928 Context data now consist of eqations for reification and equations for correctness theorems for reflection; Added attribute reflection to store correctness theorems to be trued by default
chaieb
parents: 23606
diff changeset
    37
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    38
val radd = Thm.declaration_attribute (fn th => fn context =>
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    39
  context |> Data.map (apsnd (Thm.add_thm th)))
23647
89286c4e7928 Context data now consist of eqations for reification and equations for correctness theorems for reflection; Added attribute reflection to store correctness theorems to be trued by default
chaieb
parents: 23606
diff changeset
    40
24045
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    41
val rdel = Thm.declaration_attribute (fn th => fn context =>
bead02a55952 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23647
diff changeset
    42
  context |> Data.map (apsnd (Thm.del_thm th)))
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    43
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    44
(* concrete syntax *)
23606
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    45
(*
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    46
local
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    47
fun keyword k = Scan.lift (Args.$$$ k -- Args.colon) >> K ();
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
val constsN = "consts";
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    50
val addN = "add";
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    51
val delN = "del";
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    52
val any_keyword = keyword constsN || keyword addN || keyword delN;
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    53
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
    54
val terms = thms >> map (term_of o Drule.dest_term);
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
fun optional scan = Scan.optional scan [];
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
in
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    59
fun att_syntax src = src |> Attrib.syntax
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    60
 ((Scan.lift (Args.$$$ "del") |-- thms) >> del ||
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    61
  optional (keyword addN |-- thms) >> add)
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    62
end;
23606
60950b22dcbf Cleaned add and del attributes
chaieb
parents: 23545
diff changeset
    63
*)
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    64
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    65
(* theory setup *)
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    66
 val setup =
23647
89286c4e7928 Context data now consist of eqations for reification and equations for correctness theorems for reflection; Added attribute reflection to store correctness theorems to be trued by default
chaieb
parents: 23606
diff changeset
    67
  Attrib.add_attributes [("reify", Attrib.add_del_args add del, "Reify data"),
89286c4e7928 Context data now consist of eqations for reification and equations for correctness theorems for reflection; Added attribute reflection to store correctness theorems to be trued by default
chaieb
parents: 23606
diff changeset
    68
                         ("reflection", Attrib.add_del_args radd rdel, "Reflection data")];
23545
2fddae6056ab Context Data for the reflection and reification methods
chaieb
parents:
diff changeset
    69
end;