caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Yann Régis-Gianas" <yann@lrde.epita.fr>
To: jehenrik <jehenrik@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] camlp4: pretty printing not to a file
Date: Fri, 30 Aug 2002 09:46:29 +0200	[thread overview]
Message-ID: <20020830074629.GA4422@barcelona.lrde.epita.fr> (raw)
In-Reply-To: <5B049D08-BB80-11D6-9EB3-00039375801A@yahoo.com>

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


  reply	other threads:[~2002-08-30  7:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-29 18:51 jehenrik
2002-08-30  7:46 ` Yann Régis-Gianas [this message]
2002-08-30  8:34   ` Daniel de Rauglaudre
2002-09-05 16:29   ` jehenrik
2002-09-06  1:36     ` Daniel de Rauglaudre
2002-09-06  9:09       ` Yann Régis-Gianas
2002-09-06 12:29         ` Daniel de Rauglaudre
2002-09-06 16:35         ` jehenrik
2002-09-06 17:13           ` Daniel de Rauglaudre
2002-09-06 16:45         ` jehenrik
2002-08-30  8:21 ` Daniel de Rauglaudre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020830074629.GA4422@barcelona.lrde.epita.fr \
    --to=yann@lrde.epita.fr \
    --cc=caml-list@inria.fr \
    --cc=jehenrik@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).