src/Pure/display.ML
author wenzelm
Tue, 19 May 1998 17:15:30 +0200
changeset 4945 d8c809afafb8
parent 4782 9c0b31da51c6
child 4950 226f2cde9f4d
permissions -rw-r--r--
fixed handle_error: cat_lines;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     1
(*  Title:      Pure/display.ML
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     2
    ID:         $Id$
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     5
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     6
Printing of theories, theorems, etc.
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     7
*)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     8
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     9
signature DISPLAY =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    10
  sig
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    11
  val pprint_cterm	: cterm -> pprint_args -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    12
  val pprint_ctyp	: ctyp -> pprint_args -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    13
  val pprint_theory	: theory -> pprint_args -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    14
  val pprint_thm	: thm -> pprint_args -> unit
4126
c41846a38e20 added pretty_ctyp;
wenzelm
parents: 3990
diff changeset
    15
  val pretty_ctyp	: ctyp -> Pretty.T
3547
977d58464d7f added pretty_cterm;
wenzelm
parents: 3531
diff changeset
    16
  val pretty_cterm	: cterm -> Pretty.T
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    17
  val pretty_thm	: thm -> Pretty.T
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    18
  val print_cterm	: cterm -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    19
  val print_ctyp	: ctyp -> unit
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
    20
  val show_consts	: bool ref
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    21
  val print_goals	: int -> thm -> unit
4498
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
    22
  val pretty_name_space : string * NameSpace.T -> Pretty.T
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    23
  val print_syntax	: theory -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    24
  val print_theory	: theory -> unit
3873
64f496e0885d improved print_data;
wenzelm
parents: 3866
diff changeset
    25
  val print_data	: theory -> string -> unit
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    26
  val print_thm		: thm -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    27
  val prth		: thm -> thm
4270
957c887b89b5 changed Sequence interface (now Seq, in seq.ML);
wenzelm
parents: 4256
diff changeset
    28
  val prthq		: thm Seq.seq -> thm Seq.seq
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    29
  val prths		: thm list -> thm list
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    30
  val show_hyps		: bool ref
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    31
  val string_of_cterm	: cterm -> string
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    32
  val string_of_ctyp	: ctyp -> string
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    33
  val string_of_thm	: thm -> string
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    34
  end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    35
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    36
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    37
structure Display : DISPLAY =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    38
struct
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    39
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    40
(*If false, hypotheses are printed as dots*)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    41
val show_hyps = ref true;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    42
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    43
fun pretty_thm th =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    44
  let
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    45
    val {sign, hyps, prop, ...} = rep_thm th;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    46
    val xshyps = extra_shyps th;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    47
    val hlen = length xshyps + length hyps;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    48
    val hsymbs =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    49
      if hlen = 0 then []
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    50
      else if ! show_hyps then
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    51
        [Pretty.brk 2, Pretty.list "[" "]"
3785
0830d11b8916 now uses new Sign.pretty_sort;
wenzelm
parents: 3669
diff changeset
    52
          (map (Sign.pretty_term sign) hyps @
0830d11b8916 now uses new Sign.pretty_sort;
wenzelm
parents: 3669
diff changeset
    53
           map (Sign.pretty_sort sign) xshyps)]
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    54
      else
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    55
        [Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^ "]")];
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    56
  in
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    57
    Pretty.block (Sign.pretty_term sign prop :: hsymbs)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    58
  end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    59
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    60
val string_of_thm = Pretty.string_of o pretty_thm;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    61
val pprint_thm = Pretty.pprint o Pretty.quote o pretty_thm;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    62
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    63
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    64
(** Top-level commands for printing theorems **)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    65
val print_thm = writeln o string_of_thm;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    66
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    67
fun prth th = (print_thm th; th);
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    68
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    69
(*Print and return a sequence of theorems, separated by blank lines. *)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    70
fun prthq thseq =
4270
957c887b89b5 changed Sequence interface (now Seq, in seq.ML);
wenzelm
parents: 4256
diff changeset
    71
  (Seq.print (fn _ => print_thm) 100000 thseq; thseq);
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    72
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    73
(*Print and return a list of theorems, separated by blank lines. *)
4210
abce78c8a931 tuned prths;
wenzelm
parents: 4126
diff changeset
    74
fun prths ths = (seq (fn th => (print_thm th; writeln "")) ths; ths);
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    75
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    76
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    77
(* other printing commands *)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    78
4126
c41846a38e20 added pretty_ctyp;
wenzelm
parents: 3990
diff changeset
    79
fun pretty_ctyp cT =
c41846a38e20 added pretty_ctyp;
wenzelm
parents: 3990
diff changeset
    80
  let val {sign, T} = rep_ctyp cT in Sign.pretty_typ sign T end;
c41846a38e20 added pretty_ctyp;
wenzelm
parents: 3990
diff changeset
    81
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    82
fun pprint_ctyp cT =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    83
  let val {sign, T} = rep_ctyp cT in Sign.pprint_typ sign T end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    84
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    85
fun string_of_ctyp cT =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    86
  let val {sign, T} = rep_ctyp cT in Sign.string_of_typ sign T end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    87
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    88
val print_ctyp = writeln o string_of_ctyp;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    89
3547
977d58464d7f added pretty_cterm;
wenzelm
parents: 3531
diff changeset
    90
fun pretty_cterm ct =
977d58464d7f added pretty_cterm;
wenzelm
parents: 3531
diff changeset
    91
  let val {sign, t, ...} = rep_cterm ct in Sign.pretty_term sign t end;
977d58464d7f added pretty_cterm;
wenzelm
parents: 3531
diff changeset
    92
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    93
fun pprint_cterm ct =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    94
  let val {sign, t, ...} = rep_cterm ct in Sign.pprint_term sign t end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    95
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    96
fun string_of_cterm ct =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    97
  let val {sign, t, ...} = rep_cterm ct in Sign.string_of_term sign t end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    98
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    99
val print_cterm = writeln o string_of_cterm;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   100
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   101
4250
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   102
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   103
(** print theory **)
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   104
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   105
val pprint_theory = Sign.pprint_sg o sign_of;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   106
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   107
val print_syntax = Syntax.print_syntax o syn_of;
3873
64f496e0885d improved print_data;
wenzelm
parents: 3866
diff changeset
   108
val print_data = Sign.print_data o sign_of;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   109
4250
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   110
4498
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   111
(* pretty_name_space  *)
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   112
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   113
fun pretty_name_space (kind, space) =
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   114
  let
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   115
    fun prt_entry (name, accs) = Pretty.block
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   116
      (Pretty.str (quote name ^ " =") :: Pretty.brk 1 ::
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   117
        Pretty.commas (map (Pretty.str o quote) accs));
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   118
  in
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   119
    Pretty.fbreaks (Pretty.str (kind ^ ":") :: map prt_entry (NameSpace.dest space))
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   120
    |> Pretty.block
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   121
  end;
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   122
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   123
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   124
4250
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   125
(* print signature *)
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   126
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   127
fun print_sign sg =
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   128
  let
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   129
    fun prt_cls c = Sign.pretty_sort sg [c];
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   130
    fun prt_sort S = Sign.pretty_sort sg S;
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   131
    fun prt_arity t (c, Ss) = Sign.pretty_arity sg (t, Ss, [c]);
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   132
    fun prt_typ ty = Pretty.quote (Sign.pretty_typ sg ty);
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   133
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   134
    val ext_class = Sign.cond_extern sg Sign.classK;
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   135
    val ext_tycon = Sign.cond_extern sg Sign.typeK;
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   136
    val ext_const = Sign.cond_extern sg Sign.constK;
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   137
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   138
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   139
    fun pretty_classes cs = Pretty.block
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   140
      (Pretty.breaks (Pretty.str "classes:" :: map prt_cls cs));
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   141
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   142
    fun pretty_classrel (c, cs) = Pretty.block
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   143
      (prt_cls c :: Pretty.str " <" :: Pretty.brk 1 ::
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   144
        Pretty.commas (map prt_cls cs));
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   145
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   146
    fun pretty_default S = Pretty.block
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   147
      [Pretty.str "default:", Pretty.brk 1, prt_sort S];
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   148
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   149
    fun pretty_ty (t, n) = Pretty.block
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   150
      [Pretty.str (ext_tycon t), Pretty.str (" " ^ string_of_int n)];
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   151
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   152
    fun pretty_abbr (t, (vs, rhs)) = Pretty.block
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   153
      [prt_typ (Type (t, map (fn v => TVar ((v, 0), [])) vs)),
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   154
        Pretty.str " =", Pretty.brk 1, prt_typ rhs];
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   155
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   156
    fun pretty_arities (t, ars) = map (prt_arity t) ars;
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   157
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   158
    fun pretty_const (c, ty) = Pretty.block
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   159
      [Pretty.str c, Pretty.str " ::", Pretty.brk 1, prt_typ ty];
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   160
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   161
    val {self = _, tsig, const_tab, syn = _, path, spaces, data} = Sign.rep_sg sg;
4440
9ed4098074bc adapted to new sort function;
wenzelm
parents: 4270
diff changeset
   162
    val spaces' = sort_wrt fst spaces;
