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