Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
camlp4: From AST to shortcuts
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-10-10 (12:37)
From: Nicolas Pouillard <nicolas.pouillard@i...>
Subject: Re: [Caml-list] camlp4: From AST to shortcuts
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 [1].


> 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