Coccinelle release 1.0.0-rc15
[bpt/coccinelle.git] / bundles / menhirLib / menhir-20120123 / src / pprint.mli
1 (**************************************************************************)
2 (* *)
3 (* Menhir *)
4 (* *)
5 (* François Pottier, INRIA Rocquencourt *)
6 (* Yann Régis-Gianas, PPS, Université Paris Diderot *)
7 (* *)
8 (* Copyright 2005-2008 Institut National de Recherche en Informatique *)
9 (* et en Automatique. All rights reserved. This file is distributed *)
10 (* under the terms of the Q Public License version 1.0, with the change *)
11 (* described in file LICENSE. *)
12 (* *)
13 (**************************************************************************)
14
15 (* ------------------------------------------------------------------------- *)
16
17 (* Basic combinators for building documents. *)
18
19 type document
20
21 val empty: document
22 val hardline: document
23 val char: char -> document
24 val substring: string -> int -> int -> document
25 val text: string -> document
26 val blank: int -> document
27 val (^^): document -> document -> document
28 val nest: int -> document -> document
29 val column: (int -> document) -> document
30 val nesting: (int -> document) -> document
31 val group: document -> document
32 val ifflat: document -> document -> document
33
34 (* ------------------------------------------------------------------------- *)
35
36 (* Low-level combinators for alignment and indentation. *)
37
38 val align: document -> document
39 val hang: int -> document -> document
40 val indent: int -> document -> document
41
42 (* ------------------------------------------------------------------------- *)
43
44 (* High-level combinators for building documents. *)
45
46 (* [break n] Puts [n] spaces in flat mode and a new line otherwise.
47 Equivalent to: [ifflat (String.make n ' ') hardline] *)
48 val break: int -> document
49
50 (* [break0] equivalent to [break 0] *)
51 val break0: document
52
53 (* [break1] equivalent to [break 1] *)
54 val break1: document
55
56 val string: string -> document
57 val words: string -> document
58
59 val lparen: document
60 val rparen: document
61 val langle: document
62 val rangle: document
63 val lbrace: document
64 val rbrace: document
65 val lbracket: document
66 val rbracket: document
67 val squote: document
68 val dquote: document
69 val bquote: document
70 val semi: document
71 val colon: document
72 val comma: document
73 val space: document
74 val dot: document
75 val sharp: document
76 val backslash: document
77 val equals: document
78 val qmark: document
79 val tilde: document
80 val at: document
81 val percent: document
82 val dollar: document
83 val caret: document
84 val ampersand: document
85 val star: document
86 val plus: document
87 val minus: document
88 val underscore: document
89 val bang: document
90 val bar: document
91
92 val squotes: document -> document
93 val dquotes: document -> document
94 val bquotes: document -> document
95 val braces: document -> document
96 val parens: document -> document
97 val angles: document -> document
98 val brackets: document -> document
99
100 val fold: (document -> document -> document) -> document list -> document
101 val fold1: (document -> document -> document) -> document list -> document
102 val fold1map: (document -> document -> document) -> ('a -> document) -> 'a list -> document
103 val sepmap: document -> ('a -> document) -> 'a list -> document
104
105 val optional: ('a -> document) -> 'a option -> document
106
107 (* [prefix left right]
108 Flat layout: [left] [right]
109 Otherwise: [left]
110 [right]
111 *)
112 val prefix: string -> document -> document
113
114 (* [infix middle left right]
115 Flat layout: [left] [middle] [right]
116 Otherwise: [left] [middle]
117 [right]
118 *)
119 val infix: string -> document -> document -> document
120
121 (* [infix_com middle left right]
122 Flat layout: [left][middle] [right]
123 Otherwise: [left][middle]
124 [right]
125 *)
126 val infix_com: string -> document -> document -> document
127
128 (* [infix_dot middle left right]
129 Flat layout: [left][middle][right]
130 Otherwise: [left][middle]
131 [right]
132 *)
133 val infix_dot: string -> document -> document -> document
134
135 (* [surround nesting break open_doc contents close_doc] *)
136 val surround: int -> document -> document -> document -> document -> document
137
138 (* [surround1 open_txt contents close_txt]
139 Flat: [open_txt][contents][close_txt]
140 Otherwise: [open_txt]
141 [contents]
142 [close_txt]
143 *)
144 val surround1: string -> document -> string -> document
145
146 (* [surround2 open_txt contents close_txt]
147 Flat: [open_txt] [contents] [close_txt]
148 Otherwise: [open_txt]
149 [contents]
150 [close_txt]
151 *)
152 val surround2: string -> document -> string -> document
153
154 (* [soft_surround nesting break open_doc contents close_doc] *)
155 val soft_surround: int -> document -> document -> document -> document -> document
156
157 (* [seq indent break empty_seq open_seq sep_seq close_seq contents] *)
158 val seq: int -> document -> document -> document -> document -> document ->
159 document list -> document
160
161 (* [seq1 open_seq sep_seq close_seq contents]
162 Flat layout: [open_seq][contents][sep_seq]...[sep_seq][contents][close_seq]
163 Otherwise: [open_seq]
164 [contents][sep_seq]...[sep_seq][contents]
165 [close_seq]
166 *)
167 val seq1: string -> string -> string -> document list -> document
168
169 (* [seq2 open_seq sep_seq close_seq contents]
170 Flat layout: [open_seq] [contents][sep_seq]...[sep_seq][contents] [close_seq]
171 Otherwise: [open_seq]
172 [contents][sep_seq]...[sep_seq][contents]
173 [close_seq]
174 *)
175 val seq2: string -> string -> string -> document list -> document
176
177 (* [group1 d] equivalent to [group (nest 1 d)] *)
178 val group1: document -> document
179
180 (* [group2 d] equivalent to [group (nest 2 d)] *)
181 val group2: document -> document
182
183 module Operators : sig
184 val ( ^^ ) : document -> document -> document
185 val ( !^ ) : string -> document
186 val ( ^/^ ) : document -> document -> document
187 val ( ^//^ ) : document -> document -> document
188 val ( ^@^ ) : document -> document -> document
189 val ( ^@@^ ) : document -> document -> document
190 end
191
192 (* ------------------------------------------------------------------------- *)
193
194 (* A signature for document renderers. *)
195
196 module type RENDERER = sig
197
198 (* Output channels. *)
199
200 type channel
201
202 (* [pretty rfrac width channel document] pretty-prints the document
203 [document] to the output channel [channel]. The parameter [width] is the
204 maximum number of characters per line. The parameter [rfrac] is the
205 ribbon width, a fraction relative to [width]. The ribbon width is the
206 maximum number of non-indentation characters per line. *)
207
208 val pretty: float -> int -> channel -> document -> unit
209
210 (* [compact channel document] prints the document [document] to the output
211 channel [channel]. No indentation is used. All newline instructions are
212 respected, that is, no groups are flattened. *)
213
214 val compact: channel -> document -> unit
215
216 end
217
218 (* ------------------------------------------------------------------------- *)
219
220 (* Renderers to output channels and to memory buffers. *)
221
222 module Channel : RENDERER with type channel = out_channel
223
224 module Buffer : RENDERER with type channel = Buffer.t
225
226 (* ------------------------------------------------------------------------- *)
227
228 (* A signature for value representations.
229 This is compatible with the associated Camlp4 generator:
230 SwitchValueRepresentation *)
231
232 module type VALUE_REPRESENTATION = sig
233 (* The type of value representation *)
234 type t
235
236 (* [variant type_name data_constructor_name tag arguments]
237 Given information about the variant and its arguments,
238 this function produces a new value representation. *)
239 val variant : string -> string -> int -> t list -> t
240
241 (* [record type_name fields]
242 Given a type name and a list of record fields, this function
243 produces the value representation of a record. *)
244 val record : string -> (string * t) list -> t
245
246 (* [tuple arguments]
247 Given a list of value representation this function produces
248 a new value representation. *)
249 val tuple : t list -> t
250
251 (* ------------------------------------------------------------------------- *)
252
253 (* Value representation for primitive types. *)
254
255 val string : string -> t
256 val int : int -> t
257 val int32 : int32 -> t
258 val int64 : int64 -> t
259 val nativeint : nativeint -> t
260 val float : float -> t
261 val char : char -> t
262 val bool : bool -> t
263 val option : ('a -> t) -> 'a option -> t
264 val list : ('a -> t) -> 'a list -> t
265 val array : ('a -> t) -> 'a array -> t
266 val ref : ('a -> t) -> 'a ref -> t
267
268 (* Value representation for any other value. *)
269 val unknown : string -> 'a -> t
270 end
271
272 (* A signature for source printers. *)
273
274 module type DOCUMENT_VALUE_REPRESENTATION =
275 VALUE_REPRESENTATION with type t = document
276
277 module ML : DOCUMENT_VALUE_REPRESENTATION
278
279 (* Deprecated *)
280 val line: document
281 val linebreak: document
282 val softline: document
283 val softbreak: document