Version française
Home     About     Download     Resources     Contact us    
Browse thread
Equivalent of Quotation.ExStr in new camlp4?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Harrison, John R <john.r.harrison@i...>
Subject: RE: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
Thanks; unfortunately in the gap between your two messages I really
needed
to get my code running, so I just took the path of least resistance and
switched to camlp5. But I'll re-examine this in the future when I have
more
time.

John.

-----Original Message-----
From: Nicolas Pouillard [mailto:nicolas.pouillard@gmail.com] 
Sent: Thursday, August 09, 2007 11:31 AM
To: Harrison, John R
Cc: O'Caml Mailing List
Subject: RE: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?

Sorry, I used ocamlbuild to use this example and show it without ;(

I forgot -I +camlp4/Camlp4Parsers

Excerpts from Harrison, John R's message of Thu Jul 26 18:49:19 +0200
2007:
> Trying your example in 3.10.0, I get the following:
> 
> | $ ocamlc -pp camlp4of -I +camlp4 -c ex_str.ml
> | File "ex_str.ml", line 2, characters 2-24:
> | Unbound module Camlp4OCamlParser.Make
> 
> I get a similar error in the toplevel even after #load "camlp4o.cma".
> Do I need to load and/or open something else?
> 
> John.
> 
> -----Original Message-----
> From: Nicolas Pouillard [mailto:nicolas.pouillard@gmail.com] 
> Sent: Thursday, July 26, 2007 1:44 AM
> To: Harrison, John R
> Cc: caml-list@yquem.inria.fr
> Subject: Re: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
> 
> On 7/25/07, Harrison, John R <john.r.harrison@intel.com> wrote:
> > | No ExStr is no more supported. But you can do it your self by
> calling
> > | the parser on your string if you really don't want switch to an
AST
> > | based quotation expander.
> >
> > OK, that's fine. But how do I do that? Concretely, this is what I
had
> > before, so what should I have now?
> >
> >   Quotation.add "" (Quotation.ExStr (fun x -> quotexpander));;
> >
> > I don't mind in principle writing an AST-producing expander, but at
> the
> > moment the priority is to get my code working in 3.10 with minimal
> > expenditure of effort.
> >
> 
> You can instanciate an OCaml parser that way:
> 
> $ cat ex_str.mlmodule Caml =
>   Camlp4OCamlParser.Make
>     (Camlp4OCamlRevisedParser.Make
>       (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation)));;
> 
> let quotexpander str =
>   "[1; 2; 3]" (* ... do some real code on str *)
> 
> let patt_quotexpander loc _loc_name_opt str =
>   Gram.parse_string Caml.patt loc (quotexpander str)
> 
> let expr_quotexpander loc _loc_name_opt str =
>   Gram.parse_string Caml.expr loc (quotexpander str)
> 
> let str_item_quotexpander loc loc_name_opt str =
>   <:str_item@loc< $exp: expr_quotexpander loc loc_name_opt str$ >>
> 
> let () =
>   Syntax.Quotation.add "" Syntax.Quotation.DynAst.expr_tag
> expr_quotexpander;
>   Syntax.Quotation.add "" Syntax.Quotation.DynAst.str_item_tag
> str_item_quotexpander;
>   Syntax.Quotation.add "" Syntax.Quotation.DynAst.patt_tag
> patt_quotexpander
> 
> $ ocamlc -pp camlp4of -I +camlp4 -c ex_str.ml
> $ camlp4o ./ex_str.cmo -str '<<>>;;'
> 
> HTH
> 
> -- 
> Nicolas Pouillard

-- 
Nicolas Pouillard aka Ertai