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