src/Pure/display.ML
author wenzelm
Thu Jul 08 18:29:07 1999 +0200 (1999-07-08)
changeset 6926 7ffc131909e5
parent 6894 b92c2f0413b8
child 6976 3895ba31db71
permissions -rw-r--r--
added pretty_thm_no_hyps;
paulson@1591
     1
(*  Title:      Pure/display.ML
paulson@1591
     2
    ID:         $Id$
paulson@1591
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@1591
     4
    Copyright   1993  University of Cambridge
paulson@1591
     5
paulson@1591
     6
Printing of theories, theorems, etc.
paulson@1591
     7
*)
paulson@1591
     8
paulson@1591
     9
signature DISPLAY =
wenzelm@4950
    10
sig
wenzelm@4950
    11
  val show_hyps		: bool ref
wenzelm@6087
    12
  val show_tags		: bool ref
wenzelm@6926
    13
  val pretty_thm	: thm -> Pretty.T
wenzelm@6314
    14
  val pretty_thm_no_quote: thm -> Pretty.T
wenzelm@6926
    15
  val pretty_thm_no_hyps: thm -> Pretty.T
wenzelm@6087
    16
  val pretty_thms	: thm list -> Pretty.T
wenzelm@4950
    17
  val string_of_thm	: thm -> string
wenzelm@4950
    18
  val pprint_thm	: thm -> pprint_args -> unit
paulson@1591
    19
  val print_thm		: thm -> unit
wenzelm@6087
    20
  val print_thms	: thm list -> unit
paulson@1591
    21
  val prth		: thm -> thm
wenzelm@4270
    22
  val prthq		: thm Seq.seq -> thm Seq.seq
paulson@1591
    23
  val prths		: thm list -> thm list
wenzelm@4950
    24
  val pretty_ctyp	: ctyp -> Pretty.T
wenzelm@4950
    25
  val pprint_ctyp	: ctyp -> pprint_args -> unit
paulson@1591
    26
  val string_of_ctyp	: ctyp -> string
wenzelm@4950
    27
  val print_ctyp	: ctyp -> unit
wenzelm@4950
    28
  val pretty_cterm	: cterm -> Pretty.T
wenzelm@4950
    29
  val pprint_cterm	: cterm -> pprint_args -> unit
wenzelm@4950
    30
  val string_of_cterm	: cterm -> string
wenzelm@4950
    31
  val print_cterm	: cterm -> unit
wenzelm@4950
    32
  val pretty_theory	: theory -> Pretty.T
wenzelm@4950
    33
  val pprint_theory	: theory -> pprint_args -> unit
wenzelm@4950
    34
  val print_syntax	: theory -> unit
wenzelm@4950
    35
  val print_theory	: theory -> unit
wenzelm@4950
    36
  val pretty_name_space : string * NameSpace.T -> Pretty.T
wenzelm@4950
    37
  val show_consts	: bool ref
wenzelm@4950
    38
end;
paulson@1591
    39
wenzelm@4950
    40
structure Display: DISPLAY =
paulson@1591
    41
struct
paulson@1591
    42
wenzelm@6087
    43
(** print thm **)
wenzelm@6087
    44
wenzelm@6087
    45
val show_hyps = ref true;	(*false: print meta-hypotheses as dots*)
wenzelm@6087
    46
val show_tags = ref false;	(*false: suppress tags*)
wenzelm@6087
    47
wenzelm@6889
    48
local
wenzelm@6889
    49
wenzelm@6087
    50
fun pretty_tag (name, args) = Pretty.strs (name :: args);
wenzelm@6087
    51
val pretty_tags = Pretty.list "[" "]" o map pretty_tag;
paulson@1591
    52
wenzelm@6889
    53
fun is_oracle (Thm.Oracle _) = true
wenzelm@6889
    54
  | is_oracle _ = false;
wenzelm@6889
    55
wenzelm@6889
    56
fun ex_oracle (Join (der, ders)) = is_oracle der orelse exists ex_oracle ders;
wenzelm@6889
    57
wenzelm@6314
    58
fun pretty_thm_aux quote th =
paulson@1591
    59
  let
