Browse thread
Equivalent of Quotation.ExStr in new camlp4?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2007-07-26 (16:49) |
From: | Harrison, John R <john.r.harrison@i...> |
Subject: | RE: [Caml-list] Equivalent of Quotation.ExStr in new camlp4? |
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