4250
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   163
    val {classes, classrel, default, tycons, abbrs, arities} =
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   164
      Type.rep_tsig tsig;
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   165
    val consts = sort_wrt fst (map (apfst ext_const) (Symtab.dest const_tab));
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   166
  in
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   167
    Pretty.writeln (Pretty.strs ("stamps:" :: Sign.stamp_names_of sg));
4256
e768c42069bb removed data.ML (made part of sign.ML);
wenzelm
parents: 4250
diff changeset
   168
    Pretty.writeln (Pretty.strs ("data:" :: Sign.data_kinds data));
4782
9c0b31da51c6 tuned comments;
wenzelm
parents: 4498
diff changeset
   169
    Pretty.writeln (Pretty.strs ["name prefix:", NameSpace.pack path]);
4498
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4440
diff changeset
   170
    Pretty.writeln (Pretty.big_list "name spaces:" (map pretty_name_space spaces'));
4250
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   171
    Pretty.writeln (pretty_classes classes);
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   172
    Pretty.writeln (Pretty.big_list "class relation:" (map pretty_classrel classrel));
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   173
    Pretty.writeln (pretty_default default);
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   174
    Pretty.writeln (Pretty.big_list "type constructors:" (map pretty_ty tycons));
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   175
    Pretty.writeln (Pretty.big_list "type abbreviations:" (map pretty_abbr abbrs));
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   176
    Pretty.writeln (Pretty.big_list "type arities:" (flat (map pretty_arities arities)));
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   177
    Pretty.writeln (Pretty.big_list "consts:" (map pretty_const consts))
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   178
  end;
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   179
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   180
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   181
(* print axioms, oracles, theorems *)
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   182
3811
ec27ddb5104c print_theory: added oracles;
wenzelm
parents: 3785
diff changeset
   183
fun print_thy thy =
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   184
  let
3990
wenzelm
parents: 3936
diff changeset
   185
    val {sign, axioms, oracles, ...} = rep_theory thy;
wenzelm
parents: 3936
diff changeset
   186
    val axioms = Symtab.dest axioms;
3811
ec27ddb5104c print_theory: added oracles;
wenzelm
parents: 3785
diff changeset
   187
    val oras = map fst (Symtab.dest oracles);
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   188
3936
1954255c29ef tuned output;
wenzelm
parents: 3879
diff changeset
   189
    fun prt_axm (a, t) = Pretty.block
3990
wenzelm
parents: 3936
diff changeset
   190
      [Pretty.str (Sign.cond_extern sign Theory.axiomK a ^ ":"), Pretty.brk 1,
3936
1954255c29ef tuned output;
wenzelm
parents: 3879
diff changeset
   191
        Pretty.quote (Sign.pretty_term sign t)];
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   192
  in
3990
wenzelm
parents: 3936
diff changeset
   193
    Pretty.writeln (Pretty.big_list "axioms:" (map prt_axm axioms));
wenzelm
parents: 3936
diff changeset
   194
    Pretty.writeln (Pretty.strs ("oracles:" :: oras));
4782
9c0b31da51c6 tuned comments;
wenzelm
parents: 4498
diff changeset
   195
    print_data thy "Pure/theorems"	(*forward reference!*)
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   196
  end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   197
4250
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   198
fun print_theory thy = (print_sign (sign_of thy); print_thy thy);
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   199
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   200
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   201
4250
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   202
(** print_goals **)
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   203
4250
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   204
(*print thm A1,...,An/B in "goal style" -- premises as numbered subgoals*)
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   205
3806a00677ff moved Sign.print_sg to display.ML;
wenzelm
parents: 4210
diff changeset
   206
(*also show consts in case of showing types?*)
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   207
val show_consts = ref false;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   208
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   209
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   210
local
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   211
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   212
  (* utils *)
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   213
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   214
  fun ins_entry (x, y) [] = [(x, [y])]
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   215
    | ins_entry (x, y) ((pair as (x', ys')) :: pairs) =
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   216
        if x = x' then (x', y ins ys') :: pairs
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   217
        else pair :: ins_entry (x, y) pairs;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   218
3990
wenzelm
parents: 3936
diff changeset
   219
  fun add_consts (Const (c, T), env) = ins_entry (T, (c, T)) env
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   220
    | add_consts (t $ u, env) = add_consts (u, add_consts (t, env))
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   221
    | add_consts (Abs (_, _, t), env) = add_consts (t, env)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   222
    | add_consts (_, env) = env;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   223
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   224
  fun add_vars (Free (x, T), env) = ins_entry (T, (x, ~1)) env
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   225
    | add_vars (Var (xi, T), env) = ins_entry (T, xi) env
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   226
    | add_vars (Abs (_, _, t), env) = add_vars (t, env)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   227
    | add_vars (t $ u, env) = add_vars (u, add_vars (t, env))
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   228
    | add_vars (_, env) = env;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   229
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   230
  fun add_varsT (Type (_, Ts), env) = foldr add_varsT (Ts, env)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   231
    | add_varsT (TFree (x, S), env) = ins_entry (S, (x, ~1)) env
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   232
    | add_varsT (TVar (xi, S), env) = ins_entry (S, xi) env;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   233
4440
9ed4098074bc adapted to new sort function;
wenzelm
parents: 4270
diff changeset
   234
  fun sort_idxs vs = map (apsnd (sort (prod_ord string_ord int_ord))) vs;
9ed4098074bc adapted to new sort function;
wenzelm
parents: 4270
diff changeset
   235
  fun sort_cnsts cs = map (apsnd (sort_wrt fst)) cs;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   236
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   237
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   238
  (* prepare atoms *)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   239
3990
wenzelm
parents: 3936
diff changeset
   240
  fun consts_of t = sort_cnsts (add_consts (t, []));
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   241
  fun vars_of t = sort_idxs (add_vars (t, []));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   242
  fun varsT_of t = rev (sort_idxs (it_term_types add_varsT (t, [])));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   243
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   244
in
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   245
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   246
  fun print_goals maxgoals state =
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   247
    let
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   248
      val {sign, ...} = rep_thm state;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   249
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   250
      val prt_term = Sign.pretty_term sign;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   251
      val prt_typ = Sign.pretty_typ sign;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   252
      val prt_sort = Sign.pretty_sort sign;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   253
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   254
      fun prt_atoms prt prtT (X, xs) = Pretty.block
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   255
        [Pretty.block (Pretty.commas (map prt xs)), Pretty.str " ::",
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   256
          Pretty.brk 1, prtT X];
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   257
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   258
      fun prt_var (x, ~1) = prt_term (Syntax.free x)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   259
        | prt_var xi = prt_term (Syntax.var xi);
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   260
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   261
      fun prt_varT (x, ~1) = prt_typ (TFree (x, []))
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   262
        | prt_varT xi = prt_typ (TVar (xi, []));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   263
3990
wenzelm
parents: 3936
diff changeset
   264
      val prt_consts = prt_atoms (prt_term o Const) prt_typ;
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   265
      val prt_vars = prt_atoms prt_var prt_typ;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   266
      val prt_varsT = prt_atoms prt_varT prt_sort;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   267
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   268
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   269
      fun print_list _ _ [] = ()
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   270
        | print_list name prt lst = (writeln "";
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   271
            Pretty.writeln (Pretty.big_list name (map prt lst)));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   272
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   273
      fun print_subgoals (_, []) = ()
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   274
        | print_subgoals (n, A :: As) = (Pretty.writeln (Pretty.blk (0,
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   275
            [Pretty.str (" " ^ string_of_int n ^ ". "), prt_term A]));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   276
              print_subgoals (n + 1, As));
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   277
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   278
      val print_ffpairs =
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   279
        print_list "Flex-flex pairs:" (prt_term o Logic.mk_flexpair);
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   280
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   281
      val print_consts = print_list "Constants:" prt_consts o consts_of;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   282
      val print_vars = print_list "Variables:" prt_vars o vars_of;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   283
      val print_varsT = print_list "Type variables:" prt_varsT o varsT_of;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   284
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   285
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   286
      val {prop, ...} = rep_thm state;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   287
      val (tpairs, As, B) = Logic.strip_horn prop;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   288
      val ngoals = length As;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   289
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   290
      fun print_gs (types, sorts) =
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   291
       (Pretty.writeln (prt_term B);
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   292
        if ngoals = 0 then writeln "No subgoals!"
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   293
        else if ngoals > maxgoals then
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   294
          (print_subgoals (1, take (maxgoals, As));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   295
            writeln ("A total of " ^ string_of_int ngoals ^ " subgoals..."))
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   296
        else print_subgoals (1, As);
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   297
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   298
        print_ffpairs tpairs;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   299
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   300
        if types andalso ! show_consts then print_consts prop else ();
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   301
        if types then print_vars prop else ();
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   302
        if sorts then print_varsT prop else ());
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   303
    in
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   304
      setmp show_no_free_types true
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   305
        (setmp show_types (! show_types orelse ! show_sorts)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   306
          (setmp show_sorts false print_gs))
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   307
     (! show_types orelse ! show_sorts, ! show_sorts)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   308
  end;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   309
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   310
end;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   311
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   312
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   313
end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   314
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   315
open Display;