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: jehenrik <jehenrik@y...>
Subject: Re: [Caml-list] camlp4: pretty printing not to a file
Thanks for the response, this seems to be what I am looking for, but the 
code snippet you sent does not work for me.  I'm running ocaml+camlp4 
3.04, and did not get anything working or comprehensible with my limited 
knowledge of the camlp4 code base.  I had to edit a couple of 
expressions to get things to type check, that may be the source of 
problems.  But could you verify it please?  The behavior now is:

(** printer for ocaml expr *)
let print_expr2 = printer pr_expr;;

let r = Grammar.Entry.parse expr (Stream.of_string
       "let foo = x + 2 in foo * foo");;

print_expr2 r;;

<pr_fun: not impl: expr; tag = 14>- : string = ""
^^^ this stuff comes out on stderr, I think.  Either that or stdout.

The code with my changes is:


(** 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 (_,_) -> ())  (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_expr2 = printer pr_expr;;

(** printer for ocaml pattern *)
let print_patt = printer pr_patt;;


Your help is much appreciated.  Thanks.


Jeff Henrikson



-------------------
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