caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Harrison, John R" <john.r.harrison@intel.com>
To: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
Cc: <caml-list@yquem.inria.fr>
Subject: RE: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
Date: Thu, 26 Jul 2007 09:49:19 -0700	[thread overview]
Message-ID: <509223F0BF55E74FA1247D17207E7A0C01B12606@orsmsx419.amr.corp.intel.com> (raw)
In-Reply-To: <cd67f63a0707260144h2d0cad58h281781be452df391@mail.gmail.com>

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


  reply	other threads:[~2007-07-26 16:49 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
2007-07-26 16:49       ` Harrison, John R [this message]
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=509223F0BF55E74FA1247D17207E7A0C01B12606@orsmsx419.amr.corp.intel.com \
    --to=john.r.harrison@intel.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=nicolas.pouillard@gmail.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;
as well as URLs for NNTP newsgroup(s).