* camlp4: From AST to shortcuts
@ 2007-10-09 21:41 Joel Reymont
2007-10-10 12:36 ` [Caml-list] " Nicolas Pouillard
0 siblings, 1 reply; 4+ messages in thread
From: Joel Reymont @ 2007-10-09 21:41 UTC (permalink / raw)
To: Caml List
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 >>
Do I grep the sources and if so what files?
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.
Thanks, Joel
--
http://wagerlabs.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] camlp4: From AST to shortcuts
2007-10-09 21:41 camlp4: From AST to shortcuts Joel Reymont
@ 2007-10-10 12:36 ` Nicolas Pouillard
2007-10-10 13:00 ` Joel Reymont
0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Pouillard @ 2007-10-10 12:36 UTC (permalink / raw)
To: joelr1; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] camlp4: From AST to shortcuts
2007-10-10 12:36 ` [Caml-list] " Nicolas Pouillard
@ 2007-10-10 13:00 ` Joel Reymont
2007-10-11 13:05 ` Nicolas Pouillard
0 siblings, 1 reply; 4+ messages in thread
From: Joel Reymont @ 2007-10-10 13:00 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: caml-list
On Oct 10, 2007, at 1:36 PM, Nicolas Pouillard wrote:
> With the pretty printer.
> ...
> let _loc = ghost;;
> Format.eprintf "<:ctyp< %a >>@." pp#ctyp (Ast.TyId (_loc, Ast.IdLid
> (_loc, "int")));;
That doesn't quite work since I have to know to use a ctyp. I was
wondering if there was a way to figure out the shortcut without
knowing about ctyp beforehand.
Then again, I looked at Camlp4/Camlp4Ast.partial.ml and, conveniently
enough, TyId is located under ctyp whereas CrIn (class initializer;
what's the "r" in Cr?) is under class_str_item.
Can it be THAT simple?
Thanks, Joel
--
http://wagerlabs.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] camlp4: From AST to shortcuts
2007-10-10 13:00 ` Joel Reymont
@ 2007-10-11 13:05 ` Nicolas Pouillard
0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Pouillard @ 2007-10-11 13:05 UTC (permalink / raw)
To: joelr1; +Cc: caml-list
Excerpts from joelr1's message of Wed Oct 10 15:00:54 +0200 2007:
>
> On Oct 10, 2007, at 1:36 PM, Nicolas Pouillard wrote:
>
> > With the pretty printer.
> > ...
> > let _loc = ghost;;
> > Format.eprintf "<:ctyp< %a >>@." pp#ctyp (Ast.TyId (_loc, Ast.IdLid
> > (_loc, "int")));;
>
> That doesn't quite work since I have to know to use a ctyp. I was
> wondering if there was a way to figure out the shortcut without
> knowing about ctyp beforehand.
>
> Then again, I looked at Camlp4/Camlp4Ast.partial.ml and, conveniently
> enough, TyId is located under ctyp whereas CrIn (class initializer;
> what's the "r" in Cr?) is under class_str_item.
>
> Can it be THAT simple?
Of course! The convention for quotations given by camlp4 is
<:type_name<...>>, <:expr<...>> is for Ast.expr, <:class_str_item<...>> is
for Ast.class_str_item...
--
Nicolas Pouillard aka Ertai
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-10-11 13:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-09 21:41 camlp4: From AST to shortcuts Joel Reymont
2007-10-10 12:36 ` [Caml-list] " Nicolas Pouillard
2007-10-10 13:00 ` Joel Reymont
2007-10-11 13:05 ` Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox