caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Nicolas Ojeda Bar <nojb@math.harvard.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] pretty-printing with camlp4?
Date: Sun, 8 Jul 2012 17:02:11 +0200	[thread overview]
Message-ID: <CAPFanBFiPqoJySufhoEcTEu6ifaq5UMd8wG2NpmxrWX++evVrg@mail.gmail.com> (raw)
In-Reply-To: <1652E741-8D61-4AFB-BB94-57FD60915BE4@math.harvard.edu>

As far as I know, no such facility exists in Camlp4.

Note however that there is quite a difference between parsers and
printers. Supporting extensible parsing is very difficult, because
parsing is quite a complex process. On the contrary, "printers" as
presented here or as implemented in Camlp4 are more like regular tree
traversals, calling a pretty-printing library that takes care of the
visual formatting aspects. An "extensible printer" can therefore be
summarized as an extensible tree traversal, something that is not too
difficult to achieve with a decent software architecture; for example
Camlp4's MapGenerator framework.

If you don't need the "extensible" parts of Camlp5 printer's support,
because your datatype to print is fixed, you can use the
pretty-printing library directly. Camlp4 uses the Format module of the
standard library, but I personally found it to be a bit painful to
use, and have a preference for the Pprint library of François Pottier:
  http://gallium.inria.fr/~fpottier/pprint/pprint.tar.gz

(There are other pretty-printing libraries for OCaml that I haven't
tried, such as Martin Jambon's easy-format:
http://mjambon.com/easy-format.html )

My advice would be to use one of those pretty-printing libraries, to
see if it fits your bill, or if you really need another abstraction
layer such as Camlp5 printers.
(Of course you can also use Camlp5 directly if it solves you problem.)

On Sun, Jul 8, 2012 at 4:34 PM, Nicolas Ojeda Bar <nojb@math.harvard.edu> wrote:
> Hi,
>
> Is it possible to use Camlp4 to write pretty printers of arbitrary
> data? The signature Camlp4.Sig.Printer seems to indicate the pretty
> printing facility only works with OCaml ASTs...
>
> On the other hand, with Camlp5 it is possible to write pretty
> printers for arbitrary ASTs
> (see <http://pauillac.inria.fr/~ddr/camlp5/doc/html/printers.html>),
> so I imagine there must be a way to do the same thing with Camlp4...
>
> Thanks!
> Nicolas
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

  reply	other threads:[~2012-07-08 15:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-08 14:34 Nicolas Ojeda Bar
2012-07-08 15:02 ` Gabriel Scherer [this message]
2012-07-08 17:09 Daniel de Rauglaudre

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=CAPFanBFiPqoJySufhoEcTEu6ifaq5UMd8wG2NpmxrWX++evVrg@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=nojb@math.harvard.edu \
    /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).