On 3/30/07, Hugo Ferreira <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Nicolas Pouillard wrote:
> > On 3/30/07, Hugo Ferreira <[EMAIL PROTECTED]> wrote:
> >> Hello Nicolas,
> >>
> >> Nicolas Pouillard wrote:
> >> snip..
> >>>> let _ = Logic.print term in
> >>>> ...
> >>>> and I would like to change that to:
> >>>>
> >>>> let _ = Logic.print env term in
> >>>> ...
> >>>> where env is declared by the extension.
> >>>>
> >>>> Looking at the Pcaml module I would say I am after a Pcaml.expr (Because
> >>>> at first I thought we have a "let" label here, so this should be it).
> >>>>
> >>>> | "expr1" LEFTA
> >>>> ...
> >>>>    | "let"; OPT "rec"; LIST1 let_binding SEP "and"; "in"; expr LEVEL 
> >>>> "top"
> >>> Please don't do this. Not that way...
> >>>
> >>> You should traverse the AST and then substitute function calls.
> >>>
> >> Hmm.. I seem to understand less that I imagined about camlp4 (old
> >> version). The only solution I found was:
> >>
> >>    Pcaml.expr: LEVEL "apply"   [
> >>      [ e1 = LIDENT; e2 = SELF -> subst_func loc e1 e2
> >>       |  OPT UIDENT ; "." ; e1 = LIDENT; e2 = SELF -> subst_func loc e1 e2 
> >> ]
> >>    ];
> >>
> >> where "subst_func loc e1 e2" simply checks for "e1 = print". (Still need
> >> to work on "OPT UIDENT ; ." to accept only the "Logical" module though.)
> >> Is this what you mean by traversing the AST?
> >
> > No, here you are extending the language to treat differently
> > something. Some times that's simple enough to be acceptable but
> > overriding the application rule is not a good idea.
> >
>
> Ok. I think I get it. What you saying is: don't substitute the
> parsing/lexing rules themselves, instead match directly against
> the AST that is provided by the parsed/lexer and then substitute
> those elements.

Yes

> >>> In the new camlp4 one can do that easily with filters:
> >>>
> >>> open Camlp4.PreCast;;
> >>> AstFilters.register_str_item_filter begin
> >>>   Ast.map_expr begin function
> >>>   | <:[EMAIL PROTECTED]< Logic.print $e$ >> -> <:[EMAIL PROTECTED]< 
> >>> Logic.print env $e$ >>
> >>>   | e -> e
> >>>   end
> >>> end#str_item;;
> >>>
> >> Interesting. Is this all that is needed?
> > Yes
> >
> >> Doesn't one require an EXTEND?
> > That's my point.
> >
>
> In other words, the parsing/lexing rules are the same. You "just"
> provide a means to find that part of the AST we are interested in
> and change that. Which is really what we want.
>
> I guess then the philosophy behind the old camlp4 and the new one has
> changed somewhat. I suspect porting the code may require quite a bit of
> change.

I added filtering/transformation feature to camlp4 so some old things
can be done more easily. The parsing philosophy is quite the same.

[...]

> > It depends (but it worths its).
>
> I will wait for 3.10's availability eagerly.

Ok.

-- 
Nicolas Pouillard

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html
-~----------~----~----~----~------~----~------~--~---

Reply via email to