caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: jehenrik <jehenrik@yahoo.com>
To: yann@lrde.epita.fr
Cc: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] camlp4: pretty printing not to a file
Date: Fri, 6 Sep 2002 12:35:59 -0400	[thread overview]
Message-ID: <B95508D1-C1B6-11D6-9EB4-00039375801A@yahoo.com> (raw)
In-Reply-To: <20020906090909.GA400@barcelona.lrde.epita.fr>

> 	Something like:
>
> "PCaml.string_of_X : X -> string" where X is in { expr, patt, ctyp ... }
>
> 	could be simple and useful. It can be the application of this
> function with a default format configuration structure:
>
> "PCaml.string_of_X_formatted : format_config -> X -> string"

It seems like the Format module provides for whatever "format_config" 
would be, no?  For example, I changed your code to the following, which 
does not require global variables:

(** our printer *)
let printer pr x =
   let b = Buffer.create 1024 in
   let f = Format.formatter_of_buffer b in
   Spretty.print_pretty (Format.pp_print_char f) (Format.pp_print_string 
f)
     (Format.pp_print_flush f) "" "" 78
     (fun (_,_) -> ())  (pr.pr_fun "top" x "" [<>]);
   Format.pp_print_flush f ();
   Buffer.contents b;;

No worrying about redirecting other formatters necessary.  And the 
Format.pp_set_all_formatter_output_functions function seems to provide 
what you would need in terms of "formatting options," at least what I 
can think of.  So maybe camlp4 just needs a function:

PCaml.make_formatted_printer : (unit -> Format.formatter) -> 'a 
Grammar.Entry.e -> 'a -> string

The thunk is so that optionally a fresh buffer can be allocated each 
time.  And then a convenience function with a normal "make buffer, 
print, dump string" thing plugged in:

PCaml.print_to_string : 'a Grammar.Entry.e -> 'a -> string


Jeff


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2002-09-06 16:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-29 18:51 jehenrik
2002-08-30  7:46 ` Yann Régis-Gianas
2002-08-30  8:34   ` Daniel de Rauglaudre
2002-09-05 16:29   ` jehenrik
2002-09-06  1:36     ` Daniel de Rauglaudre
2002-09-06  9:09       ` Yann Régis-Gianas
2002-09-06 12:29         ` Daniel de Rauglaudre
2002-09-06 16:35         ` jehenrik [this message]
2002-09-06 17:13           ` Daniel de Rauglaudre
2002-09-06 16:45         ` jehenrik
2002-08-30  8:21 ` 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=B95508D1-C1B6-11D6-9EB4-00039375801A@yahoo.com \
    --to=jehenrik@yahoo.com \
    --cc=caml-list@inria.fr \
    --cc=daniel.de_rauglaudre@inria.fr \
    --cc=yann@lrde.epita.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).