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 JAA30510; Fri, 30 Aug 2002 09:29:23 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA30365 for ; Fri, 30 Aug 2002 09:29:22 +0200 (MET DST) Received: from colt.epita.fr (colt.epita.fr [62.23.180.27]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7U7TLD05001 for ; Fri, 30 Aug 2002 09:29:21 +0200 (MET DST) Received: from hermes.epita.fr (hermes.epita.fr [163.5.255.10]) by colt.epita.fr id g7U7R9p26308 Fri, 30 Aug 2002 09:27:09 +0200 (MEST) Received: from goa.lrde.epita.fr (mail@goa.lrde.epita.fr [10.223.13.2]) by hermes.epita.fr id g7U7R9A10788 Fri, 30 Aug 2002 09:27:09 +0200 (MEST) Received: from barcelona.lrde.epita.fr ([10.223.13.32] ident=mail) by goa.lrde.epita.fr with esmtp (Exim 3.35 #1 (Debian)) id 17kgJz-0005Dk-00; Fri, 30 Aug 2002 09:35:59 +0200 Received: from yann by barcelona.lrde.epita.fr with local (Exim 3.33 #1 (Debian)) id 17kgU9-0001xV-00; Fri, 30 Aug 2002 09:46:29 +0200 Date: Fri, 30 Aug 2002 09:46:29 +0200 To: jehenrik Cc: caml-list@inria.fr Subject: Re: [Caml-list] camlp4: pretty printing not to a file Message-ID: <20020830074629.GA4422@barcelona.lrde.epita.fr> Reply-To: yann@lrde.epita.fr References: <5B049D08-BB80-11D6-9EB3-00039375801A@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5B049D08-BB80-11D6-9EB3-00039375801A@yahoo.com> User-Agent: Mutt/1.3.25i From: =?iso-8859-1?Q?Yann_R=E9gis-Gianas?= Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, Aug 29, 2002 at 02:51:41PM -0400, jehenrik wrote: > Hi, I want a camlp4 macro which takes a caml expression for a list and > replaces it by a list of (source code as string, value) tuples. I have > two problems: printing not to a file, and pattern matching the list. It > seems that the good camlp4 pretty printing facilities are only able to > go to files, Yes. The first time I tried to print AST with camlp4, I thought that camlp4 should be called camlp2 ... In fact, it is due to the poor documentation about printers. It is possible to print AST in something different from file using global variables. Look: (** global buffer. *) let b = Buffer.create 1024 (** our printer *) let printer pr x = Buffer.clear b; Spretty.print_pretty Format.print_char Format.print_string Format.print_flush "" "" 78 (fun _ _ -> ("", 0, 0, 0)) 0 (pr.pr_fun "top" x "" [<>]); Format.print_flush (); Buffer.contents b (** initialize the pretty printer output. *) let init_printer () = let _ = Buffer.clear b in let null () = () and bufferize s start len = Buffer.add_substring b s start len; in Format.set_formatter_output_functions bufferize null (** printer for ocaml types *) let print_ctyp = printer pr_ctyp (** printer for ocaml expr *) let print_expr = printer pr_expr (** printer for ocaml pattern *) let print_patt = printer pr_patt -- Yann Régis-Gianas. ------------------- 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