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 OAA03903; Fri, 6 Sep 2002 14:29:25 +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 OAA03935 for ; Fri, 6 Sep 2002 14:29:25 +0200 (MET DST) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g86CTO126260 for ; Fri, 6 Sep 2002 14:29:24 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id OAA11757 for caml-list@inria.fr; Fri, 6 Sep 2002 14:29:24 +0200 Date: Fri, 6 Sep 2002 14:29:24 +0200 From: Daniel de Rauglaudre To: caml-list@inria.fr Subject: Re: [Caml-list] camlp4: pretty printing not to a file Message-ID: <20020906142924.B27346@verdot.inria.fr> References: <20020830074629.GA4422@barcelona.lrde.epita.fr> <20020906033628.A26991@verdot.inria.fr> <20020906090909.GA400@barcelona.lrde.epita.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.2.5i In-Reply-To: <20020906090909.GA400@barcelona.lrde.epita.fr>; from yann@lrde.epita.fr on Fri, Sep 06, 2002 at 11:09:09AM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Fri, Sep 06, 2002 at 11:09:09AM +0200, Yann Régis-Gianas wrote: > "PCaml.string_of_X : X -> string" where X is in { expr, patt, ctyp ... } Ok, this is implemented and committed in Camlp4 CVS directory. I added a new function "Pcaml.string_of" of type: 'a printer_t -> 'a -> string You can use it with Pcaml.pr_expr, Pcaml.pr_patt, and so on. Example, pretty printing in normal syntax by loading pr_o.cmo: $ ocaml camlp4o.cma pr_o.cmo q_MLast.cmo Objective Caml version 3.06 Camlp4s Parsing version 3.06 # let loc = 0, 0;; val loc : int * int = (0, 0) # Pcaml.string_of Pcaml.pr_sig_item <:sig_item< value x : int >>;; - : string = "val x : int" # Pcaml.string_of Pcaml.pr_str_item <:str_item< value x = 3 >>;; - : string = "let x = 3" # Pcaml.string_of Pcaml.pr_module_type <:module_type< sig value x : int; end >>;; - : string = "sig val x : int end" # Pcaml.string_of Pcaml.pr_module_expr <:module_expr< struct value x = 3; end >>;; - : string = "struct let x = 3 end" # Pcaml.string_of Pcaml.pr_expr <:expr< let x = 3 in x + 2 >>;; - : string = "let x = 3 in x + 2" # Pcaml.string_of Pcaml.pr_patt <:patt< ([x; y; z :: t], 5) >>;; - : string = "x :: y :: z :: t, 5" # Pcaml.string_of Pcaml.pr_ctyp <:ctyp< list (list (int * string)) >>;; - : string = "(int * string) list list" # Pcaml.string_of Pcaml.pr_class_sig_item <:class_sig_item< method virtual foo : bar >>;; - : string = "method virtual foo : bar" # Pcaml.string_of Pcaml.pr_class_str_item <:class_str_item< method private foo = 3 >>;; - : string = "method private foo = 3" # Pcaml.string_of Pcaml.pr_class_type <:class_type< [ a ] -> [ b ] -> object method foo : bar; end >>;; - : string = "a -> b -> object method foo : bar end" # Pcaml.string_of Pcaml.pr_class_expr <:class_expr< object value foo = 3; method foo = bar; end >>;; - : string = "object val foo = 3 method foo = bar end" Hope this helps, comme on dit dans ce cas-là. -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- 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