1Stdlib.Format(3)                 OCaml library                Stdlib.Format(3)
2
3
4

NAME

6       Stdlib.Format - no description
7

Module

9       Module   Stdlib.Format
10

Documentation

12       Module Format
13        : (module Stdlib__format)
14
15
16
17
18
19
20
21
22
23   Introduction
24       For a gentle introduction to the basics of pretty-printing using Format
25       , read http://caml.inria.fr/resources/doc/guides/format.en.html.
26
27       You may consider this module as providing an extension  to  the  printf
28       facility   to   provide  automatic  line  splitting.  The  addition  of
29       pretty-printing annotations to your regular printf format strings gives
30       you fancy indentation and line breaks.  Pretty-printing annotations are
31       described below in the documentation of the function Format.fprintf .
32
33       You may also use the explicit pretty-printing box management and print‐
34       ing  functions  provided  by  this module. This style is more basic but
35       more verbose than the concise fprintf format strings.
36
37       For instance, the sequence open_box 0; print_string "x =";  print_space
38       ();
39            print_int  1;  close_box  ();  print_newline  () that prints x = 1
40       within a pretty-printing box,  can  be  abbreviated  as  printf  "@[%s@
41       %i@]@." "x =" 1 , or even shorter printf "@[x =@ %i@]@." 1 .
42
43       Rule of thumb for casual users of this library:
44
45       -use simple pretty-printing boxes (as obtained by open_box 0 );
46
47       -use simple break hints as obtained by print_cut () that outputs a sim‐
48       ple break hint, or by print_space () that outputs a space indicating  a
49       break hint;
50
51       -once  a  pretty-printing  box is open, display its material with basic
52       printing functions (e. g.  print_int and print_string );
53
54       -when the material for a pretty-printing box  has  been  printed,  call
55       close_box () to close the box;
56
57       -at the end of pretty-printing, flush the pretty-printer to display all
58       the remaining material, e.g. evaluate print_newline () .
59
60       The behavior of pretty-printing commands is unspecified if there is  no
61       open pretty-printing box. Each box opened by one of the open_ functions
62       below must be closed using close_box for proper formatting.  Otherwise,
63       some  of the material printed in the boxes may not be output, or may be
64       formatted incorrectly.
65
66       In case of interactive use, each phrase  is  executed  in  the  initial
67       state  of the standard pretty-printer: after each phrase execution, the
68       interactive system closes all open pretty-printing boxes,  flushes  all
69       pending text, and resets the standard pretty-printer.
70
71       Warning:  mixing calls to pretty-printing functions of this module with
72       calls to Stdlib low level output functions is error prone.
73
74       The pretty-printing functions output material that is  delayed  in  the
75       pretty-printer  queue and stacks in order to compute proper line split‐
76       ting. In contrast, basic I/O output functions write directly  in  their
77       output device. As a consequence, the output of a basic I/O function may
78       appear before the output of a pretty-printing function  that  has  been
79       called before. For instance,
80           Stdlib.print_string "<";
81           Format.print_string "PRETTY";
82           Stdlib.print_string ">";
83           Format.print_string "TEXT";
84        leads to output <>PRETTYTEXT .
85
86       type formatter
87
88
89       Abstract  data corresponding to a pretty-printer (also called a format‐
90       ter) and all its machinery. See also Format.formatter .
91
92
93
94
95   Pretty-printing boxes
96       The pretty-printing engine uses the concepts of pretty-printing box and
97       break  hint  to  drive  indentation  and line splitting behavior of the
98       pretty-printer.
99
100       Each different pretty-printing box  kind  introduces  a  specific  line
101       splitting policy:
102
103
104       -within  an  horizontal  box, break hints never split the line (but the
105       line may be split in a box nested deeper),
106
107       -within a vertical box, break hints always split the line,
108
109       -within an horizontal/vertical box, if the box fits on the current line
110       then  break  hints  never  split  the line, otherwise break hint always
111       split the line,
112
113       -within a compacting box, a break hint never splits  the  line,  unless
114       there is no more room on the current line.
115
116       Note  that  line  splitting policy is box specific: the policy of a box
117       does not rule the policy of inner boxes. For instance,  if  a  vertical
118       box is nested in an horizontal box, all break hints within the vertical
119       box will split the line.
120
121       Moreover, opening a box after  the  Format.maxindent  splits  the  line
122       whether or not the box would end up fitting on the line.
123
124       val pp_open_box : formatter -> int -> unit
125
126
127
128
129       val open_box : int -> unit
130
131
132       pp_open_box  ppf d opens a new compacting pretty-printing box with off‐
133       set d in the formatter ppf .
134
135       Within this box, the pretty-printer prints as much as possible material
136       on every line.
137
138       A  break  hint  splits the line if there is no more room on the line to
139       print the remainder of the box.
140
141       Within this box, the pretty-printer emphasizes the box structure: if  a
142       structural  box  does not fit fully on a simple line, a break hint also
143       splits the line if the splitting ``moves to the left''  (i.e.  the  new
144       line gets an indentation smaller than the one of the current line).
145
146       This box is the general purpose pretty-printing box.
147
148       If  the pretty-printer splits the line in the box, offset d is added to
149       the current indentation.
150
151
152
153       val pp_close_box : formatter -> unit -> unit
154
155
156
157
158       val close_box : unit -> unit
159
160       Closes the most recently open pretty-printing box.
161
162
163
164       val pp_open_hbox : formatter -> unit -> unit
165
166
167
168
169       val open_hbox : unit -> unit
170
171
172       pp_open_hbox ppf () opens a new 'horizontal' pretty-printing box.
173
174       This box prints material on a single line.
175
176       Break hints in a horizontal box never split the line.  (Line  splitting
177       may still occur inside boxes nested deeper).
178
179
180
181       val pp_open_vbox : formatter -> int -> unit
182
183
184
185
186       val open_vbox : int -> unit
187
188
189       pp_open_vbox ppf d opens a new 'vertical' pretty-printing box with off‐
190       set d .
191
192       This box prints material on as many lines as break hints in the box.
193
194       Every break hint in a vertical box splits the line.
195
196       If the pretty-printer splits the line in the box, d  is  added  to  the
197       current indentation.
198
199
200
201       val pp_open_hvbox : formatter -> int -> unit
202
203
204
205
206       val open_hvbox : int -> unit
207
208
209       pp_open_hvbox  ppf  d opens a new 'horizontal/vertical' pretty-printing
210       box with offset d .
211
212       This box behaves as an horizontal box if it fits on a single line, oth‐
213       erwise it behaves as a vertical box.
214
215       If  the  pretty-printer  splits  the line in the box, d is added to the
216       current indentation.
217
218
219
220       val pp_open_hovbox : formatter -> int -> unit
221
222
223
224
225       val open_hovbox : int -> unit
226
227
228       pp_open_hovbox ppf d opens a new 'horizontal-or-vertical' pretty-print‐
229       ing box with offset d .
230
231       This box prints material as much as possible on every line.
232
233       A  break  hint  splits the line if there is no more room on the line to
234       print the remainder of the box.
235
236       If the pretty-printer splits the line in the box, d  is  added  to  the
237       current indentation.
238
239
240
241
242   Formatting functions
243       val pp_print_string : formatter -> string -> unit
244
245
246
247
248       val print_string : string -> unit
249
250
251       pp_print_string ppf s prints s in the current pretty-printing box.
252
253
254
255       val pp_print_as : formatter -> int -> string -> unit
256
257
258
259
260       val print_as : int -> string -> unit
261
262
263       pp_print_as ppf len s prints s in the current pretty-printing box.  The
264       pretty-printer formats s as if it were of length len .
265
266
267
268       val pp_print_int : formatter -> int -> unit
269
270
271
272
273       val print_int : int -> unit
274
275       Print an integer in the current pretty-printing box.
276
277
278
279       val pp_print_float : formatter -> float -> unit
280
281
282
283
284       val print_float : float -> unit
285
286       Print a floating point number in the current pretty-printing box.
287
288
289
290       val pp_print_char : formatter -> char -> unit
291
292
293
294
295       val print_char : char -> unit
296
297       Print a character in the current pretty-printing box.
298
299
300
301       val pp_print_bool : formatter -> bool -> unit
302
303
304
305
306       val print_bool : bool -> unit
307
308       Print a boolean in the current pretty-printing box.
309
310
311
312
313   Break hints
314       A 'break hint' tells the pretty-printer to output some space  or  split
315       the line whichever way is more appropriate to the current pretty-print‐
316       ing box splitting rules.
317
318       Break hints are used to separate printing items and  are  mandatory  to
319       let the pretty-printer correctly split lines and indent items.
320
321       Simple break hints are:
322
323       -the 'space': output a space or split the line if appropriate,
324
325       -the 'cut': split the line if appropriate.
326
327       Note:  the  notions  of  space  and line splitting are abstract for the
328       pretty-printing engine, since those notions can be completely redefined
329       by  the  programmer.   However,  in the pretty-printer default setting,
330       ``output a space'' simply means printing a space character (ASCII  code
331       32)  and  ``split  the line'' means printing a newline character (ASCII
332       code 10).
333
334       val pp_print_space : formatter -> unit -> unit
335
336
337
338
339       val print_space : unit -> unit
340
341
342       pp_print_space ppf () emits a 'space' break  hint:  the  pretty-printer
343       may split the line at this point, otherwise it prints one space.
344
345
346       pp_print_space ppf () is equivalent to pp_print_break ppf 1 0 .
347
348
349
350       val pp_print_cut : formatter -> unit -> unit
351
352
353
354
355       val print_cut : unit -> unit
356
357
358       pp_print_cut  ppf  ()  emits a 'cut' break hint: the pretty-printer may
359       split the line at this point, otherwise it prints nothing.
360
361
362       pp_print_cut ppf () is equivalent to pp_print_break ppf 0 0 .
363
364
365
366       val pp_print_break : formatter -> int -> int -> unit
367
368
369
370
371       val print_break : int -> int -> unit
372
373
374       pp_print_break ppf nspaces  offset  emits  a  'full'  break  hint:  the
375       pretty-printer  may  split  the line at this point, otherwise it prints
376       nspaces spaces.
377
378       If the pretty-printer splits the line, offset is added to  the  current
379       indentation.
380
381
382
383       val  pp_print_custom_break : formatter -> fits:string * int * string ->
384       breaks:string * int * string -> unit
385
386
387       pp_print_custom_break ppf ~fits:(s1, n, s2) ~breaks:(s3, m, s4) emits a
388       custom break hint: the pretty-printer may split the line at this point.
389
390       If  it  does not split the line, then the s1 is emitted, then n spaces,
391       then s2 .
392
393       If it splits the line, then it emits the  s3  string,  then  an  indent
394       (according  to  the box rules), then an offset of m spaces, then the s4
395       string.
396
397       While n and m are handled by formatter_out_functions.out_indent  ,  the
398       strings  will  be  handled by formatter_out_functions.out_string . This
399       allows for a custom formatter that handles indentation distinctly,  for
400       example, outputs <br/> tags or &nbsp; entities.
401
402       The  custom  break  is  useful  if  you  want  to  change which visible
403       (non-whitespace) characters are printed in case of break or  no  break.
404       For example, when printing a list
405       [a; b; c]
406       trailing semicolon when it is printed vertically:
407
408
409       [
410         a;
411         b;
412         c;
413       ]
414
415
416       You can do this as follows:
417       printf "@[<v 0>[@;<0 2>@[<v 0>a;@,b;@,c@]%t]@]@\n"
418         (pp_print_custom_break ~fits:("", 0, "") ~breaks:(";", 0, ""))
419
420
421
422       Since 4.08.0
423
424
425
426       val pp_force_newline : formatter -> unit -> unit
427
428
429
430
431       val force_newline : unit -> unit
432
433       Force a new line in the current pretty-printing box.
434
435       The pretty-printer must split the line at this point,
436
437       Not  the normal way of pretty-printing, since imperative line splitting
438       may interfere with current line  counters  and  box  size  calculation.
439       Using break hints within an enclosing vertical box is a better alterna‐
440       tive.
441
442
443
444       val pp_print_if_newline : formatter -> unit -> unit
445
446
447
448
449       val print_if_newline : unit -> unit
450
451       Execute the next formatting command if the preceding line has just been
452       split. Otherwise, ignore the next formatting command.
453
454
455
456
457   Pretty-printing termination
458       val pp_print_flush : formatter -> unit -> unit
459
460
461
462
463       val print_flush : unit -> unit
464
465       End of pretty-printing: resets the pretty-printer to initial state.
466
467       All open pretty-printing boxes are closed, all pending text is printed.
468       In addition, the pretty-printer low level output device is  flushed  to
469       ensure that all pending text is really displayed.
470
471       Note:  never  use print_flush in the normal course of a pretty-printing
472       routine, since the pretty-printer uses a complex buffering machinery to
473       properly  indent  the output; manually flushing those buffers at random
474       would conflict with the pretty-printer strategy and result to poor ren‐
475       dering.
476
477       Only consider using print_flush when displaying all pending material is
478       mandatory (for instance in case of interactive use when  you  want  the
479       user  to  read  some  text) and when resetting the pretty-printer state
480       will not disturb further pretty-printing.
481
482       Warning: If the output device of the pretty-printer is an output  chan‐
483       nel,  repeated  calls  to  print_flush means repeated calls to flush to
484       flush the out channel;  these  explicit  flush  calls  could  foil  the
485       buffering  strategy  of  output  channels and could dramatically impact
486       efficiency.
487
488
489
490       val pp_print_newline : formatter -> unit -> unit
491
492
493
494
495       val print_newline : unit -> unit
496
497       End of pretty-printing: resets the pretty-printer to initial state.
498
499       All open pretty-printing boxes are closed, all pending text is printed.
500
501       Equivalent to Format.print_flush followed by a new  line.   See  corre‐
502       sponding words of caution for Format.print_flush .
503
504       Note:  this  is  not the normal way to output a new line; the preferred
505       method is using break hints within a vertical pretty-printing box.
506
507
508
509
510   Margin
511       val pp_set_margin : formatter -> int -> unit
512
513
514
515
516       val set_margin : int -> unit
517
518
519       pp_set_margin ppf d sets the right margin to  d  (in  characters):  the
520       pretty-printer splits lines that overflow the right margin according to
521       the break hints given.  Setting the margin to d means that the  format‐
522       ting  engine aims at printing at most d-1 characters per line.  Nothing
523       happens if d is smaller than 2.  If d is too large, the right margin is
524       set  to  the  maximum admissible value (which is greater than 10 ^ 9 ).
525       If d is less than the current maximum indentation  limit,  the  maximum
526       indentation limit is decreased while trying to preserve a minimal ratio
527       max_indent/margin>=50% and if possible the current difference margin  -
528       max_indent .
529
530       See also Format.pp_set_geometry .
531
532
533
534       val pp_get_margin : formatter -> unit -> int
535
536
537
538
539       val get_margin : unit -> int
540
541       Returns the position of the right margin.
542
543
544
545
546   Maximum indentation limit
547       val pp_set_max_indent : formatter -> int -> unit
548
549
550
551
552       val set_max_indent : int -> unit
553
554
555       pp_set_max_indent  ppf d sets the maximum indentation limit of lines to
556       d (in characters): once this  limit  is  reached,  new  pretty-printing
557       boxes  are rejected to the left, unless the enclosing box fully fits on
558       the current line.  As an illustration,
559       set_margin 10; set_max_indent 5; printf "@[123456@[7@]89A@]@."
560       yields
561           123456
562           789A
563
564       because the nested box "@[7@]" is opened after the maximum  indentation
565       limit  (  7>5  )  and  its parent box does not fit on the current line.
566       Either decreasing the length of the parent box to  make  it  fit  on  a
567       line:
568       printf "@[123456@[7@]89@]@."
569       or  opening  an  intermediary  box before the maximum indentation limit
570       which fits on the current line
571       printf "@[123@[456@[7@]89@]A@]@."
572       avoids the rejection to the left of the inner boxes and  print  respec‐
573       tively  "123456789"  and  "123456789A" .  Note also that vertical boxes
574       never fit on a line whereas horizontal boxes always fully  fit  on  the
575       current  line.  Opening a box may split a line whereas the contents may
576       have fit.  If this behavior is problematic, it can be curtailed by set‐
577       ting  the  maximum  indentation limit to margin - 1 . Note that setting
578       the maximum indentation limit to margin is invalid.
579
580       Nothing happens if d is smaller than 2.
581
582       If d is too large, the limit is set to  the  maximum  admissible  value
583       (which is greater than 10 ^ 9 ).
584
585       If  d  is  greater or equal than the current margin, it is ignored, and
586       the current maximum indentation limit is kept.
587
588       See also Format.pp_set_geometry .
589
590
591
592       val pp_get_max_indent : formatter -> unit -> int
593
594
595
596
597       val get_max_indent : unit -> int
598
599       Return the maximum indentation limit (in characters).
600
601
602
603
604   Geometry
605       Geometric functions can be used to manipulate simultaneously  the  cou‐
606       pled variables, margin and maxixum indentation limit.
607
608       type geometry = {
609        max_indent : int ;
610        margin : int ;
611        }
612
613
614
615
616
617       val check_geometry : geometry -> bool
618
619       Check if the formatter geometry is valid: 1 < max_indent < margin
620
621
622
623
624       val pp_set_geometry : formatter -> max_indent:int -> margin:int -> unit
625
626
627
628
629       val set_geometry : max_indent:int -> margin:int -> unit
630
631
632
633
634       val pp_safe_set_geometry : formatter -> max_indent:int -> margin:int ->
635       unit
636
637
638
639
640       val safe_set_geometry : max_indent:int -> margin:int -> unit
641
642
643       pp_set_geometry ppf ~max_indent ~margin sets both the margin and  maxi‐
644       mum indentation limit for ppf .
645
646       When  1 < max_indent < margin , pp_set_geometry ppf ~max_indent ~margin
647       is  equivalent  to  pp_set_margin  ppf  margin;  pp_set_max_indent  ppf
648       max_indent  ;  and  avoids  the  subtly incorrect pp_set_max_indent ppf
649       max_indent; pp_set_margin ppf margin ;
650
651       Outside of this domain,  pp_set_geometry  raises  an  invalid  argument
652       exception whereas pp_safe_set_geometry does nothing.
653
654
655       Since 4.08.0
656
657
658
659       val pp_update_geometry : formatter -> (geometry -> geometry) -> unit
660
661
662       pp_update_geometry  ppf (fun geo -> { geo with ... }) lets you update a
663       formatter's geometry in a way that is robust to extension of the geome‐
664       try record with new fields.
665
666       Raises  an invalid argument exception if the returned geometry does not
667       satisfy Format.check_geometry .
668
669
670       Since 4.11.0
671
672
673
674       val update_geometry : (geometry -> geometry) -> unit
675
676
677
678
679       val pp_get_geometry : formatter -> unit -> geometry
680
681
682
683
684       val get_geometry : unit -> geometry
685
686       Return the current geometry of the formatter
687
688
689       Since 4.08.0
690
691
692
693
694   Maximum formatting depth
695       The maximum formatting depth is the maximum number  of  pretty-printing
696       boxes simultaneously open.
697
698       Material  inside  boxes  nested  deeper is printed as an ellipsis (more
699       precisely as the text returned by Format.get_ellipsis_text () ).
700
701       val pp_set_max_boxes : formatter -> int -> unit
702
703
704
705
706       val set_max_boxes : int -> unit
707
708
709       pp_set_max_boxes ppf max sets the  maximum  number  of  pretty-printing
710       boxes simultaneously open.
711
712       Material  inside  boxes  nested  deeper is printed as an ellipsis (more
713       precisely as the text returned by Format.get_ellipsis_text () ).
714
715       Nothing happens if max is smaller than 2.
716
717
718
719       val pp_get_max_boxes : formatter -> unit -> int
720
721
722
723
724       val get_max_boxes : unit -> int
725
726       Returns the maximum number  of  pretty-printing  boxes  allowed  before
727       ellipsis.
728
729
730
731       val pp_over_max_boxes : formatter -> unit -> bool
732
733
734
735
736       val over_max_boxes : unit -> bool
737
738       Tests  if  the  maximum  number  of  pretty-printing boxes allowed have
739       already been opened.
740
741
742
743
744   Tabulation boxes
745       A tabulation box prints material on lines divided into cells  of  fixed
746       length. A tabulation box provides a simple way to display vertical col‐
747       umns of left adjusted text.
748
749       This box features command set_tab to define cell boundaries,  and  com‐
750       mand  print_tab to move from cell to cell and split the line when there
751       is no more cells to print on the line.
752
753       Note: printing within tabulation box is  line  directed,  so  arbitrary
754       line  splitting  inside  a tabulation box leads to poor rendering. Yet,
755       controlled use of tabulation boxes allows simple  printing  of  columns
756       within module Format .
757
758       val pp_open_tbox : formatter -> unit -> unit
759
760
761
762
763       val open_tbox : unit -> unit
764
765
766       open_tbox () opens a new tabulation box.
767
768       This box prints lines separated into cells of fixed width.
769
770       Inside  a  tabulation box, special tabulation markers defines points of
771       interest on the line (for instance to delimit cell boundaries).   Func‐
772       tion Format.set_tab sets a tabulation marker at insertion point.
773
774       A  tabulation  box  features specific tabulation breaks to move to next
775       tabulation marker  or  split  the  line.  Function  Format.print_tbreak
776       prints a tabulation break.
777
778
779
780       val pp_close_tbox : formatter -> unit -> unit
781
782
783
784
785       val close_tbox : unit -> unit
786
787       Closes the most recently opened tabulation box.
788
789
790
791       val pp_set_tab : formatter -> unit -> unit
792
793
794
795
796       val set_tab : unit -> unit
797
798       Sets a tabulation marker at current insertion point.
799
800
801
802       val pp_print_tab : formatter -> unit -> unit
803
804
805
806
807       val print_tab : unit -> unit
808
809
810       print_tab  ()  emits a 'next' tabulation break hint: if not already set
811       on a tabulation marker, the insertion point moves to the first  tabula‐
812       tion  marker  on  the  right, or the pretty-printer splits the line and
813       insertion point moves to the leftmost tabulation marker.
814
815       It is equivalent to print_tbreak 0 0 .
816
817
818
819       val pp_print_tbreak : formatter -> int -> int -> unit
820
821
822
823
824       val print_tbreak : int -> int -> unit
825
826
827       print_tbreak nspaces offset emits a 'full' tabulation break hint.
828
829       If not already set on a tabulation marker, the insertion point moves to
830       the  first tabulation marker on the right and the pretty-printer prints
831       nspaces spaces.
832
833       If there is no next tabulation marker on the right, the  pretty-printer
834       splits  the line at this point, then insertion point moves to the left‐
835       most tabulation marker of the box.
836
837       If the pretty-printer splits the line, offset is added to  the  current
838       indentation.
839
840
841
842
843   Ellipsis
844       val pp_set_ellipsis_text : formatter -> string -> unit
845
846
847
848
849       val set_ellipsis_text : string -> unit
850
851       Set  the  text  of  the  ellipsis printed when too many pretty-printing
852       boxes are open (a single dot, .  , by default).
853
854
855
856       val pp_get_ellipsis_text : formatter -> unit -> string
857
858
859
860
861       val get_ellipsis_text : unit -> string
862
863       Return the text of the ellipsis.
864
865
866
867
868   Semantic tags
869       type stag = ..
870
871
872       Semantic tags (or simply tags) are user's defined annotations to  asso‐
873       ciate user's specific operations to printed entities.
874
875       Common  usage  of semantic tags is text decoration to get specific font
876       or text size rendering for a display device, or marking delimitation of
877       entities  (e.g.  HTML  or  TeX  elements or terminal escape sequences).
878       More sophisticated usage of semantic tags could handle dynamic  modifi‐
879       cation  of  the  pretty-printer behavior to properly print the material
880       within some specific tags.  For instance, we can define an RGB tag like
881       so:
882       type stag += RGB of {r:int;g:int;b:int}
883
884
885       In  order  to properly delimit printed entities, a semantic tag must be
886       opened before and closed after the entity. Semantic tags must be  prop‐
887       erly   nested  like  parentheses  using  Format.pp_open_stag  and  For‐
888       mat.pp_close_stag .
889
890       Tag specific operations occur any time a tag is opened  or  closed,  At
891       each  occurrence, two kinds of operations are performed tag-marking and
892       tag-printing:
893
894       -The tag-marking operation is the simpler tag  specific  operation:  it
895       simply  writes a tag specific string into the output device of the for‐
896       matter. Tag-marking does not interfere with line-splitting computation.
897
898       -The tag-printing operation is the more involved  tag  specific  opera‐
899       tion: it can print arbitrary material to the formatter. Tag-printing is
900       tightly linked to the current pretty-printer operations.
901
902       Roughly speaking, tag-marking is commonly used to get a better  render‐
903       ing  of  texts  in the rendering device, while tag-printing allows fine
904       tuning of printing  routines  to  print  the  same  entity  differently
905       according  to the semantic tags (i.e. print additional material or even
906       omit parts of the output).
907
908       More precisely: when a semantic tag is opened or closed then  both  and
909       successive 'tag-printing' and 'tag-marking' operations occur:
910
911       -Tag-printing a semantic tag means calling the formatter specific func‐
912       tion print_open_stag (resp.  print_close_stag ) with the  name  of  the
913       tag  as argument: that tag-printing function can then print any regular
914       material to the formatter (so that this material is enqueued  as  usual
915       in the formatter queue for further line splitting computation).
916
917       -Tag-marking  a semantic tag means calling the formatter specific func‐
918       tion mark_open_stag (resp.  mark_close_stag ) with the name of the  tag
919       as argument: that tag-marking function can then return the 'tag-opening
920       marker' (resp. `tag-closing marker') for direct output into the  output
921       device of the formatter.
922
923       Being  written directly into the output device of the formatter, seman‐
924       tic tag marker strings are not considered as part of the printing mate‐
925       rial  that  drives  line  splitting  (in other words, the length of the
926       strings corresponding to tag markers is considered  as  zero  for  line
927       splitting).
928
929       Thus,   semantic   tag   handling  is  in  some  sense  transparent  to
930       pretty-printing and does not interfere with usual indentation. Hence, a
931       single  pretty-printing routine can output both simple 'verbatim' mate‐
932       rial or richer decorated output depending on the treatment of tags.  By
933       default,  tags  are  not active, hence the output is not decorated with
934       tag information. Once set_tags is set  to  true  ,  the  pretty-printer
935       engine honors tags and decorates the output accordingly.
936
937       Default  tag-marking  functions  behave  the  HTML  way: Format.tag are
938       enclosed in "<" and ">" while other tags are  ignored;  hence,  opening
939       marker for tag string "t" is "<t>" and closing marker is "</t>" .
940
941       Default tag-printing functions just do nothing.
942
943       Tag-marking  and  tag-printing  functions are user definable and can be
944       set by calling Format.set_formatter_stag_functions .
945
946       Semantic tag operations may be set on or  off  with  Format.set_tags  .
947       Tag-marking operations may be set on or off with Format.set_mark_tags .
948       Tag-printing operations may be set on or off with Format.set_print_tags
949       .
950
951
952       type tag = string
953
954
955
956
957       type Format.stag +=
958        |  String_tag  of tag  (* String_tag s is a string tag s . String tags
959       can be inserted either by explicitly using the  constructor  String_tag
960       or by using the dedicated format syntax "@{<s> ... @}" .
961        *)
962
963
964
965
966
967       val pp_open_stag : formatter -> stag -> unit
968
969
970
971
972       val open_stag : stag -> unit
973
974
975       pp_open_stag ppf t opens the semantic tag named t .
976
977       The  print_open_stag  tag-printing  function of the formatter is called
978       with t as argument; then the opening tag marker for t  ,  as  given  by
979       mark_open_stag t , is written into the output device of the formatter.
980
981
982
983       val pp_close_stag : formatter -> unit -> unit
984
985
986
987
988       val close_stag : unit -> unit
989
990
991       pp_close_stag ppf () closes the most recently opened semantic tag t .
992
993       The closing tag marker, as given by mark_close_stag t , is written into
994       the  output  device  of  the  formatter;  then   the   print_close_stag
995       tag-printing function of the formatter is called with t as argument.
996
997
998
999       val pp_set_tags : formatter -> bool -> unit
1000
1001
1002
1003
1004       val set_tags : bool -> unit
1005
1006
1007       pp_set_tags  ppf  b  turns  on  or  off  the treatment of semantic tags
1008       (default is off).
1009
1010
1011
1012       val pp_set_print_tags : formatter -> bool -> unit
1013
1014
1015
1016
1017       val set_print_tags : bool -> unit
1018
1019
1020       pp_set_print_tags ppf b turns on or off the tag-printing operations.
1021
1022
1023
1024       val pp_set_mark_tags : formatter -> bool -> unit
1025
1026
1027
1028
1029       val set_mark_tags : bool -> unit
1030
1031
1032       pp_set_mark_tags ppf b turns on or off the tag-marking operations.
1033
1034
1035
1036       val pp_get_print_tags : formatter -> unit -> bool
1037
1038
1039
1040
1041       val get_print_tags : unit -> bool
1042
1043       Return the current status of tag-printing operations.
1044
1045
1046
1047       val pp_get_mark_tags : formatter -> unit -> bool
1048
1049
1050
1051
1052       val get_mark_tags : unit -> bool
1053
1054       Return the current status of tag-marking operations.
1055
1056
1057
1058       val pp_set_formatter_out_channel : formatter -> out_channel -> unit
1059
1060
1061   Redirecting the standard formatter output
1062       val set_formatter_out_channel : out_channel -> unit
1063
1064       Redirect the standard pretty-printer output to the given channel.  (All
1065       the  output  functions of the standard formatter are set to the default
1066       output functions printing to the given channel.)
1067
1068
1069       set_formatter_out_channel  is   equivalent   to   Format.pp_set_format‐
1070       ter_out_channel std_formatter .
1071
1072
1073
1074       val  pp_set_formatter_output_functions : formatter -> (string -> int ->
1075       int -> unit) -> (unit -> unit) -> unit
1076
1077
1078
1079
1080       val set_formatter_output_functions : (string -> int -> int -> unit)  ->
1081       (unit -> unit) -> unit
1082
1083
1084       pp_set_formatter_output_functions  ppf out flush redirects the standard
1085       pretty-printer output functions to the functions out and flush .
1086
1087       The out function performs all the pretty-printer string output.  It  is
1088       called  with  a string s , a start position p , and a number of charac‐
1089       ters n ; it is supposed to output characters p to p + n - 1 of s .
1090
1091       The flush function is called whenever  the  pretty-printer  is  flushed
1092       (via  conversion  %!   , or pretty-printing indications @?  or @.  , or
1093       using low level functions print_flush or print_newline ).
1094
1095
1096
1097       val pp_get_formatter_output_functions : formatter -> unit -> (string ->
1098       int -> int -> unit) * (unit -> unit)
1099
1100
1101
1102
1103       val  get_formatter_output_functions  : unit -> (string -> int -> int ->
1104       unit) * (unit -> unit)
1105
1106       Return the current output functions of the standard pretty-printer.
1107
1108
1109
1110
1111   Redefining formatter output
1112       The Format module is versatile enough to let  you  completely  redefine
1113       the  meaning  of pretty-printing output: you may provide your own func‐
1114       tions to define how to handle indentation,  line  splitting,  and  even
1115       printing of all the characters that have to be printed!
1116
1117   Redefining output functions
1118       type formatter_out_functions = {
1119        out_string : string -> int -> int -> unit ;
1120        out_flush : unit -> unit ;
1121        out_newline : unit -> unit ;
1122        out_spaces : int -> unit ;
1123        out_indent : int -> unit ;
1124        }
1125
1126
1127       The set of output functions specific to a formatter:
1128
1129       -the out_string function performs all the pretty-printer string output.
1130       It is called with a string s , a start position p ,  and  a  number  of
1131       characters  n ; it is supposed to output characters p to p + n - 1 of s
1132       .
1133
1134       -the out_flush function flushes the pretty-printer output device.
1135
1136       - out_newline is called to open a  new  line  when  the  pretty-printer
1137       splits the line.
1138
1139       -the out_spaces function outputs spaces when a break hint leads to spa‐
1140       ces instead of a line split. It is called with the number of spaces  to
1141       output.
1142
1143       -the  out_indent  function  performs  new  line  indentation  when  the
1144       pretty-printer splits the line. It is called with the indentation value
1145       of the new line.
1146
1147       By default:
1148
1149       -fields  out_string  and  out_flush  are  output device specific; (e.g.
1150       output_string and flush for a out_channel  device,  or  Buffer.add_sub‐
1151       string and ignore for a Buffer.t output device),
1152
1153       -field out_newline is equivalent to out_string "\n" 0 1 ;
1154
1155       -fields   out_spaces   and  out_indent  are  equivalent  to  out_string
1156       (String.make n ' ') 0 n .
1157
1158
1159
1160       Since 4.01.0
1161
1162
1163
1164       val pp_set_formatter_out_functions : formatter  ->  formatter_out_func‐
1165       tions -> unit
1166
1167
1168
1169
1170       val set_formatter_out_functions : formatter_out_functions -> unit
1171
1172
1173       pp_set_formatter_out_functions  ppf out_funs Set all the pretty-printer
1174       output functions of ppf to those of argument out_funs ,
1175
1176       This way, you can change the meaning of indentation (which can be some‐
1177       thing  else than just printing space characters) and the meaning of new
1178       lines opening (which can be connected to any other action needed by the
1179       application at hand).
1180
1181       Reasonable  defaults  for  functions  out_spaces  and  out_newline  are
1182       respectively  out_funs.out_string  (String.make  n  '  ')   0   n   and
1183       out_funs.out_string "\n" 0 1 .
1184
1185
1186       Since 4.01.0
1187
1188
1189
1190       val  pp_get_formatter_out_functions  :  formatter  ->  unit  -> format‐
1191       ter_out_functions
1192
1193
1194
1195
1196       val get_formatter_out_functions : unit -> formatter_out_functions
1197
1198       Return the current output functions of  the  pretty-printer,  including
1199       line  splitting and indentation functions. Useful to record the current
1200       setting and restore it afterwards.
1201
1202
1203       Since 4.01.0
1204
1205
1206
1207
1208   Redefining semantic tag operations
1209       type formatter_stag_functions = {
1210        mark_open_stag : stag -> string ;
1211        mark_close_stag : stag -> string ;
1212        print_open_stag : stag -> unit ;
1213        print_close_stag : stag -> unit ;
1214        }
1215
1216
1217       The semantic tag handling functions specific to a formatter: mark  ver‐
1218       sions are the 'tag-marking' functions that associate a string marker to
1219       a tag in order for the pretty-printing engine to write those markers as
1220       0  length tokens in the output device of the formatter.  print versions
1221       are the 'tag-printing' functions that can perform regular printing when
1222       a tag is closed or opened.
1223
1224
1225
1226       val pp_set_formatter_stag_functions : formatter -> formatter_stag_func‐
1227       tions -> unit
1228
1229
1230
1231
1232       val set_formatter_stag_functions : formatter_stag_functions -> unit
1233
1234
1235       pp_set_formatter_stag_functions ppf tag_funs  changes  the  meaning  of
1236       opening  and  closing  semantic  tag operations to use the functions in
1237       tag_funs when printing on ppf .
1238
1239       When opening a semantic tag with name t , the string t is passed to the
1240       opening  tag-marking  function  (the mark_open_stag field of the record
1241       tag_funs ), that must return the opening tag marker for that name. When
1242       the next call to close_stag () happens, the semantic tag name t is sent
1243       back to the closing tag-marking function (the mark_close_stag field  of
1244       record tag_funs ), that must return a closing tag marker for that name.
1245
1246       The print_ field of the record contains the tag-printing functions that
1247       are called at tag opening and tag closing time, to output regular mate‐
1248       rial in the pretty-printer queue.
1249
1250
1251
1252       val  pp_get_formatter_stag_functions  :  formatter  ->  unit -> format‐
1253       ter_stag_functions
1254
1255
1256
1257
1258       val get_formatter_stag_functions : unit -> formatter_stag_functions
1259
1260       Return the current semantic tag operation  functions  of  the  standard
1261       pretty-printer.
1262
1263
1264
1265
1266   Defining formatters
1267       Defining  new formatters permits unrelated output of material in paral‐
1268       lel on several output devices.  All the parameters of a  formatter  are
1269       local  to the formatter: right margin, maximum indentation limit, maxi‐
1270       mum number of pretty-printing boxes simultaneously open, ellipsis,  and
1271       so on, are specific to each formatter and may be fixed independently.
1272
1273       For  instance, given a Buffer.t buffer b , Format.formatter_of_buffer b
1274       returns a new formatter using buffer b as  its  output  device.   Simi‐
1275       larly,   given   a  out_channel  output  channel  oc  ,  Format.format‐
1276       ter_of_out_channel oc returns a new formatter using channel oc  as  its
1277       output device.
1278
1279       Alternatively,  given out_funs , a complete set of output functions for
1280       a formatter, then Format.formatter_of_out_functions out_funs computes a
1281       new formatter using those functions for output.
1282
1283       val formatter_of_out_channel : out_channel -> formatter
1284
1285
1286       formatter_of_out_channel oc returns a new formatter writing to the cor‐
1287       responding output channel oc .
1288
1289
1290
1291       val std_formatter : formatter
1292
1293       The standard formatter to write to standard output.
1294
1295       It is defined as Format.formatter_of_out_channel stdout .
1296
1297
1298
1299       val err_formatter : formatter
1300
1301       A formatter to write to standard error.
1302
1303       It is defined as Format.formatter_of_out_channel stderr .
1304
1305
1306
1307       val formatter_of_buffer : Buffer.t -> formatter
1308
1309
1310       formatter_of_buffer b returns a new formatter writing to buffer b .  At
1311       the  end  of  pretty-printing, the formatter must be flushed using For‐
1312       mat.pp_print_flush or Format.pp_print_newline , to print all the  pend‐
1313       ing material into the buffer.
1314
1315
1316
1317       val stdbuf : Buffer.t
1318
1319       The string buffer in which str_formatter writes.
1320
1321
1322
1323       val str_formatter : formatter
1324
1325       A formatter to output to the Format.stdbuf string buffer.
1326
1327
1328       str_formatter is defined as Format.formatter_of_buffer Format.stdbuf .
1329
1330
1331
1332       val flush_str_formatter : unit -> string
1333
1334       Returns the material printed with str_formatter , flushes the formatter
1335       and resets the corresponding buffer.
1336
1337
1338
1339       val make_formatter : (string -> int -> int -> unit) -> (unit  ->  unit)
1340       -> formatter
1341
1342
1343       make_formatter  out  flush  returns  a  new formatter that outputs with
1344       function out , and flushes with function flush .
1345
1346       For instance,
1347           make_formatter
1348             (Stdlib.output oc)
1349             (fun () -> Stdlib.flush oc)
1350       returns a formatter to the out_channel oc .
1351
1352
1353
1354       val formatter_of_out_functions : formatter_out_functions -> formatter
1355
1356
1357       formatter_of_out_functions out_funs returns a new formatter that writes
1358       with the set of output functions out_funs .
1359
1360       See  definition  of type Format.formatter_out_functions for the meaning
1361       of argument out_funs .
1362
1363
1364       Since 4.06.0
1365
1366
1367
1368
1369   Symbolic pretty-printing
1370       Symbolic pretty-printing is pretty-printing using a symbolic formatter,
1371       i.e. a formatter that outputs symbolic pretty-printing items.
1372
1373       When using a symbolic formatter, all regular pretty-printing activities
1374       occur but output material is symbolic and stored in a buffer of  output
1375       items.   At  the  end  of  pretty-printing,  flushing the output buffer
1376       allows post-processing of symbolic output before performing  low  level
1377       output operations.
1378
1379       In practice, first define a symbolic output buffer b using:
1380
1381       -  let  sob  = make_symbolic_output_buffer () .  Then define a symbolic
1382       formatter with:
1383
1384       - let ppf = formatter_of_symbolic_output_buffer sob
1385
1386       Use symbolic formatter ppf as usual, and retrieve symbolic items at end
1387       of pretty-printing by flushing symbolic output buffer sob with:
1388
1389       - flush_symbolic_output_buffer sob .
1390
1391
1392       type symbolic_output_item =
1393        | Output_flush  (* symbolic flush command
1394        *)
1395        | Output_newline  (* symbolic newline command
1396        *)
1397        | Output_string of string
1398         (* Output_string s : symbolic output for string s
1399
1400        *)
1401        | Output_spaces of int
1402         (* Output_spaces n : symbolic command to output n spaces
1403        *)
1404        | Output_indent of int
1405         (* Output_indent i : symbolic indentation of size i
1406
1407        *)
1408
1409
1410       Items produced by symbolic pretty-printers
1411
1412
1413       Since 4.06.0
1414
1415
1416       type symbolic_output_buffer
1417
1418
1419       The output buffer of a symbolic pretty-printer.
1420
1421
1422       Since 4.06.0
1423
1424
1425
1426       val make_symbolic_output_buffer : unit -> symbolic_output_buffer
1427
1428
1429       make_symbolic_output_buffer () returns a fresh buffer for symbolic out‐
1430       put.
1431
1432
1433       Since 4.06.0
1434
1435
1436
1437       val clear_symbolic_output_buffer : symbolic_output_buffer -> unit
1438
1439
1440       clear_symbolic_output_buffer sob resets buffer sob .
1441
1442
1443       Since 4.06.0
1444
1445
1446
1447       val  get_symbolic_output_buffer  :   symbolic_output_buffer   ->   sym‐
1448       bolic_output_item list
1449
1450
1451       get_symbolic_output_buffer sob returns the contents of buffer sob .
1452
1453
1454       Since 4.06.0
1455
1456
1457
1458       val   flush_symbolic_output_buffer  :  symbolic_output_buffer  ->  sym‐
1459       bolic_output_item list
1460
1461
1462       flush_symbolic_output_buffer sob returns the contents of buffer sob and
1463       resets  buffer sob .  flush_symbolic_output_buffer sob is equivalent to
1464       let items = get_symbolic_output_buffer sob in
1465          clear_symbolic_output_buffer sob; items
1466
1467
1468
1469       Since 4.06.0
1470
1471
1472
1473       val add_symbolic_output_item : symbolic_output_buffer ->  symbolic_out‐
1474       put_item -> unit
1475
1476
1477       add_symbolic_output_item sob itm adds item itm to buffer sob .
1478
1479
1480       Since 4.06.0
1481
1482
1483
1484       val  formatter_of_symbolic_output_buffer  :  symbolic_output_buffer  ->
1485       formatter
1486
1487
1488       formatter_of_symbolic_output_buffer sob returns  a  symbolic  formatter
1489       that outputs to symbolic_output_buffer sob .
1490
1491
1492       Since 4.06.0
1493
1494
1495
1496
1497   Convenience formatting functions.
1498       val  pp_print_list  : ?pp_sep:(formatter -> unit -> unit) -> (formatter
1499       -> 'a -> unit) -> formatter -> 'a list -> unit
1500
1501
1502       pp_print_list ?pp_sep pp_v ppf l prints items of list l , using pp_v to
1503       print  each item, and calling pp_sep between items ( pp_sep defaults to
1504       Format.pp_print_cut .  Does nothing on empty lists.
1505
1506
1507       Since 4.02.0
1508
1509
1510
1511       val pp_print_text : formatter -> string -> unit
1512
1513
1514       pp_print_text ppf s prints s  with  spaces  and  newlines  respectively
1515       printed using Format.pp_print_space and Format.pp_force_newline .
1516
1517
1518       Since 4.02.0
1519
1520
1521
1522       val  pp_print_option  : ?none:(formatter -> unit -> unit) -> (formatter
1523       -> 'a -> unit) -> formatter -> 'a option -> unit
1524
1525
1526       pp_print_option ?none pp_v ppf o prints o on ppf using  pp_v  if  o  is
1527       Some v and none if it is None .  none prints nothing by default.
1528
1529
1530       Since 4.08
1531
1532
1533
1534       val  pp_print_result : ok:(formatter -> 'a -> unit) -> error:(formatter
1535       -> 'e -> unit) -> formatter -> ('a, 'e) result -> unit
1536
1537
1538       pp_print_result ~ok ~error ppf r prints r on ppf using ok if r is Ok  _
1539       and error if r is Error _ .
1540
1541
1542       Since 4.08
1543
1544
1545
1546
1547   Formatted pretty-printing
1548       Module  Format  provides  a  complete  set of printf like functions for
1549       pretty-printing using format string specifications.
1550
1551       Specific annotations may  be  added  in  the  format  strings  to  give
1552       pretty-printing commands to the pretty-printing engine.
1553
1554       Those  annotations  are  introduced  in  the format strings using the @
1555       character. For instance, @ means a space break,  @,  means  a  cut,  @[
1556       opens a new box, and @] closes the last open box.
1557
1558       val fprintf : formatter -> ('a, formatter, unit) format -> 'a
1559
1560
1561
1562
1563
1564       fprintf ff fmt arg1 ... argN formats the arguments arg1 to argN accord‐
1565       ing to the format string fmt , and outputs the resulting string on  the
1566       formatter ff .
1567
1568       The  format string fmt is a character string which contains three types
1569       of objects: plain characters and conversion specifications as specified
1570       in  the  Printf module, and pretty-printing indications specific to the
1571       Format module.
1572
1573       The pretty-printing indication characters are introduced by a @ charac‐
1574       ter, and their meanings are:
1575
1576       -  @[  : open a pretty-printing box. The type and offset of the box may
1577       be optionally specified with the following  syntax:  the  <  character,
1578       followed  by  an optional box type indication, then an optional integer
1579       offset, and the closing > character.  Pretty-printing box type  is  one
1580       of  h  ,  v  ,  hv  ,  b  ,  or hov .  ' h ' stands for an 'horizontal'
1581       pretty-printing box, ' v ' stands for a 'vertical' pretty-printing box,
1582       '  hv  ' stands for an 'horizontal/vertical' pretty-printing box, ' b '
1583       stands for an 'horizontal-or-vertical' pretty-printing box  demonstrat‐
1584       ing  indentation,  '  hov  '  stands  a simple 'horizontal-or-vertical'
1585       pretty-printing box.   For  instance,  @[<hov  2>  opens  an  'horizon‐
1586       tal-or-vertical'  pretty-printing  box  with  indentation 2 as obtained
1587       with open_hovbox 2 .  For more details about pretty-printing boxes, see
1588       the various box opening functions open_*box .
1589
1590       - @] : close the most recently opened pretty-printing box.
1591
1592       - @, : output a 'cut' break hint, as with print_cut () .
1593
1594       - @ : output a 'space' break hint, as with print_space () .
1595
1596       - @; : output a 'full' break hint as with print_break . The nspaces and
1597       offset parameters of the break hint may be  optionally  specified  with
1598       the  following  syntax: the < character, followed by an integer nspaces
1599       value, then an integer offset , and  a  closing  >  character.   If  no
1600       parameters  are  provided,  the  good break defaults to a 'space' break
1601       hint.
1602
1603       - @.  : flush the pretty-printer and split the line, as with print_new‐
1604       line () .
1605
1606       -  @<n>  : print the following item as if it were of length n .  Hence,
1607       printf "@<0>%s" arg prints arg as a zero length string.  If @<n> is not
1608       followed by a conversion specification, then the following character of
1609       the format is printed as if it were of length n .
1610
1611       - @{ : open a semantic tag. The name of the tag may be optionally spec‐
1612       ified  with  the  following  syntax:  the  <  character, followed by an
1613       optional string specification, and the closing > character. The  string
1614       specification is any character string that does not contain the closing
1615       character '>' . If omitted, the tag name defaults to the empty  string.
1616       For   more   details  about  semantic  tags,  see  the  functions  For‐
1617       mat.open_stag and Format.close_stag .
1618
1619       - @} : close the most recently opened semantic tag.
1620
1621       - @?  : flush the pretty-printer as with  print_flush  ()  .   This  is
1622       equivalent to the conversion %!  .
1623
1624       -  @\n : force a newline, as with force_newline () , not the normal way
1625       of pretty-printing, you should prefer using break hints inside a verti‐
1626       cal pretty-printing box.
1627
1628       Note: To prevent the interpretation of a @ character as a pretty-print‐
1629       ing indication, escape it with a % character.  Old quotation mode @@ is
1630       deprecated  since it is not compatible with formatted input interpreta‐
1631       tion of character '@' .
1632
1633       Example: printf "@[%s@ %d@]@." "x =" 1 is equivalent  to  open_box  ();
1634       print_string "x ="; print_space ();
1635           print_int  1;  close_box  ();  print_newline  () .  It prints x = 1
1636       within a pretty-printing 'horizontal-or-vertical' box.
1637
1638       val printf : ('a, formatter, unit) format -> 'a
1639
1640       Same as fprintf above, but output on std_formatter .
1641
1642
1643
1644       val eprintf : ('a, formatter, unit) format -> 'a
1645
1646       Same as fprintf above, but output on err_formatter .
1647
1648
1649
1650       val sprintf : ('a, unit, string) format -> 'a
1651
1652       Same as printf above, but instead of printing on a formatter, returns a
1653       string  containing  the  result of formatting the arguments.  Note that
1654       the pretty-printer queue is flushed at the end of each call to  sprintf
1655       .
1656
1657       In  case of multiple and related calls to sprintf to output material on
1658       a single string, you should consider using fprintf with the  predefined
1659       formatter  str_formatter  and  call  flush_str_formatter  () to get the
1660       final result.
1661
1662       Alternatively, you can use Format.fprintf with a formatter writing to a
1663       buffer of your own: flushing the formatter and the buffer at the end of
1664       pretty-printing returns the desired string.
1665
1666
1667
1668       val asprintf : ('a, formatter, unit, string) format4 -> 'a
1669
1670       Same as printf above, but instead of printing on a formatter, returns a
1671       string  containing the result of formatting the arguments.  The type of
1672       asprintf is general enough to interact nicely with %a conversions.
1673
1674
1675       Since 4.01.0
1676
1677
1678
1679       val dprintf : ('a, formatter, unit, formatter -> unit) format4 -> 'a
1680
1681       Same as Format.fprintf , except the formatter  is  the  last  argument.
1682       dprintf  "..."  a b c is a function of type formatter -> unit which can
1683       be given to a format specifier %t .
1684
1685       This can be used as a replacement for Format.asprintf to delay  format‐
1686       ting  decisions. Using the string returned by Format.asprintf in a for‐
1687       matting context forces formatting decisions to be taken  in  isolation,
1688       and the final string may be created prematurely.  Format.dprintf allows
1689       delay of formatting decisions until the  final  formatting  context  is
1690       known.  For example:
1691         let t = Format.dprintf "%i@ %i@ %i" 1 2 3 in
1692         ...
1693         Format.printf "@[<v>%t@]" t
1694
1695
1696
1697       Since 4.08.0
1698
1699
1700
1701       val ifprintf : formatter -> ('a, formatter, unit) format -> 'a
1702
1703       Same  as  fprintf above, but does not print anything.  Useful to ignore
1704       some material when conditionally printing.
1705
1706
1707       Since 3.10.0
1708
1709
1710
1711
1712       Formatted Pretty-Printing with continuations.
1713
1714       val kfprintf : (formatter -> 'a) -> formatter -> ('b, formatter,  unit,
1715       'a) format4 -> 'b
1716
1717       Same as fprintf above, but instead of returning immediately, passes the
1718       formatter to its first argument at the end of printing.
1719
1720
1721
1722       val kdprintf : ((formatter -> unit) -> 'a) -> ('b, formatter, unit, 'a)
1723       format4 -> 'b
1724
1725       Same  as  Format.dprintf  above,  but instead of returning immediately,
1726       passes the suspended printer to its first argument at the end of print‐
1727       ing.
1728
1729
1730       Since 4.08.0
1731
1732
1733
1734       val ikfprintf : (formatter -> 'a) -> formatter -> ('b, formatter, unit,
1735       'a) format4 -> 'b
1736
1737       Same as kfprintf above, but does not print anything.  Useful to  ignore
1738       some material when conditionally printing.
1739
1740
1741       Since 3.12.0
1742
1743
1744
1745       val ksprintf : (string -> 'a) -> ('b, unit, string, 'a) format4 -> 'b
1746
1747       Same  as  sprintf above, but instead of returning the string, passes it
1748       to the first argument.
1749
1750
1751
1752       val kasprintf : (string -> 'a) -> ('b, formatter, unit, 'a) format4  ->
1753       'b
1754
1755       Same  as asprintf above, but instead of returning the string, passes it
1756       to the first argument.
1757
1758
1759       Since 4.03
1760
1761
1762
1763
1764   Deprecated
1765       val bprintf : Buffer.t -> ('a, formatter, unit) format -> 'a
1766
1767       Deprecated.  This function is error prone. Do not use it.   This  func‐
1768       tion  is  neither  compositional  nor incremental, since it flushes the
1769       pretty-printer queue at each call.
1770
1771       If you need to print to some buffer b , you must first define a format‐
1772       ter  writing  to  b , using let to_b = formatter_of_buffer b ; then use
1773       regular calls to Format.fprintf with formatter to_b .
1774
1775
1776
1777       val kprintf : (string -> 'a) -> ('b, unit, string, 'a) format4 -> 'b
1778
1779       Deprecated.  An alias for ksprintf .
1780
1781
1782
1783       val set_all_formatter_output_functions : out:(string -> int ->  int  ->
1784       unit)  -> flush:(unit -> unit) -> newline:(unit -> unit) -> spaces:(int
1785       -> unit) -> unit
1786
1787       Deprecated.  Subsumed by set_formatter_out_functions .
1788
1789
1790
1791       val get_all_formatter_output_functions : unit -> (string -> int ->  int
1792       -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
1793
1794       Deprecated.  Subsumed by get_formatter_out_functions .
1795
1796
1797
1798       val pp_set_all_formatter_output_functions : formatter -> out:(string ->
1799       int -> int -> unit) -> flush:(unit -> unit) -> newline:(unit  ->  unit)
1800       -> spaces:(int -> unit) -> unit
1801
1802       Deprecated.  Subsumed by pp_set_formatter_out_functions .
1803
1804
1805
1806       val   pp_get_all_formatter_output_functions  :  formatter  ->  unit  ->
1807       (string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int
1808       -> unit)
1809
1810       Deprecated.  Subsumed by pp_get_formatter_out_functions .
1811
1812
1813
1814
1815   String tags
1816       val pp_open_tag : formatter -> tag -> unit
1817
1818       Deprecated.  Subsumed by Format.pp_open_stag .
1819
1820
1821
1822       val open_tag : tag -> unit
1823
1824       Deprecated.  Subsumed by Format.open_stag .
1825
1826
1827
1828       val pp_close_tag : formatter -> unit -> unit
1829
1830       Deprecated.  Subsumed by Format.pp_close_stag .
1831
1832
1833
1834       val close_tag : unit -> unit
1835
1836       Deprecated.  Subsumed by Format.close_stag .
1837
1838
1839       type formatter_tag_functions = {
1840        mark_open_tag : tag -> string ;
1841        mark_close_tag : tag -> string ;
1842        print_open_tag : tag -> unit ;
1843        print_close_tag : tag -> unit ;
1844        }
1845
1846
1847       Deprecated.  Subsumed by Format.formatter_stag_functions .
1848
1849
1850
1851       val  pp_set_formatter_tag_functions  : formatter -> formatter_tag_func‐
1852       tions -> unit
1853
1854       Deprecated.  Subsumed by Format.pp_set_formatter_stag_functions .
1855
1856
1857       This function will erase non-string tag formatting functions.
1858
1859
1860
1861       val set_formatter_tag_functions : formatter_tag_functions -> unit
1862
1863       Deprecated.  Subsumed by Format.set_formatter_stag_functions .
1864
1865
1866
1867       val pp_get_formatter_tag_functions  :  formatter  ->  unit  ->  format‐
1868       ter_tag_functions
1869
1870       Deprecated.  Subsumed by Format.pp_get_formatter_stag_functions .
1871
1872
1873
1874       val get_formatter_tag_functions : unit -> formatter_tag_functions
1875
1876       Deprecated.  Subsumed by Format.get_formatter_stag_functions .
1877
1878
1879
1880
1881
1882OCamldoc                          2020-09-01                  Stdlib.Format(3)
Impressum