src/Pure/attribute.ML
author wenzelm
Wed, 10 Jun 1998 11:58:11 +0200
changeset 5023 c12c438a89db
parent 5005 4486d53a6438
child 5194 650bf0ce0229
permissions -rw-r--r--
moved attributes theory data to Isar/isar_thy.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
4850
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    20
  val none: 'a -> 'a * 'b attribute list
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    21
  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
    22
  val no_attrss: 'a * 'b list -> ('a * ('b * tag list) list) * 'c attribute list
4790
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    23
  val fail: string -> string -> 'a
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    24
  val apply: ('a * tthm) * 'a attribute list -> ('a * tthm)
4850
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    25
  val applys: ('a * tthm list) * 'a attribute list -> ('a * tthm list)
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    26
  val pretty_tthm: tthm -> Pretty.T
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    27
  val tag: tag -> 'a attribute
4790
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    28
  val untag: tag -> 'a attribute
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    29
  val lemma: tag
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    30
  val assumption: tag
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    31
  val tag_lemma: 'a attribute
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    32
  val tag_assumption: 'a attribute
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    33
end;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    34
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    35
structure Attribute: ATTRIBUTE =
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    36
struct
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    37
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    38
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    39
(** tags and attributes **)
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    40
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    41
type tag = string * string list;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    42
type tthm = thm * tag list;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    43
type 'a attribute = 'a * tthm -> 'a * tthm;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    44
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    45
fun thm_of (thm, _) = thm;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    46
fun tthm_of thm = (thm, []);
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    47
4850
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    48
fun none x = (x, []);
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    49
fun no_attrs (x, y) = ((x, (y, [])), []);
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    50
fun no_attrss (x, ys) = ((x, map (rpair []) ys), []);
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    51
4790
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    52
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    53
(* apply attributes *)
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    54
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    55
exception FAIL of string * string;
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    56
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    57
fun fail name msg = raise FAIL (name, msg);
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    58
5023
c12c438a89db moved attributes theory data to Isar/isar_thy.ML;
wenzelm
parents: 5005
diff changeset
    59
(* FIXME error (!!?), push up the warning (??) *)
4790
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    60
fun warn_failed (name, msg) =
4797
d66477d29598 tuned fail;
wenzelm
parents: 4792
diff changeset
    61
  warning ("Failed invocation of " ^ quote name ^ " attribute: " ^ msg);
4790
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    62
4850
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    63
fun apply (x_th, []) = x_th
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    64
  | apply (x_th, f :: fs) = apply (f x_th handle FAIL info => (warn_failed info; x_th), fs);
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    65
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    66
fun applys ((x, []), _) = (x, [])
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    67
  | applys ((x, th :: ths), atts) =
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    68
      let
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    69
        val (x', th') = apply ((x, th), atts);
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    70
        val (x'', ths') = applys ((x', ths), atts);
050481f41e28 added none: 'a -> 'a * 'b attribute list;
wenzelm
parents: 4797
diff changeset
    71
      in (x'', th' :: ths') end;
4780
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    72
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    73
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    74
(* display tagged theorems *)
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    75
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    76
fun pretty_tag (name, []) = Pretty.str name
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    77
  | pretty_tag (name, args) = Pretty.block
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    78
      [Pretty.str name, Pretty.list "(" ")" (map Pretty.str args)];
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    79
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    80
val pretty_tags = Pretty.list "[" "]" o map pretty_tag;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    81
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    82
fun pretty_tthm (thm, []) = Pretty.quote (Display.pretty_thm thm)
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    83
  | pretty_tthm (thm, tags) = Pretty.block
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    84
      [Pretty.quote (Display.pretty_thm thm), Pretty.brk 1, pretty_tags tags];
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    85
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
4790
5adb93457e39 removed simple;
wenzelm
parents: 4780
diff changeset
    89
fun tag tg (x, (thm, tags)) = (x, (thm, tg ins tags));
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", []);
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    94
fun tag_lemma x = tag lemma x;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    95
fun tag_assumption x = tag assumption x;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    96
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    97
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    98
end;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
    99
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
   100
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
   101
structure BasicAttribute: BASIC_ATTRIBUTE = Attribute;
f4ff003bc7ee Theorem tags and attributes.
wenzelm
parents:
diff changeset
   102
open BasicAttribute;