From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA09897; Fri, 6 Sep 2002 18:33:39 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA10079 for ; Fri, 6 Sep 2002 18:33:38 +0200 (MET DST) Received: from c007.snv.cp.net (h015.c007.snv.cp.net [209.228.33.243]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id g86GXb108952 for ; Fri, 6 Sep 2002 18:33:37 +0200 (MET DST) Received: (cpmta 5810 invoked from network); 6 Sep 2002 09:33:35 -0700 Received: from 65.187.194.217 (HELO localhost) by smtp.directvinternet.com (209.228.33.243) with SMTP; 6 Sep 2002 09:33:35 -0700 X-Sent: 6 Sep 2002 16:33:35 GMT Date: Fri, 6 Sep 2002 12:35:59 -0400 Subject: Re: [Caml-list] camlp4: pretty printing not to a file Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v482) Cc: Daniel de Rauglaudre , caml-list@inria.fr To: yann@lrde.epita.fr From: jehenrik In-Reply-To: <20020906090909.GA400@barcelona.lrde.epita.fr> Message-Id: Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.482) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > 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