Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007913OCamldocumentationpublic2019-02-07 04:422019-02-18 09:45
Reporterramsdell0 
Assigned Tooctachron 
PrioritynormalSeverityminorReproducibilityalways
StatusassignedResolutionopen 
Platformx86_64OSMac OSOS VersionMojave
Product Version4.07.1 
Target VersionFixed in Version 
Summary0007913: Pretty printer line break unexpected
DescriptionThe enclosed program shows a case in which a line of text is broken in an unexpected place. The pretty printer only allows line breaks after commas, but the program breaks a line after an open parenthesis.

The output of the enclosed program is:

$ ./ppterm
pred(a12(x1, y1), a1234(x1, y1), a1234(x1, y1), a1234(x1, y1), a1234(
     x1, y1), a1234(x1, y1))
Steps To Reproduce$ ocamlc -o ppterm ppterm.ml
$ ./ppterm
TagsNo tags attached.
Attached Files? file icon ppterm.ml [^] (2,022 bytes) 2019-02-07 04:42 [Show Content]

- Relationships
related to 0007804resolvedoctachron In the format library, are boxes intended to implicitly break? 

-  Notes
(0019585)
octachron (developer)
2019-02-07 11:53

This is the maximum indentation feature in action (cf. http://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html#1_Maximumindentationlimit [^]): boxes opened beyond the current value of the maximum indentation are rejected to the left. Your specific issue can be fixed by increasing this maximum indentation with

let () =
  let f = formatter_of_out_channel stdout in
  Format.pp_set_max_indent f (Format.pp_get_margin f ()-1);
  pp_print_term f example;
  pp_print_newline f ()
(0019586)
ramsdell0 (reporter)
2019-02-07 19:18

Thank you for your quick reply. The snippet of code I submitted was
extracted from a larger set of programs, one of which read the flawed
pretty printing output and exhibited a subtle bug as a result. The
patch you sent eliminates erroneous output and squashes the bug.

I ask that goal for responding to this bug report be to change the
documentation in the Format library's source code. I reread that
documentation and I do not see how others have a chance at figuring
out the correct way to obtain the desired behavior. Let me offer some
words for you to consider to add to the file.

(** {1:breaks Break hints} *)

(** The pretty printer will split a line at a location specified by a
break hint or when boxes are opened beyond the current maximum
indentation limit. The second case will be explained in the section
titled "Maximum indentation limit". *)

...

(** {1 Maximum indentation limit} *)

val pp_set_max_indent : formatter -> int -> unit
val set_max_indent : int -> unit
(**...

  If [d] is greater or equal than the current margin, it is ignored,
  and the current maximum indentation limit is kept.

...

  To insure that a pretty printer splits lines only under the
  direction of break hints, set the maximum margin as follows.
  {[pp_set_max_margin f (pp_get_margin f () - 1)]}

  See also {!pp_set_geometry}.
*)
(0019607)
octachron (developer)
2019-02-18 09:44

I agree that the documentation should be updated.

- Issue History
Date Modified Username Field Change
2019-02-07 04:42 ramsdell0 New Issue
2019-02-07 04:42 ramsdell0 File Added: ppterm.ml
2019-02-07 11:53 octachron Note Added: 0019585
2019-02-07 11:57 octachron Relationship added related to 0007804
2019-02-07 19:18 ramsdell0 Note Added: 0019586
2019-02-18 09:44 octachron Note Added: 0019607
2019-02-18 09:44 octachron Category standard library => documentation
2019-02-18 09:45 octachron Assigned To => octachron
2019-02-18 09:45 octachron Status new => assigned


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker