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