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?

> 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? Doesn't one require an EXTEND?
Note that I am stuck with 3.09.3 and the previous version of ocamlp4. 
Now I wonder how much work will be required to port my stuff to the new 
version.

Venting: Is it just me or is an IQ above 180 required for working with 
camlp4 (and certain Ocaml constructs). Took the whole morning to find 
the solution above!

Thanks for the help. Appreciate it.
Hugo F.


> Cheers,
> 


--~--~---------~--~----~------------~-------~--~----~
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