caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Equivalent of Quotation.ExStr in new camlp4?
@ 2007-07-24 21:23 Harrison, John R
  2007-07-25 11:40 ` [Caml-list] " Gabriel Kerneis
  2007-07-25 16:14 ` Nicolas Pouillard
  0 siblings, 2 replies; 9+ messages in thread
From: Harrison, John R @ 2007-07-24 21:23 UTC (permalink / raw)
  To: caml-list; +Cc: Harrison, John R

[-- Attachment #1: Type: text/plain, Size: 279 bytes --]

In the old camlp4 one could set up a quotation parser to just apply a
string

transformation and thereafter parse with the usual OCaml parser, e.g.

 

  Quotation.add name (Quotation.ExStr expander)

 

What is the equivalent in the new camlp4?

 

John.

 


[-- Attachment #2: Type: text/html, Size: 2375 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
  2007-07-24 21:23 Equivalent of Quotation.ExStr in new camlp4? Harrison, John R
@ 2007-07-25 11:40 ` Gabriel Kerneis
  2007-07-25 16:14   ` Harrison, John R
  2007-07-25 16:14 ` Nicolas Pouillard
  1 sibling, 1 reply; 9+ messages in thread
From: Gabriel Kerneis @ 2007-07-25 11:40 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 598 bytes --]

Le Tue, 24 Jul 2007 14:23:34 -0700, "Harrison, John R"
<john.r.harrison@intel.com> a écrit :
> In the old camlp4 one could set up a quotation parser to just apply a
> string
> transformation and thereafter parse with the usual OCaml parser, e.g.
>   Quotation.add name (Quotation.ExStr expander)
> What is the equivalent in the new camlp4?

In Ocsigen,
Quotation.add "xml" (Quotation.ExAst (xml_exp, xml_pat))
became
open Camlp4.PreCast ;
Syntax.Quotation.add "xml" Syntax.Quotation.DynAst.expr_tag
Parser.xml_exp

Maybe this can give you a clue ?

Regards,
-- 
Gabriel Kerneis

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
  2007-07-24 21:23 Equivalent of Quotation.ExStr in new camlp4? Harrison, John R
  2007-07-25 11:40 ` [Caml-list] " Gabriel Kerneis
@ 2007-07-25 16:14 ` Nicolas Pouillard
  2007-07-25 16:23   ` Harrison, John R
  1 sibling, 1 reply; 9+ messages in thread
From: Nicolas Pouillard @ 2007-07-25 16:14 UTC (permalink / raw)
  To: Harrison, John R; +Cc: caml-list

Hello,

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.

Regards,

On 7/24/07, Harrison, John R <john.r.harrison@intel.com> wrote:
>
>
>
>
> In the old camlp4 one could set up a quotation parser to just apply a string
>
> transformation and thereafter parse with the usual OCaml parser, e.g.
>
>
>
>   Quotation.add name (Quotation.ExStr expander)
>
>
>
> What is the equivalent in the new camlp4?
>
>
>
> John.
>
-- 
Nicolas Pouillard


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
  2007-07-25 11:40 ` [Caml-list] " Gabriel Kerneis
@ 2007-07-25 16:14   ` Harrison, John R
  0 siblings, 0 replies; 9+ messages in thread
From: Harrison, John R @ 2007-07-25 16:14 UTC (permalink / raw)
  To: Gabriel Kerneis, caml-list; +Cc: Harrison, John R

| In Ocsigen,
| Quotation.add "xml" (Quotation.ExAst (xml_exp, xml_pat))
| became
| open Camlp4.PreCast ;
| Syntax.Quotation.add "xml" Syntax.Quotation.DynAst.expr_tag
| Parser.xml_exp
| 
| Maybe this can give you a clue ?

Maybe, but I was looking for the equivalent of Quotation.ExStr
rather than Quotation.ExAst, i.e. apply a string transform then
the usual OCaml parser rather than my own parser producing an
AST.

John.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
  2007-07-25 16:14 ` Nicolas Pouillard
@ 2007-07-25 16:23   ` Harrison, John R
  2007-07-26  8:44     ` Nicolas Pouillard
  0 siblings, 1 reply; 9+ messages in thread
From: Harrison, John R @ 2007-07-25 16:23 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list

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

John.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
  2007-07-25 16:23   ` Harrison, John R
@ 2007-07-26  8:44     ` Nicolas Pouillard
  2007-07-26 16:49       ` Harrison, John R
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Pouillard @ 2007-07-26  8:44 UTC (permalink / raw)
  To: Harrison, John R; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
  2007-07-26  8:44     ` Nicolas Pouillard
@ 2007-07-26 16:49       ` Harrison, John R
  2007-08-09 18:31         ` Nicolas Pouillard
  0 siblings, 1 reply; 9+ messages in thread
From: Harrison, John R @ 2007-07-26 16:49 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
  2007-07-26 16:49       ` Harrison, John R
@ 2007-08-09 18:31         ` Nicolas Pouillard
  2007-08-22 16:21           ` Harrison, John R
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Pouillard @ 2007-08-09 18:31 UTC (permalink / raw)
  To: Harrison John R; +Cc: O'Caml Mailing List

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [Caml-list] Equivalent of Quotation.ExStr in new camlp4?
  2007-08-09 18:31         ` Nicolas Pouillard
@ 2007-08-22 16:21           ` Harrison, John R
  0 siblings, 0 replies; 9+ messages in thread
From: Harrison, John R @ 2007-08-22 16:21 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: O'Caml Mailing List

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-08-22 18:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-24 21:23 Equivalent of Quotation.ExStr in new camlp4? 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
2007-08-09 18:31         ` Nicolas Pouillard
2007-08-22 16:21           ` Harrison, John R

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).