author | wenzelm |
Sat, 07 Apr 2012 16:41:59 +0200 | |
changeset 47389 | e8552cba702d |
parent 45778 | df6e210fb44c |
child 72004 | 913162a47d9f |
permissions | -rw-r--r-- |
39348 | 1 |
(* ========================================================================= *) |
2 |
(* PRETTY-PRINTING *) |
|
39502 | 3 |
(* Copyright (c) 2008 Joe Hurd, distributed under the BSD License *) |
39348 | 4 |
(* ========================================================================= *) |
5 |
||
6 |
signature Print = |
|
7 |
sig |
|
8 |
||
9 |
(* ------------------------------------------------------------------------- *) |
|
39443
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
10 |
(* Escaping strings. *) |
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
11 |
(* ------------------------------------------------------------------------- *) |
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
12 |
|
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
13 |
val escapeString : {escape : char list} -> string -> string |
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
14 |
|
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
15 |
(* ------------------------------------------------------------------------- *) |
39348 | 16 |
(* A type of pretty-printers. *) |
17 |
(* ------------------------------------------------------------------------- *) |
|
18 |
||
45778 | 19 |
type ppstream |
39348 | 20 |
|
45778 | 21 |
type 'a pp = 'a -> ppstream |
39348 | 22 |
|
23 |
val skip : ppstream |
|
24 |
||
25 |
val sequence : ppstream -> ppstream -> ppstream |
|
26 |
||
27 |
val duplicate : int -> ppstream -> ppstream |
|
28 |
||
29 |
val program : ppstream list -> ppstream |
|
30 |
||
31 |
val stream : ppstream Stream.stream -> ppstream |
|
32 |
||
45778 | 33 |
val ppPpstream : ppstream pp |
34 |
||
35 |
(* ------------------------------------------------------------------------- *) |
|
36 |
(* Pretty-printing blocks. *) |
|
37 |
(* ------------------------------------------------------------------------- *) |
|
38 |
||
39 |
datatype style = Consistent | Inconsistent |
|
39348 | 40 |
|
45778 | 41 |
datatype block = |
42 |
Block of |
|
43 |
{style : style, |
|
44 |
indent : int} |
|
45 |
||
46 |
val styleBlock : block -> style |
|
47 |
||
48 |
val indentBlock : block -> int |
|
49 |
||
50 |
val block : block -> ppstream -> ppstream |
|
51 |
||
52 |
val consistentBlock : int -> ppstream list -> ppstream |
|
53 |
||
54 |
val inconsistentBlock : int -> ppstream list -> ppstream |
|
39348 | 55 |
|
39443
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
56 |
(* ------------------------------------------------------------------------- *) |
45778 | 57 |
(* Words are unbreakable strings annotated with their effective size. *) |
39443
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
58 |
(* ------------------------------------------------------------------------- *) |
39348 | 59 |
|
45778 | 60 |
datatype word = Word of {word : string, size : int} |
61 |
||
62 |
val mkWord : string -> word |
|
63 |
||
64 |
val emptyWord : word |
|
65 |
||
66 |
val charWord : char -> word |
|
67 |
||
68 |
val ppWord : word pp |
|
69 |
||
70 |
val space : ppstream |
|
71 |
||
72 |
val spaces : int -> ppstream |
|
73 |
||
74 |
(* ------------------------------------------------------------------------- *) |
|
75 |
(* Possible line breaks. *) |
|
76 |
(* ------------------------------------------------------------------------- *) |
|
77 |
||
78 |
datatype break = Break of {size : int, extraIndent : int} |
|
79 |
||
80 |
val mkBreak : int -> break |
|
81 |
||
82 |
val ppBreak : break pp |
|
83 |
||
84 |
val break : ppstream |
|
85 |
||
86 |
val breaks : int -> ppstream |
|
87 |
||
88 |
(* ------------------------------------------------------------------------- *) |
|
89 |
(* Forced line breaks. *) |
|
90 |
(* ------------------------------------------------------------------------- *) |
|
91 |
||
92 |
val newline : ppstream |
|
93 |
||
94 |
val newlines : int -> ppstream |
|
39348 | 95 |
|
96 |
(* ------------------------------------------------------------------------- *) |
|
97 |
(* Pretty-printer combinators. *) |
|
98 |
(* ------------------------------------------------------------------------- *) |
|
99 |
||
100 |
val ppMap : ('a -> 'b) -> 'b pp -> 'a pp |
|
101 |
||
102 |
val ppBracket : string -> string -> 'a pp -> 'a pp |
|
103 |
||
104 |
val ppOp : string -> ppstream |
|
105 |
||
106 |
val ppOp2 : string -> 'a pp -> 'b pp -> ('a * 'b) pp |
|
107 |
||
108 |
val ppOp3 : string -> string -> 'a pp -> 'b pp -> 'c pp -> ('a * 'b * 'c) pp |
|
109 |
||
110 |
val ppOpList : string -> 'a pp -> 'a list pp |
|
111 |
||
112 |
val ppOpStream : string -> 'a pp -> 'a Stream.stream pp |
|
113 |
||
114 |
(* ------------------------------------------------------------------------- *) |
|
115 |
(* Pretty-printers for common types. *) |
|
116 |
(* ------------------------------------------------------------------------- *) |
|
117 |
||
118 |
val ppChar : char pp |
|
119 |
||
45778 | 120 |
val ppString : string pp |
121 |
||
39348 | 122 |
val ppEscapeString : {escape : char list} -> string pp |
123 |
||
124 |
val ppUnit : unit pp |
|
125 |
||
126 |
val ppBool : bool pp |
|
127 |
||
128 |
val ppInt : int pp |
|
129 |
||
130 |
val ppPrettyInt : int pp |
|
131 |
||
132 |
val ppReal : real pp |
|
133 |
||
134 |
val ppPercent : real pp |
|
135 |
||
136 |
val ppOrder : order pp |
|
137 |
||
138 |
val ppList : 'a pp -> 'a list pp |
|
139 |
||
140 |
val ppStream : 'a pp -> 'a Stream.stream pp |
|
141 |
||
142 |
val ppOption : 'a pp -> 'a option pp |
|
143 |
||
144 |
val ppPair : 'a pp -> 'b pp -> ('a * 'b) pp |
|
145 |
||
146 |
val ppTriple : 'a pp -> 'b pp -> 'c pp -> ('a * 'b * 'c) pp |
|
147 |
||
42102 | 148 |
val ppException : exn pp |
149 |
||
39348 | 150 |
(* ------------------------------------------------------------------------- *) |
151 |
(* Pretty-printing infix operators. *) |
|
152 |
(* ------------------------------------------------------------------------- *) |
|
153 |
||
39443
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
154 |
type token = string |
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
155 |
|
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
156 |
datatype assoc = |
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
157 |
LeftAssoc |
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
158 |
| NonAssoc |
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
159 |
| RightAssoc |
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
160 |
|
39348 | 161 |
datatype infixes = |
162 |
Infixes of |
|
39443
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
163 |
{token : token, |
39348 | 164 |
precedence : int, |
39443
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
165 |
assoc : assoc} list |
39348 | 166 |
|
167 |
val tokensInfixes : infixes -> StringSet.set |
|
168 |
||
39443
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
169 |
val layerInfixes : infixes -> {tokens : StringSet.set, assoc : assoc} list |
39348 | 170 |
|
171 |
val ppInfixes : |
|
39443
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
172 |
infixes -> |
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
173 |
('a -> (token * 'a * 'a) option) -> ('a * token) pp -> |
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39349
diff
changeset
|
174 |
('a * bool) pp -> ('a * bool) pp |
39348 | 175 |
|
176 |
(* ------------------------------------------------------------------------- *) |
|
45778 | 177 |
(* Pretty-printer rendering. *) |
178 |
(* ------------------------------------------------------------------------- *) |
|
179 |
||
180 |
val render : |
|
181 |
{lineLength : int option} -> ppstream -> |
|
182 |
{indent : int, line : string} Stream.stream |
|
183 |
||
184 |
val toStringWithLineLength : |
|
185 |
{lineLength : int option} -> 'a pp -> 'a -> string |
|
186 |
||
187 |
val toStreamWithLineLength : |
|
188 |
{lineLength : int option} -> 'a pp -> 'a -> string Stream.stream |
|
189 |
||
190 |
val toLine : 'a pp -> 'a -> string |
|
191 |
||
192 |
(* ------------------------------------------------------------------------- *) |
|
193 |
(* Pretty-printer rendering with a global line length. *) |
|
39348 | 194 |
(* ------------------------------------------------------------------------- *) |
195 |
||
196 |
val lineLength : int ref |
|
197 |
||
198 |
val toString : 'a pp -> 'a -> string |
|
199 |
||
200 |
val toStream : 'a pp -> 'a -> string Stream.stream |
|
201 |
||
202 |
val trace : 'a pp -> string -> 'a -> unit |
|
203 |
||
204 |
end |