wenzelm@6889
    60
    val {sign, hyps, prop, der, ...} = rep_thm th;
wenzelm@6087
    61
    val xshyps = Thm.extra_shyps th;
wenzelm@6087
    62
    val (_, tags) = Thm.get_name_tags th;
wenzelm@6087
    63
wenzelm@6314
    64
    val prt_term = (if quote then Pretty.quote else I) o Sign.pretty_term sign;
wenzelm@6279
    65
paulson@1591
    66
    val hlen = length xshyps + length hyps;
wenzelm@6894
    67
    val ex_ora = ex_oracle der;
paulson@1591
    68
    val hsymbs =
wenzelm@6894
    69
      if hlen = 0 andalso not ex_ora then []
paulson@1591
    70
      else if ! show_hyps then
paulson@1591
    71
        [Pretty.brk 2, Pretty.list "[" "]"
wenzelm@6889
    72
          (map prt_term hyps @ map (Sign.pretty_sort sign) xshyps @
wenzelm@6894
    73
            (if ex_ora then [Pretty.str "!"] else []))]
wenzelm@6889
    74
      else [Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^
wenzelm@6894
    75
        (if ex_ora then "!" else "") ^ "]")];
wenzelm@6087
    76
    val tsymbs =
wenzelm@6087
    77
      if null tags orelse not (! show_tags) then []
wenzelm@6087
    78
      else [Pretty.brk 1, pretty_tags tags];
wenzelm@6279
    79
  in Pretty.block (prt_term prop :: (hsymbs @ tsymbs)) end;
paulson@1591
    80
wenzelm@6889
    81
in
wenzelm@6889
    82
wenzelm@6926
    83
val pretty_thm = pretty_thm_aux true;
wenzelm@6314
    84
val pretty_thm_no_quote = pretty_thm_aux false;
wenzelm@6926
    85
val pretty_thm_no_hyps = setmp show_hyps false pretty_thm;
wenzelm@6314
    86
wenzelm@6889
    87
end;
wenzelm@6889
    88
wenzelm@6889
    89
paulson@1591
    90
val string_of_thm = Pretty.string_of o pretty_thm;
wenzelm@6279
    91
val pprint_thm = Pretty.pprint o pretty_thm;
paulson@1591
    92
wenzelm@6087
    93
fun pretty_thms [th] = pretty_thm th
wenzelm@6087
    94
  | pretty_thms ths = Pretty.block (Pretty.fbreaks (map pretty_thm ths));
paulson@1591
    95
wenzelm@6087
    96
wenzelm@6087
    97
(* top-level commands for printing theorems *)
wenzelm@6087
    98
wenzelm@6087
    99
val print_thm = Pretty.writeln o pretty_thm;
wenzelm@6087
   100
val print_thms = Pretty.writeln o pretty_thms;
paulson@1591
   101
paulson@1591
   102
fun prth th = (print_thm th; th);
paulson@1591
   103
paulson@1591
   104
(*Print and return a sequence of theorems, separated by blank lines. *)
paulson@1591
   105
fun prthq thseq =
wenzelm@4270
   106
  (Seq.print (fn _ => print_thm) 100000 thseq; thseq);
paulson@1591
   107
paulson@1591
   108
(*Print and return a list of theorems, separated by blank lines. *)
wenzelm@4210
   109
fun prths ths = (seq (fn th => (print_thm th; writeln "")) ths; ths);
paulson@1591
   110
paulson@1591
   111
paulson@1591
   112
(* other printing commands *)
paulson@1591
   113
wenzelm@4126
   114
fun pretty_ctyp cT =
wenzelm@4126
   115
  let val {sign, T} = rep_ctyp cT in Sign.pretty_typ sign T end;
wenzelm@4126
   116
paulson@1591
   117
fun pprint_ctyp cT =
paulson@1591
   118
  let val {sign, T} = rep_ctyp cT in Sign.pprint_typ sign T end;
paulson@1591
   119
paulson@1591
   120
fun string_of_ctyp cT =
paulson@1591
   121
  let val {sign, T} = rep_ctyp cT in Sign.string_of_typ sign T end;
paulson@1591
   122
paulson@1591
   123
val print_ctyp = writeln o string_of_ctyp;
paulson@1591
   124
wenzelm@3547
   125
fun pretty_cterm ct =
wenzelm@3547
   126
  let val {sign, t, ...} = rep_cterm ct in Sign.pretty_term sign t end;
wenzelm@3547
   127
paulson@1591
   128
fun pprint_cterm ct =
paulson@1591
   129
  let val {sign, t, ...} = rep_cterm ct in Sign.pprint_term sign t end;
paulson@1591
   130
paulson@1591
   131
fun string_of_cterm ct =
paulson@1591
   132
  let val {sign, t, ...} = rep_cterm ct in Sign.string_of_term sign t end;
paulson@1591
   133
paulson@1591
   134
val print_cterm = writeln o string_of_cterm;
paulson@1591
   135
paulson@1591
   136
wenzelm@4250
   137
wenzelm@4250
   138
(** print theory **)
paulson@1591
   139
wenzelm@6390
   140
val pretty_theory = Sign.pretty_sg o Theory.sign_of;
wenzelm@6390
   141
val pprint_theory = Sign.pprint_sg o Theory.sign_of;
paulson@1591
   142
wenzelm@6390
   143
val print_syntax = Syntax.print_syntax o Theory.syn_of;
paulson@1591
   144
wenzelm@4250
   145
wenzelm@4498
   146
(* pretty_name_space  *)
wenzelm@4498
   147
wenzelm@4498
   148
fun pretty_name_space (kind, space) =
wenzelm@4498
   149
  let
wenzelm@4498
   150
    fun prt_entry (name, accs) = Pretty.block
wenzelm@4498
   151
      (Pretty.str (quote name ^ " =") :: Pretty.brk 1 ::
wenzelm@4498
   152
        Pretty.commas (map (Pretty.str o quote) accs));
wenzelm@4498
   153
  in
wenzelm@4498
   154
    Pretty.fbreaks (Pretty.str (kind ^ ":") :: map prt_entry (NameSpace.dest space))
wenzelm@4498
   155
    |> Pretty.block
wenzelm@4498
   156
  end;
wenzelm@4498
   157
wenzelm@4498
   158
wenzelm@4498
   159
wenzelm@4250
   160
(* print signature *)
wenzelm@4250
   161
wenzelm@4250
   162
fun print_sign sg =
wenzelm@4250
   163
  let
wenzelm@4250
   164
    fun prt_cls c = Sign.pretty_sort sg [c];
wenzelm@4250
   165
    fun prt_sort S = Sign.pretty_sort sg S;
wenzelm@4250
   166
    fun prt_arity t (c, Ss) = Sign.pretty_arity sg (t, Ss, [c]);
wenzelm@4250
   167
    fun prt_typ ty = Pretty.quote (Sign.pretty_typ sg ty);
wenzelm@4250
   168
wenzelm@4250
   169
wenzelm@4250
   170
    fun pretty_classes cs = Pretty.block
wenzelm@4250
   171
      (Pretty.breaks (Pretty.str "classes:" :: map prt_cls cs));
wenzelm@4250
   172
wenzelm@4250
   173
    fun pretty_classrel (c, cs) = Pretty.block
wenzelm@4250
   174
      (prt_cls c :: Pretty.str " <" :: Pretty.brk 1 ::
wenzelm@4250
   175
        Pretty.commas (map prt_cls cs));
wenzelm@4250
   176
wenzelm@4250
   177
    fun pretty_default S = Pretty.block
wenzelm@4250
   178
      [Pretty.str "default:", Pretty.brk 1, prt_sort S];
wenzelm@4250
   179
wenzelm@4250
   180
    fun pretty_ty (t, n) = Pretty.block
wenzelm@6846
   181
      [Pretty.str (Sign.cond_extern sg Sign.typeK t), Pretty.spc 1, Pretty.str (string_of_int n)];
wenzelm@4250
   182
wenzelm@4250
   183
    fun pretty_abbr (t, (vs, rhs)) = Pretty.block
wenzelm@4250
   184
      [prt_typ (Type (t, map (fn v => TVar ((v, 0), [])) vs)),
wenzelm@4250
   185
        Pretty.str " =", Pretty.brk 1, prt_typ rhs];
wenzelm@4250
   186
wenzelm@4250
   187
    fun pretty_arities (t, ars) = map (prt_arity t) ars;
wenzelm@4250
   188
wenzelm@4250
   189
    fun pretty_const (c, ty) = Pretty.block
wenzelm@4250
   190
      [Pretty.str c, Pretty.str " ::", Pretty.brk 1, prt_typ ty];
wenzelm@4250
   191
wenzelm@4250
   192
    val {self = _, tsig, const_tab, syn = _, path, spaces, data} = Sign.rep_sg sg;
wenzelm@6846
   193
    val spaces' = Library.sort_wrt fst spaces;
wenzelm@4250
   194
    val {classes, classrel, default, tycons, abbrs, arities} =
wenzelm@4250
   195
      Type.rep_tsig tsig;
wenzelm@6846
   196
    val consts = Sign.cond_extern_table sg Sign.constK const_tab;
wenzelm@4250
   197
  in
wenzelm@4250
   198
    Pretty.writeln (Pretty.strs ("stamps:" :: Sign.stamp_names_of sg));
wenzelm@4256
   199
    Pretty.writeln (Pretty.strs ("data:" :: Sign.data_kinds data));
wenzelm@4782
   200
    Pretty.writeln (Pretty.strs ["name prefix:", NameSpace.pack path]);
wenzelm@4498
   201
    Pretty.writeln (Pretty.big_list "name spaces:" (map pretty_name_space spaces'));
wenzelm@4250
   202
    Pretty.writeln (pretty_classes classes);
wenzelm@4250
   203
    Pretty.writeln (Pretty.big_list "class relation:" (map pretty_classrel classrel));
wenzelm@4250
   204
    Pretty.writeln (pretty_default default);
wenzelm@4250
   205
    Pretty.writeln (Pretty.big_list "type constructors:" (map pretty_ty tycons));
wenzelm@4250
   206
    Pretty.writeln (Pretty.big_list "type abbreviations:" (map pretty_abbr abbrs));
wenzelm@4250
   207
    Pretty.writeln (Pretty.big_list "type arities:" (flat (map pretty_arities arities)));
wenzelm@4250
   208
    Pretty.writeln (Pretty.big_list "consts:" (map pretty_const consts))
wenzelm@4250
   209
  end;
wenzelm@4250
   210
wenzelm@4250
   211
wenzelm@4250
   212
(* print axioms, oracles, theorems *)
wenzelm@4250
   213
wenzelm@3811
   214
fun print_thy thy =
paulson@1591
   215
  let
wenzelm@6390
   216
    val {sign, axioms, oracles, ...} = Theory.rep_theory thy;
wenzelm@6846
   217
    fun cond_externs kind = Sign.cond_extern_table sign kind;
paulson@1591
   218
wenzelm@3936
   219
    fun prt_axm (a, t) = Pretty.block
wenzelm@6846
   220
      [Pretty.str (a ^ ":"), Pretty.brk 1, Pretty.quote (Sign.pretty_term sign t)];
paulson@1591
   221
  in
wenzelm@6846
   222
    Pretty.writeln (Pretty.big_list "axioms:" (map prt_axm (cond_externs Theory.axiomK axioms)));
wenzelm@6846
   223
    Pretty.writeln (Pretty.strs ("oracles:" :: (map #1 (cond_externs Theory.oracleK oracles))))
paulson@1591
   224
  end;
paulson@1591
   225
wenzelm@6390
   226
fun print_theory thy = (print_sign (Theory.sign_of thy); print_thy thy);
paulson@1591
   227
wenzelm@4250
   228
(*also show consts in case of showing types?*)
wenzelm@3851
   229
val show_consts = ref false;
wenzelm@3851
   230
paulson@1591
   231
paulson@1591
   232
end;
paulson@1591
   233
paulson@1591
   234
open Display;