* [Caml-list] Format java-like comment block
@ 2014-10-09 11:09 Matthieu Dubuget
0 siblings, 0 replies; only message in thread
From: Matthieu Dubuget @ 2014-10-09 11:09 UTC (permalink / raw)
To: caml-list
Hello,
I'm trying to output lines of text in a java-like comment block using
Format (Ocaml 4.01.0).
It should start with '/**'.
Each line should begin with ' *'.
And the comment should be closed with ' */'.
Since I was not able to achieve this, I wrote a flat example
(see below).
It's output is as expected:
```
..............................................................................
/**
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin faucibus
tempor est sit amet laoreet. Suspendisse lacinia commodo
*/
..............................................................................
```
If I uncomment the commented lines, I would have expected something like:
```
..............................................................................
/**
* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin faucibus
* tempor est sit amet laoreet. Suspendisse lacinia commodo
*/
..............................................................................
```
but instead, I'm obtaining:
..............................................................................
/**
* Lorem ipsum dolor sit amet, consectetur adipiscing elit.
* Proin faucibus tempor est sit amet
* laoreet. Suspendisse
* lacinia commodo
*/
..............................................................................
Is it a bug or a misunderstanding?
```ocaml
let _ =
let mymargin = 78 in
let add_rule b marg =
Buffer.add_string b "\n";
Buffer.add_string b (String.make marg '.');
Buffer.add_string b "\n" in
(* let stars = "* " in *)
let b = Buffer.create 100 in
let f = Format.formatter_of_buffer b in
Format.pp_set_margin f mymargin;
add_rule b mymargin;
Format.pp_open_box f 3;
Format.pp_print_string f " /**";
Format.pp_force_newline f ();
Format.pp_open_box f 0;
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "Lorem";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "ipsum";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "dolor";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "sit";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "amet,";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "consectetur";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "adipiscing";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "elit.";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "Proin";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "faucibus";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "tempor";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "est";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "sit";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "amet";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "laoreet.";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "Suspendisse";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "lacinia";
Format.pp_print_space f ();
(* Format.pp_print_if_newline f (); *)
(* Format.pp_print_string f stars; *)
Format.pp_print_string f "commodo";
Format.pp_force_newline f ();
Format.pp_print_string f "*/";
Format.pp_print_newline f ();
add_rule b mymargin;
Buffer.contents b |> print_endline
```
--
Matthieu Dubuget
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-10-09 11:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-09 11:09 [Caml-list] Format java-like comment block Matthieu Dubuget
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox