src/Pure/attribute.ML
author wenzelm
Tue, 24 Nov 1998 11:58:38 +0100
changeset 5948 f389885afb92
parent 5901 a8e1ca1b2ec6
child 6000 aa84c30c1f61
permissions -rw-r--r--
added Isar/isar.ML;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/attribute.ML
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
     4
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
     5
Theorem tags and attributes.
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
     6
*)
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
     7
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
     8
signature BASIC_ATTRIBUTE =
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
     9
sig
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    10
  type tag
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    11
  type tthm
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    12
  type 'a attribute
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    13
end;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    14
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    15
signature ATTRIBUTE =
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    16
sig
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    17
  include BASIC_ATTRIBUTE
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    18
  val thm_of: tthm -> thm
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    19
  val tthm_of: thm -> tthm
5872
df19e1de5c8a removed lift_modifier;
wenzelm
parents: 5835
diff changeset
    20
  val thms_of: tthm list -> thm list
df19e1de5c8a removed lift_modifier;
wenzelm
parents: 5835
diff changeset
    21
  val tthms_of: thm list -> tthm list
df19e1de5c8a removed lift_modifier;
wenzelm
parents: 5835
diff changeset
    22
  val rule: ('a -> thm -> thm) -> 'a attribute
4850
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    23
  val none: 'a -> 'a * 'b attribute list
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    24
  val no_attrs: 'a * 'b -> ('a * ('b * tag list)) * 'c attribute list
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    25
  val no_attrss: 'a * 'b list -> ('a * ('b * tag list) list) * 'c attribute list
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    26
  val apply: ('a * tthm) * 'a attribute list -> ('a * tthm)
4850
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    27
  val applys: ('a * tthm list) * 'a attribute list -> ('a * tthm list)
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    28
  val pretty_tthm: tthm -> Pretty.T
5901
a8e1ca1b2ec6 added pretty_tthms, print_tthms;
wenzelm
parents: 5872
diff changeset
    29
  val pretty_tthms: tthm list -> Pretty.T
5872
df19e1de5c8a removed lift_modifier;
wenzelm
parents: 5835
diff changeset
    30
  val print_tthm: tthm -> unit
5901
a8e1ca1b2ec6 added pretty_tthms, print_tthms;
wenzelm
parents: 5872
diff changeset
    31
  val print_tthms: tthm list -> unit
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    32
  val tag: tag -> 'a attribute
4790
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    33
  val untag: tag -> 'a attribute
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    34
  val lemma: tag
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    35
  val assumption: tag
5194
650bf0ce0229 added internal;
wenzelm
parents: 5023
diff changeset
    36
  val internal: tag
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    37
  val tag_lemma: 'a attribute
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    38
  val tag_assumption: 'a attribute
5194
650bf0ce0229 added internal;
wenzelm
parents: 5023
diff changeset
    39
  val tag_internal: 'a attribute
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    40
end;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    41
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    42
structure Attribute: ATTRIBUTE =
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    43
struct
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    44
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    45
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    46
(** tags and attributes **)
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    47
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    48
type tag = string * string list;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    49
type tthm = thm * tag list;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    50
type 'a attribute = 'a * tthm -> 'a * tthm;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    51
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    52
fun thm_of (thm, _) = thm;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    53
fun tthm_of thm = (thm, []);
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    54
5872
df19e1de5c8a removed lift_modifier;
wenzelm
parents: 5835
diff changeset
    55
fun thms_of ths = map thm_of ths;
df19e1de5c8a removed lift_modifier;
wenzelm
parents: 5835
diff changeset
    56
fun tthms_of ths = map tthm_of ths;
5835
5b79fbf1a65f added lift_modifier, rule;
wenzelm
parents: 5559
diff changeset
    57
5872
df19e1de5c8a removed lift_modifier;
wenzelm
parents: 5835
diff changeset
    58
fun rule f (x, (thm, _)) = (x, (f x thm, []));
5835
5b79fbf1a65f added lift_modifier, rule;
wenzelm
parents: 5559
diff changeset
    59
4850
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    60
fun none x = (x, []);
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    61
fun no_attrs (x, y) = ((x, (y, [])), []);
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    62
fun no_attrss (x, ys) = ((x, map (rpair []) ys), []);
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    63
4790
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    64
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    65
(* apply attributes *)
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    66
5901
a8e1ca1b2ec6 added pretty_tthms, print_tthms;
wenzelm
parents: 5872
diff changeset
    67
fun apply (x_th, atts) = Library.apply atts x_th;
a8e1ca1b2ec6 added pretty_tthms, print_tthms;
wenzelm
parents: 5872
diff changeset
    68
fun applys (x_ths, atts) = foldl_map (Library.apply atts) x_ths;
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    69
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    70
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    71
(* display tagged theorems *)
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    72
5559
95e8692fda23 tuned pretty_tag;
wenzelm
parents: 5194
diff changeset
    73
fun pretty_tag (name, args) = Pretty.strs (name :: args);
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    74
val pretty_tags = Pretty.list "[" "]" o map pretty_tag;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    75
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    76
fun pretty_tthm (thm, []) = Pretty.quote (Display.pretty_thm thm)
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    77
  | pretty_tthm (thm, tags) = Pretty.block
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    78
      [Pretty.quote (Display.pretty_thm thm), Pretty.brk 1, pretty_tags tags];
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    79
5901
a8e1ca1b2ec6 added pretty_tthms, print_tthms;
wenzelm
parents: 5872
diff changeset
    80
fun pretty_tthms [th] = pretty_tthm th
a8e1ca1b2ec6 added pretty_tthms, print_tthms;
wenzelm
parents: 5872
diff changeset
    81
  | pretty_tthms ths = Pretty.block (Pretty.fbreaks (map pretty_tthm ths));
a8e1ca1b2ec6 added pretty_tthms, print_tthms;
wenzelm
parents: 5872
diff changeset
    82
5872
df19e1de5c8a removed lift_modifier;
wenzelm
parents: 5835
diff changeset
    83
val print_tthm = Pretty.writeln o pretty_tthm;
5901
a8e1ca1b2ec6 added pretty_tthms, print_tthms;
wenzelm
parents: 5872
diff changeset
    84
val print_tthms = Pretty.writeln o pretty_tthms;
5872
df19e1de5c8a removed lift_modifier;
wenzelm
parents: 5835
diff changeset
    85
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    86
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    87
(* basic attributes *)
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    88
5559
95e8692fda23 tuned pretty_tag;
wenzelm
parents: 5194
diff changeset
    89
fun tag tg (x, (thm, tags)) = (x, (thm, if tg mem tags then tags else tags @ [tg]));
4790
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    90
fun untag tg (x, (thm, tags)) = (x, (thm, tags \ tg));
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    91
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    92
val lemma = ("lemma", []);
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    93
val assumption = ("assumption", []);
5194
650bf0ce0229 added internal;
wenzelm
parents: 5023
diff changeset
    94
val internal = ("internal", []);
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    95
fun tag_lemma x = tag lemma x;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    96
fun tag_assumption x = tag assumption x;
5194
650bf0ce0229 added internal;
wenzelm
parents: 5023
diff changeset
    97
fun tag_internal x = tag internal x;
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    98
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    99
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
   100
end;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
   101
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
   102
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
   103
structure BasicAttribute: BASIC_ATTRIBUTE = Attribute;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
   104
open BasicAttribute;