src/Pure/display.ML
author wenzelm
Wed Aug 02 19:38:33 2000 +0200 (2000-08-02)
changeset 9500 e21a76142269
parent 8908 25f2bdc02123
child 10010 f6ccb6df9cb9
permissions -rw-r--r--
use oracle flag from derivation;
     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 pretty_full_theory: theory -> Pretty.T list
    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 local
    48 
    49 fun pretty_tag (name, args) = Pretty.strs (name :: map quote args);
    50 val pretty_tags = Pretty.list "[" "]" o map pretty_tag;
    51 
    52 fun pretty_thm_aux quote th =
    53   let
    54     val {sign, hyps, prop, der = (ora, _), ...} = rep_thm th;
    55     val xshyps = Thm.extra_shyps th;
    56     val (_, tags) = Thm.get_name_tags th;
    57 
    58     val prt_term = (if quote then Pretty.quote else I) o Sign.pretty_term sign;
    59 
    60     val hlen = length xshyps + length hyps;
    61     val hsymbs =
    62       if hlen = 0 andalso not ora then []
    63       else if ! show_hyps then
    64         [Pretty.brk 2, Pretty.list "[" "]"
    65           (map prt_term hyps @ map (Sign.pretty_sort sign) xshyps @
    66             (if ora then [Pretty.str "!"] else []))]
    67       else [Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^
    68         (if ora then "!" else "") ^ "]")];
    69     val tsymbs =
    70       if null tags orelse not (! show_tags) then []
    71       else [Pretty.brk 1, pretty_tags tags];
    72   in Pretty.block (prt_term prop :: (hsymbs @ tsymbs)) end;
    73 
    74 in
    75 
    76 val pretty_thm = pretty_thm_aux true;
    77 val pretty_thm_no_quote = pretty_thm_aux false;
    78 
    79 end;
    80 
    81 
    82 val string_of_thm = Pretty.string_of o pretty_thm;
    83 val pprint_thm = Pretty.pprint o pretty_thm;
    84 
    85 fun pretty_thms [th] = pretty_thm th
    86   | pretty_thms ths = Pretty.block (Pretty.fbreaks (map pretty_thm ths));
    87 
    88 
    89 (* top-level commands for printing theorems *)
    90 
    91 val print_thm = Pretty.writeln o pretty_thm;
    92 val print_thms = Pretty.writeln o pretty_thms;
    93 
    94 fun prth th = (print_thm th; th);
    95 
    96 (*Print and return a sequence of theorems, separated by blank lines. *)
    97 fun prthq thseq =
    98   (Seq.print (fn _ => print_thm) 100000 thseq; thseq);
    99 
   100 (*Print and return a list of theorems, separated by blank lines. *)
   101 fun prths ths = (seq (fn th => (print_thm th; writeln "")) ths; ths);
   102 
   103 
   104 (* other printing commands *)
   105 
   106 fun pretty_ctyp cT =
   107   let val {sign, T} = rep_ctyp cT in Sign.pretty_typ sign T end;
   108 
   109 fun pprint_ctyp cT =
   110   let val {sign, T} = rep_ctyp cT in Sign.pprint_typ sign T end;
   111 
   112 fun string_of_ctyp cT =
   113   let val {sign, T} = rep_ctyp cT in Sign.string_of_typ sign T end;
   114 
   115 val print_ctyp = writeln o string_of_ctyp;
   116 
   117 fun pretty_cterm ct =
   118   let val {sign, t, ...} = rep_cterm ct in Sign.pretty_term sign t end;
   119 
   120 fun pprint_cterm ct =
   121   let val {sign, t, ...} = rep_cterm ct in Sign.pprint_term sign t end;
   122 
   123 fun string_of_cterm ct =
   124   let val {sign, t, ...} = rep_cterm ct in Sign.string_of_term sign t end;
   125 
   126 val print_cterm = writeln o string_of_cterm;
   127 
   128 
   129 
   130 (** print theory **)
   131 
   132 val pretty_theory = Sign.pretty_sg o Theory.sign_of;
   133 val pprint_theory = Sign.pprint_sg o Theory.sign_of;
   134 
   135 val print_syntax = Syntax.print_syntax o Theory.syn_of;
   136 
   137 
   138 (* pretty_name_space  *)
   139 
   140 fun pretty_name_space (kind, space) =
   141   let
   142     fun prt_entry (name, accs) = Pretty.block
   143       (Pretty.str (quote name ^ " =") :: Pretty.brk 1 ::
   144         Pretty.commas (map (Pretty.str o quote) accs));
   145   in
   146     Pretty.fbreaks (Pretty.str (kind ^ ":") :: map prt_entry (NameSpace.dest space))
   147     |> Pretty.block
   148   end;
   149 
   150 
   151 
   152 (* print theory *)
   153 
   154 fun pretty_full_theory thy =
   155   let
   156     val sg = Theory.sign_of thy;
   157 
   158     fun prt_cls c = Sign.pretty_sort sg [c];
   159     fun prt_sort S = Sign.pretty_sort sg S;
   160     fun prt_arity t (c, Ss) = Sign.pretty_arity sg (t, Ss, [c]);
   161     fun prt_typ ty = Pretty.quote (Sign.pretty_typ sg ty);
   162     fun prt_term t = Pretty.quote (Sign.pretty_term sg t);
   163 
   164     fun pretty_classes cs = Pretty.block
   165       (Pretty.breaks (Pretty.str "classes:" :: map prt_cls cs));
   166 
   167     fun pretty_classrel (c, cs) = Pretty.block
   168       (prt_cls c :: Pretty.str " <" :: Pretty.brk 1 ::
   169         Pretty.commas (map prt_cls cs));
   170 
   171     fun pretty_default S = Pretty.block
   172       [Pretty.str "default:", Pretty.brk 1, prt_sort S];
   173 
   174     fun pretty_ty (t, n) = Pretty.block
   175       [Pretty.str t, Pretty.brk 1, Pretty.str (string_of_int n)];
   176 
   177     fun pretty_log_types ts = Pretty.block
   178       (Pretty.breaks (Pretty.str "logical types:" :: map Pretty.str ts));
   179 
   180     fun pretty_witness None = Pretty.str "universal non-emptiness witness: --"
   181       | pretty_witness (Some (T, S)) = Pretty.block
   182           [Pretty.str "universal non-emptiness witness:", Pretty.brk 1, prt_typ T,
   183             Pretty.brk 1, prt_sort S];
   184 
   185     fun pretty_abbr (t, (vs, rhs)) = Pretty.block
   186       [prt_typ (Type (t, map (fn v => TVar ((v, 0), [])) vs)),
   187         Pretty.str " =", Pretty.brk 1, prt_typ rhs];
   188 
   189     fun pretty_arities (t, ars) = map (prt_arity t) ars;
   190 
   191     fun pretty_const (c, ty) = Pretty.block
   192       [Pretty.str c, Pretty.str " ::", Pretty.brk 1, prt_typ ty];
   193 
   194     fun prt_axm (a, t) = Pretty.block [Pretty.str (a ^ ":"), Pretty.brk 1, prt_term t];
   195 
   196 
   197     val {self = _, tsig, const_tab, syn = _, path, spaces, data} = Sign.rep_sg sg;
   198     val {axioms, oracles, ...} = Theory.rep_theory thy;
   199     val spaces' = Library.sort_wrt fst spaces;
   200     val {classes, classrel, default, tycons = type_tab, log_types, univ_witness, abbrs, arities} =
   201       Type.rep_tsig tsig;
   202     val tycons = Sign.cond_extern_table sg Sign.typeK type_tab;
   203     val consts = Sign.cond_extern_table sg Sign.constK const_tab;
   204     val axms = Sign.cond_extern_table sg Theory.axiomK axioms;
   205     val oras = Sign.cond_extern_table sg Theory.oracleK oracles;
   206   in
   207     [Pretty.strs ("stamps:" :: Sign.stamp_names_of sg),
   208       Pretty.strs ("data:" :: Sign.data_kinds data),
   209       Pretty.strs ["name prefix:", NameSpace.pack path],
   210       Pretty.big_list "name spaces:" (map pretty_name_space spaces'),
   211       pretty_classes classes,
   212       Pretty.big_list "class relation:" (map pretty_classrel (Symtab.dest classrel)),
   213       pretty_default default,
   214       pretty_log_types log_types,
   215       pretty_witness univ_witness,
   216       Pretty.big_list "type constructors:" (map pretty_ty tycons),
   217       Pretty.big_list "type abbreviations:" (map pretty_abbr (Symtab.dest abbrs)),
   218       Pretty.big_list "type arities:" (flat (map pretty_arities (Symtab.dest arities))),
   219       Pretty.big_list "consts:" (map pretty_const consts),
   220       Pretty.big_list "axioms:" (map prt_axm axms),
   221       Pretty.strs ("oracles:" :: (map #1 oras))]
   222   end;
   223 
   224 
   225 (*show consts with types in proof state output?*)
   226 val show_consts = ref false;
   227 
   228 
   229 end;
   230 
   231 open Display;