caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Pouillard" <nicolas.pouillard@inria.fr>
To: joelr1 <joelr1@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] camlp4: From AST to shortcuts
Date: Wed, 10 Oct 2007 14:36:50 +0200	[thread overview]
Message-ID: <1192019175-sup-5153@port-ext2.ensta.fr> (raw)
In-Reply-To: <97183C23-C2CB-4915-B406-798B8ABB0E0D@gmail.com>

Excerpts from joelr1's message of Tue Oct 09 23:41:14 +0200 2007:
> Suppose I'm debugging a camlp4 extension and get the following AST
> 
> Ast.TyId (_loc, Ast.IdLid (_loc, "int"))
>
> what's the best way of figuring out that this correspods to this bit?
> 
> <:ctyp< int >>

With the pretty printer.

It starts like the last time.

$ rlwrap ocaml camlp4of.cma                                                                                                                                                                                                               
open Camlp4.PreCast;;                                                                                                                                                                                                                     
module PP = Camlp4.Printers.OCaml.Make(Syntax);;                                                                                                                                                                                          
let pp = new PP.printer ();;                                                                                                                                                                                                              
let ghost = Loc.ghost;;                                                                                                                                                                                                                   
module PP = Camlp4.Printers.OCaml.Make(Syntax);;                                                                                                                                                                                          

let _loc = ghost;;
Format.eprintf "<:ctyp< %a >>@." pp#ctyp (Ast.TyId (_loc, Ast.IdLid (_loc, "int")));;

> Do I grep the sources and if so what files?

In  fact you should look at the wiki first especially the Abstract_Syntax_Tree
[3]  page.  The  wiki  also  states about "Relevant Source Files" [2]. In this
case the most relevant file is Camlp4Ast.partial.ml [1].

[1]: http://camlcvs.inria.fr/cgi-bin/cvsweb/ocaml/camlp4/Camlp4/Camlp4Ast.partial.ml?rev=1.3;content-type=text%2Fplain
[2]: http://brion.inria.fr/gallium/index.php/Relevant_Source_Files
[3]: http://brion.inria.fr/gallium/index.php/Abstract_Syntax_Tree

> This is a rather simple example but I'm trying to teach myself to  
> fish. Ultimately, I want to add initializer code and fields to the  
> AST resulting from a class declaration.

See my other mail about class initializer.

Good fishing...
-- 
Nicolas Pouillard aka Ertai


  reply	other threads:[~2007-10-10 12:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-09 21:41 Joel Reymont
2007-10-10 12:36 ` Nicolas Pouillard [this message]
2007-10-10 13:00   ` [Caml-list] " Joel Reymont
2007-10-11 13:05     ` Nicolas Pouillard

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=1192019175-sup-5153@port-ext2.ensta.fr \
    --to=nicolas.pouillard@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=joelr1@gmail.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).