author | wenzelm |
Tue, 09 Mar 1999 12:07:52 +0100 | |
changeset 6314 | 47c801a77f32 |
parent 6279 | eb4dc43023af |
child 6390 | 5d58c100ca3f |
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 |
6314 | 13 |
val pretty_thm_no_quote: thm -> Pretty.T |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
14 |
val pretty_thm : thm -> Pretty.T |
6087 | 15 |
val pretty_thms : thm list -> Pretty.T |
4950 | 16 |
val string_of_thm : thm -> string |
17 |
val pprint_thm : thm -> pprint_args -> unit |
|
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
18 |
val print_thm : thm -> unit |
6087 | 19 |
val print_thms : thm list -> unit |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
20 |
val prth : thm -> thm |
4270 | 21 |
val prthq : thm Seq.seq -> thm Seq.seq |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
22 |
val prths : thm list -> thm list |
4950 | 23 |
val pretty_ctyp : ctyp -> Pretty.T |
24 |
val pprint_ctyp : ctyp -> pprint_args -> unit |
|
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
25 |
val string_of_ctyp : ctyp -> string |
4950 | 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; |
|
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
38 |
|
4950 | 39 |
structure Display: DISPLAY = |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
40 |
struct |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
41 |
|
6087 | 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; |
|
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
49 |
|
6314 | 50 |
fun pretty_thm_aux quote th = |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
51 |
let |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
52 |
val {sign, hyps, prop, ...} = rep_thm th; |
6087 | 53 |
val xshyps = Thm.extra_shyps th; |
54 |
val (_, tags) = Thm.get_name_tags th; |
|
55 |
||
6314 | 56 |
val prt_term = (if quote then Pretty.quote else I) o Sign.pretty_term sign; |
6279 | 57 |
|
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
58 |
val hlen = length xshyps + length hyps; |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
59 |
val hsymbs = |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
60 |
if hlen = 0 then [] |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
61 |
else if ! show_hyps then |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
62 |
[Pretty.brk 2, Pretty.list "[" "]" |
6279 | 63 |
(map prt_term hyps @ map (Sign.pretty_sort sign) xshyps)] |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
64 |
else |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
65 |
[Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^ "]")]; |
6087 | 66 |
val tsymbs = |
67 |
if null tags orelse not (! show_tags) then [] |
|
68 |
else [Pretty.brk 1, pretty_tags tags]; |
|
6279 | 69 |
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
|
70 |
|
6314 | 71 |
val pretty_thm_no_quote = pretty_thm_aux false; |
72 |
val pretty_thm = pretty_thm_aux true; |
|
73 |
||
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
74 |
val string_of_thm = Pretty.string_of o pretty_thm; |
6279 | 75 |
val pprint_thm = Pretty.pprint o pretty_thm; |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
76 |
|
6087 | 77 |
fun pretty_thms [th] = pretty_thm th |
78 |
| 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
|
79 |
|
6087 | 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; |
|
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
85 |
|
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
86 |
fun prth th = (print_thm th; th); |
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 |
(*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
|
89 |
fun prthq thseq = |
4270 | 90 |
(Seq.print (fn _ => print_thm) 100000 thseq; thseq); |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
91 |
|
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
92 |
(*Print and return a list of theorems, separated by blank lines. *) |
4210 | 93 |
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
|
94 |
|
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 |
(* other printing commands *) |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
97 |
|
4126 | 98 |
fun pretty_ctyp cT = |
99 |
let val {sign, T} = rep_ctyp cT in Sign.pretty_typ sign T end; |
|
100 |
||
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
101 |
fun pprint_ctyp cT = |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
102 |
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
|
103 |
|
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
104 |
fun string_of_ctyp cT = |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
105 |
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
|
106 |
|
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
107 |
val print_ctyp = writeln o string_of_ctyp; |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
108 |
|
3547 | 109 |
fun pretty_cterm ct = |
110 |
let val {sign, t, ...} = rep_cterm ct in Sign.pretty_term sign t end; |
|
111 |
||
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
112 |
fun pprint_cterm ct = |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
113 |
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
|
114 |
|
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
115 |
fun string_of_cterm ct = |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
116 |
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
|
117 |
|
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
118 |
val print_cterm = writeln o string_of_cterm; |
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 |
|
4250 | 121 |
|
122 |
(** print theory **) |
|
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
123 |
|
4950 | 124 |
val pretty_theory = Sign.pretty_sg o sign_of; |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
125 |
val pprint_theory = Sign.pprint_sg o sign_of; |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
126 |
|
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
127 |
val print_syntax = Syntax.print_syntax o syn_of; |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
128 |
|
4250 | 129 |
|
4498 | 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 |
||
4250 | 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 |
val ext_class = Sign.cond_extern sg Sign.classK; |
|
154 |
val ext_tycon = Sign.cond_extern sg Sign.typeK; |
|
155 |
val ext_const = Sign.cond_extern sg Sign.constK; |
|
156 |
||
157 |
||
158 |
fun pretty_classes cs = Pretty.block |
|
159 |
(Pretty.breaks (Pretty.str "classes:" :: map prt_cls cs)); |
|
160 |
||
161 |
fun pretty_classrel (c, cs) = Pretty.block |
|
162 |
(prt_cls c :: Pretty.str " <" :: Pretty.brk 1 :: |
|
163 |
Pretty.commas (map prt_cls cs)); |
|
164 |
||
165 |
fun pretty_default S = Pretty.block |
|
166 |
[Pretty.str "default:", Pretty.brk 1, prt_sort S]; |
|
167 |
||
168 |
fun pretty_ty (t, n) = Pretty.block |
|
5902 | 169 |
[Pretty.str (ext_tycon t), Pretty.spc 1, Pretty.str (string_of_int n)]; |
4250 | 170 |
|
171 |
fun pretty_abbr (t, (vs, rhs)) = Pretty.block |
|
172 |
[prt_typ (Type (t, map (fn v => TVar ((v, 0), [])) vs)), |
|
173 |
Pretty.str " =", Pretty.brk 1, prt_typ rhs]; |
|
174 |
||
175 |
fun pretty_arities (t, ars) = map (prt_arity t) ars; |
|
176 |
||
177 |
fun pretty_const (c, ty) = Pretty.block |
|
178 |
[Pretty.str c, Pretty.str " ::", Pretty.brk 1, prt_typ ty]; |
|
179 |
||
180 |
val {self = _, tsig, const_tab, syn = _, path, spaces, data} = Sign.rep_sg sg; |
|
4440 | 181 |
val spaces' = sort_wrt fst spaces; |
4250 | 182 |
val {classes, classrel, default, tycons, abbrs, arities} = |
183 |
Type.rep_tsig tsig; |
|
184 |
val consts = sort_wrt fst (map (apfst ext_const) (Symtab.dest const_tab)); |
|
185 |
in |
|
186 |
Pretty.writeln (Pretty.strs ("stamps:" :: Sign.stamp_names_of sg)); |
|
4256 | 187 |
Pretty.writeln (Pretty.strs ("data:" :: Sign.data_kinds data)); |
4782 | 188 |
Pretty.writeln (Pretty.strs ["name prefix:", NameSpace.pack path]); |
4498 | 189 |
Pretty.writeln (Pretty.big_list "name spaces:" (map pretty_name_space spaces')); |
4250 | 190 |
Pretty.writeln (pretty_classes classes); |
191 |
Pretty.writeln (Pretty.big_list "class relation:" (map pretty_classrel classrel)); |
|
192 |
Pretty.writeln (pretty_default default); |
|
193 |
Pretty.writeln (Pretty.big_list "type constructors:" (map pretty_ty tycons)); |
|
194 |
Pretty.writeln (Pretty.big_list "type abbreviations:" (map pretty_abbr abbrs)); |
|
195 |
Pretty.writeln (Pretty.big_list "type arities:" (flat (map pretty_arities arities))); |
|
196 |
Pretty.writeln (Pretty.big_list "consts:" (map pretty_const consts)) |
|
197 |
end; |
|
198 |
||
199 |
||
200 |
(* print axioms, oracles, theorems *) |
|
201 |
||
3811 | 202 |
fun print_thy thy = |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
203 |
let |
3990 | 204 |
val {sign, axioms, oracles, ...} = rep_theory thy; |
205 |
val axioms = Symtab.dest axioms; |
|
3811 | 206 |
val oras = map fst (Symtab.dest oracles); |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
207 |
|
3936 | 208 |
fun prt_axm (a, t) = Pretty.block |
3990 | 209 |
[Pretty.str (Sign.cond_extern sign Theory.axiomK a ^ ":"), Pretty.brk 1, |
3936 | 210 |
Pretty.quote (Sign.pretty_term sign t)]; |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
211 |
in |
3990 | 212 |
Pretty.writeln (Pretty.big_list "axioms:" (map prt_axm axioms)); |
4993 | 213 |
Pretty.writeln (Pretty.strs ("oracles:" :: oras)) |
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
214 |
end; |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
215 |
|
4250 | 216 |
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
|
217 |
|
4250 | 218 |
(*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
|
219 |
val show_consts = ref false; |
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset
|
220 |
|
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
221 |
|
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
222 |
end; |
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
223 |
|
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset
|
224 |
open Display; |