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