1 (**************************************************************************)
5 (* François Pottier, INRIA Rocquencourt *)
6 (* Yann Régis-Gianas, PPS, Université Paris Diderot *)
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. *)
13 (**************************************************************************)
15 (* ------------------------------------------------------------------------- *)
17 (* Basic combinators for building documents. *)
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
34 (* ------------------------------------------------------------------------- *)
36 (* Low-level combinators for alignment and indentation. *)
38 val align
: document
-> document
39 val hang
: int -> document
-> document
40 val indent
: int -> document
-> document
42 (* ------------------------------------------------------------------------- *)
44 (* High-level combinators for building documents. *)
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
50 (* [break0] equivalent to [break 0] *)
53 (* [break1] equivalent to [break 1] *)
56 val string: string -> document
57 val words
: string -> document
65 val lbracket
: document
66 val rbracket
: document
76 val backslash
: document
84 val ampersand
: document
88 val underscore
: document
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
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
105 val optional
: ('a
-> document
) -> 'a
option -> document
107 (* [prefix left right]
108 Flat layout: [left] [right]
112 val prefix
: string -> document
-> document
114 (* [infix middle left right]
115 Flat layout: [left] [middle] [right]
116 Otherwise: [left] [middle]
119 val infix
: string -> document
-> document
-> document
121 (* [infix_com middle left right]
122 Flat layout: [left][middle] [right]
123 Otherwise: [left][middle]
126 val infix_com
: string -> document
-> document
-> document
128 (* [infix_dot middle left right]
129 Flat layout: [left][middle][right]
130 Otherwise: [left][middle]
133 val infix_dot
: string -> document
-> document
-> document
135 (* [surround nesting break open_doc contents close_doc] *)
136 val surround
: int -> document
-> document
-> document
-> document
-> document
138 (* [surround1 open_txt contents close_txt]
139 Flat: [open_txt][contents][close_txt]
140 Otherwise: [open_txt]
144 val surround1
: string -> document
-> string -> document
146 (* [surround2 open_txt contents close_txt]
147 Flat: [open_txt] [contents] [close_txt]
148 Otherwise: [open_txt]
152 val surround2
: string -> document
-> string -> document
154 (* [soft_surround nesting break open_doc contents close_doc] *)
155 val soft_surround
: int -> document
-> document
-> document
-> document
-> document
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
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]
167 val seq1
: string -> string -> string -> document list
-> document
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]
175 val seq2
: string -> string -> string -> document list
-> document
177 (* [group1 d] equivalent to [group (nest 1 d)] *)
178 val group1
: document
-> document
180 (* [group2 d] equivalent to [group (nest 2 d)] *)
181 val group2
: document
-> document
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
192 (* ------------------------------------------------------------------------- *)
194 (* A signature for document renderers. *)
196 module type RENDERER
= sig
198 (* Output channels. *)
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. *)
208 val pretty
: float -> int -> channel
-> document
-> unit
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. *)
214 val compact
: channel
-> document
-> unit
218 (* ------------------------------------------------------------------------- *)
220 (* Renderers to output channels and to memory buffers. *)
222 module Channel
: RENDERER
with type channel
= out_channel
224 module Buffer
: RENDERER
with type channel
= Buffer.t
226 (* ------------------------------------------------------------------------- *)
228 (* A signature for value representations.
229 This is compatible with the associated Camlp4 generator:
230 SwitchValueRepresentation *)
232 module type VALUE_REPRESENTATION
= sig
233 (* The type of value representation *)
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
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
247 Given a list of value representation this function produces
248 a new value representation. *)
249 val tuple
: t list
-> t
251 (* ------------------------------------------------------------------------- *)
253 (* Value representation for primitive types. *)
255 val string : string -> t
257 val int32
: int32
-> t
258 val int64
: int64
-> t
259 val nativeint
: nativeint
-> t
260 val float : float -> 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
268 (* Value representation for any other value. *)
269 val unknown
: string -> 'a
-> t
272 (* A signature for source printers. *)
274 module type DOCUMENT_VALUE_REPRESENTATION
=
275 VALUE_REPRESENTATION
with type t
= document
277 module ML
: DOCUMENT_VALUE_REPRESENTATION
281 val linebreak
: document
282 val softline
: document
283 val softbreak
: document