caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alan Schmitt <alan.schmitt@polytechnique.org>
To: OCaml Mailing List <caml-list@inria.fr>
Subject: [Caml-list] A question about Format and semantic tags
Date: Wed, 23 Mar 2016 13:47:07 +0100	[thread overview]
Message-ID: <m237rhpdis.fsf@charm-ecran.irisa.fr> (raw)

[-- Attachment #1: Type: text/plain, Size: 1493 bytes --]

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

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-02, Mauna Loa Obs.): 404.02

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

             reply	other threads:[~2016-03-23 12:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 12:47 Alan Schmitt [this message]
2016-03-23 15:01 ` Benoit Vaugon
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=m237rhpdis.fsf@charm-ecran.irisa.fr \
    --to=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;
as well as URLs for NNTP newsgroup(s).