From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "Harrison, John R" <john.r.harrison@intel.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
Date: Thu, 26 Jul 2007 10:44:04 +0200 [thread overview]
Message-ID: <cd67f63a0707260144h2d0cad58h281781be452df391@mail.gmail.com> (raw)
In-Reply-To: <509223F0BF55E74FA1247D17207E7A0C01B120CA@orsmsx419.amr.corp.intel.com>
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
next prev parent reply other threads:[~2007-07-26 8:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-24 21:23 Harrison, John R
2007-07-25 11:40 ` [Caml-list] " Gabriel Kerneis
2007-07-25 16:14 ` Harrison, John R
2007-07-25 16:14 ` Nicolas Pouillard
2007-07-25 16:23 ` Harrison, John R
2007-07-26 8:44 ` Nicolas Pouillard [this message]
2007-07-26 16:49 ` Harrison, John R
2007-08-09 18:31 ` Nicolas Pouillard
2007-08-22 16:21 ` Harrison, John R
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cd67f63a0707260144h2d0cad58h281781be452df391@mail.gmail.com \
--to=nicolas.pouillard@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=john.r.harrison@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox