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