Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Benoit Vaugon <benoit.vaugon@gmail.com>
To: alan.schmitt@polytechnique.org, caml-list@inria.fr
Subject: Re: [Caml-list] A question about Format and semantic tags
Date: Wed, 23 Mar 2016 16:01:49 +0100	[thread overview]
Message-ID: <56F2AFDD.3090609@gmail.com> (raw)
In-Reply-To: <m237rhpdis.fsf@charm-ecran.irisa.fr>

Hello Alan,

In fact, the Format tag activation is local to a formatter. The function 
Format.set_tags enables tags only for the std_formatter (associated to 
stdout). If you want to activate tags for the Format.str_formatter, you 
should call:

Format.pp_set_tags Format.str_formatter true;

instead of:

Format.set_tags true;
Format.set_mark_tags true;

Benoît.


Le 23/03/2016 13:47, Alan Schmitt a écrit :
> Hello,
>
> I need to output two versions of a string that only differ by the
> presence of some markers in them, and I want the output to be pretty
> (it's code to be read). It seems that semantic tags from the Format
> module would allow me to do this, with identical line breaking as these
> tags are considered 0 width. Unfortunately I cannot seem to make it
> work. Here is what I have tried:
>
> #+begin_src ocaml
> let file_put_contents filename text =
>     try
>        let handle = open_out filename in
>        output_string handle text;
>        close_out handle
>     with Sys_error s ->
>       failwith ("Could not write in file: " ^ filename ^ "\n" ^ s)
>
> let filename = "test_out.txt"
>
> let out = "@[<hov 2>Hello World@ Hello@ Hello again@ Hello@ Hello again@ Hello@ Hello again@ @{<foo>Hello@ Cut again@}@]"
>
> let _ =
>    Format.set_tags true;
>    Format.set_mark_tags true;
>    Format.fprintf Format.str_formatter (Scanf.format_from_string out "");
>    file_put_contents filename (Format.flush_str_formatter ())
> #+end_src
>
> To run this I do ~ocamlc -o tags tags.ml && ./tags && cat test_out.txt~.
>
> As I have turned on treatment of tags and tag marking, I would expect to
> see the tag marker in the output string using the default format (<foo>
> and </foo>), but I do not see them.
>
> Am I on the right track by using tags? Could someone point me to my
> mistake?
>
> Thanks a lot,
>
> Alan
>


  reply	other threads:[~2016-03-23 15:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 12:47 Alan Schmitt
2016-03-23 15:01 ` Benoit Vaugon [this message]
2016-03-23 15:38   ` Alan Schmitt

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=56F2AFDD.3090609@gmail.com \
    --to=benoit.vaugon@gmail.com \
    --cc=alan.schmitt@polytechnique.org \
    --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