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