Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Matthieu Dubuget <matthieu.dubuget@gmail.com>
To: caml-list <caml-list@inria.fr>
Subject: [Caml-list] Format java-like comment block
Date: Thu, 09 Oct 2014 13:09:00 +0200	[thread overview]
Message-ID: <54366CCC.3050607@gmail.com> (raw)


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


                 reply	other threads:[~2014-10-09 11:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54366CCC.3050607@gmail.com \
    --to=matthieu.dubuget@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox