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