src/Pure/Tools/named_thms.ML
author wenzelm
Sat, 12 Apr 2008 17:00:40 +0200
changeset 26628 63306cb94313
parent 26397 df68e8dfd0e3
child 26724 ff6ff3a9010e
permissions -rw-r--r--
replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24047
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Tools/named_thms.ML
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
     4
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
     5
Named collections of theorems in canonical order.
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
     6
*)
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
     7
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
     8
signature NAMED_THMS =
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
     9
sig
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    10
  val get: Proof.context -> thm list
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    11
  val pretty: Proof.context -> Pretty.T
26363
9d95309f8069 export add/del_thm;
wenzelm
parents: 24867
diff changeset
    12
  val add_thm: thm -> Context.generic -> Context.generic
9d95309f8069 export add/del_thm;
wenzelm
parents: 24867
diff changeset
    13
  val del_thm: thm -> Context.generic -> Context.generic
24047
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    14
  val add: attribute
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    15
  val del: attribute
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    16
  val setup: theory -> theory
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    17
end;
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    18
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    19
functor NamedThmsFun(val name: string val description: string): NAMED_THMS =
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    20
struct
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    21
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    22
structure Data = GenericDataFun
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    23
(
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    24
  type T = thm list;
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    25
  val empty = [];
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    26
  val extend = I;
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    27
  fun merge _ = Thm.merge_thms;
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    28
);
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    29
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    30
val get = Data.get o Context.Proof;
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    31
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    32
fun pretty ctxt =
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    33
  Pretty.big_list (description ^ ":") (map (ProofContext.pretty_thm ctxt) (get ctxt));
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    34
26363
9d95309f8069 export add/del_thm;
wenzelm
parents: 24867
diff changeset
    35
val add_thm = Data.map o Thm.add_thm;
9d95309f8069 export add/del_thm;
wenzelm
parents: 24867
diff changeset
    36
val del_thm = Data.map o Thm.del_thm;
9d95309f8069 export add/del_thm;
wenzelm
parents: 24867
diff changeset
    37
9d95309f8069 export add/del_thm;
wenzelm
parents: 24867
diff changeset
    38
val add = Thm.declaration_attribute add_thm;
9d95309f8069 export add/del_thm;
wenzelm
parents: 24867
diff changeset
    39
val del = Thm.declaration_attribute del_thm;
24047
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    40
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    41
val setup =
26397
df68e8dfd0e3 add dynamic fact binding;
wenzelm
parents: 26363
diff changeset
    42
  Attrib.add_attributes [(name, Attrib.add_del_args add del, "declaration of " ^ description)] #>
df68e8dfd0e3 add dynamic fact binding;
wenzelm
parents: 26363
diff changeset
    43
  PureThy.add_thms_dynamic (name, Data.get);
24047
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    44
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24117
diff changeset
    45
val _ =
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24117
diff changeset
    46
  OuterSyntax.improper_command ("print_" ^ name ^ "_rules") ("print " ^ description)
24117
94210ad252e3 added toplevel print command;
wenzelm
parents: 24047
diff changeset
    47
    OuterKeyword.diag
94210ad252e3 added toplevel print command;
wenzelm
parents: 24047
diff changeset
    48
    (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_context o
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24117
diff changeset
    49
      Toplevel.keep (Pretty.writeln o pretty o Toplevel.context_of)));
24117
94210ad252e3 added toplevel print command;
wenzelm
parents: 24047
diff changeset
    50
24047
47b588ce11ec Named collections of theorems in canonical order.
wenzelm
parents:
diff changeset
    51
end;