Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] camlp4: pretty printing not to a file
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] camlp4: pretty printing not to a file
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