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