* problem with camlp4
@ 2007-07-02 22:04 Benedikt Grundmann
2007-07-02 22:14 ` [Caml-list] " Jon Harrop
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Benedikt Grundmann @ 2007-07-02 22:04 UTC (permalink / raw)
To: Caml-list
Hi everybody,
I'm having a problem with a syntax extension I'm trying to write, the
smallest sample that I could come up with, that still shows the
problem is the following:
(*pp camlp4orf *)
open Camlp4.PreCast
let test _loc =
let num = 0 in
let acc = <:match_case<>> in
(*
<:match_case< true -> $expr:num$ | $acc$ >>
*)
<:match_case< true -> 0 | $acc$ >>
If I comment out the last line and instead enable the line above I get
this error:
ocamlc -c -pp "camlp4orf " -thread -g -I
/home/bene/godi/lib/ocaml/std-lib/camlp4 sample.ml
File "sample.ml", line 8, characters 23-25:
While expanding quotation "match_case" in a position of "expr":
Parse error: "->" expected after [opt_when_expr] (in [match_case0])
I'm sure I missed something obvious... Please help.
Thanks a lot,
Bene
--
Calvin: I try to make everyone's day a little more
surreal.
(From Calvin & Hobbes)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] problem with camlp4
2007-07-02 22:04 problem with camlp4 Benedikt Grundmann
@ 2007-07-02 22:14 ` Jon Harrop
2007-07-03 5:46 ` Bruno De Fraine
2007-07-03 8:16 ` Nicolas Pouillard
2 siblings, 0 replies; 5+ messages in thread
From: Jon Harrop @ 2007-07-02 22:14 UTC (permalink / raw)
To: caml-list
On Monday 02 July 2007 23:04:18 Benedikt Grundmann wrote:
> I'm sure I missed something obvious... Please help.
I think you need to antiquote a quoted expression:
open Camlp4.PreCast
let test _loc =
let acc = <:match_case<>> in
<:match_case< true -> $<:expr<0>>$ | $acc$ >>
What does match_case do?
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?e
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] problem with camlp4
2007-07-02 22:04 problem with camlp4 Benedikt Grundmann
2007-07-02 22:14 ` [Caml-list] " Jon Harrop
@ 2007-07-03 5:46 ` Bruno De Fraine
2007-07-03 7:05 ` Bruno De Fraine
2007-07-03 8:16 ` Nicolas Pouillard
2 siblings, 1 reply; 5+ messages in thread
From: Bruno De Fraine @ 2007-07-03 5:46 UTC (permalink / raw)
To: Benedikt Grundmann; +Cc: Caml-list
On 03 Jul 2007, at 00:04, Benedikt Grundmann wrote:
> <:match_case< true -> $expr:num$ | $acc$ >>
Do you mean this?
<:match_case< true -> $int:string_of_int num$ >>
Also notice that you can write
<:expr< match $e$ with [ $list:l$ ] >>
where l is of type "Camlp4.PreCast.Ast.match_case list".
This can be easier than folding the expression with an accumulator.
Regards,
Bruno
--
Bruno De Fraine
Vrije Universiteit Brussel
Faculty of Applied Sciences, DINF - SSEL
Room 4K208, Pleinlaan 2, B-1050 Brussels
tel: +32 (0)2 629 29 75
fax: +32 (0)2 629 28 70
e-mail: Bruno.De.Fraine@vub.ac.be
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] problem with camlp4
2007-07-03 5:46 ` Bruno De Fraine
@ 2007-07-03 7:05 ` Bruno De Fraine
0 siblings, 0 replies; 5+ messages in thread
From: Bruno De Fraine @ 2007-07-03 7:05 UTC (permalink / raw)
To: Caml-list ml; +Cc: Benedikt Grundmann
On 03 Jul 2007, at 07:46, I wrote:
> <:match_case< true -> $int:string_of_int num$ >>
Alain Frisch reminded me this can be shortened to
<:match_case< true -> $`int:num$ >>
with the new camlp4.
Regards,
Bruno
--
Bruno De Fraine
Vrije Universiteit Brussel
Faculty of Applied Sciences, DINF - SSEL
Room 4K208, Pleinlaan 2, B-1050 Brussels
tel: +32 (0)2 629 29 75
fax: +32 (0)2 629 28 70
e-mail: Bruno.De.Fraine@vub.ac.be
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] problem with camlp4
2007-07-02 22:04 problem with camlp4 Benedikt Grundmann
2007-07-02 22:14 ` [Caml-list] " Jon Harrop
2007-07-03 5:46 ` Bruno De Fraine
@ 2007-07-03 8:16 ` Nicolas Pouillard
2 siblings, 0 replies; 5+ messages in thread
From: Nicolas Pouillard @ 2007-07-03 8:16 UTC (permalink / raw)
To: Benedikt Grundmann; +Cc: Caml-list
On 7/3/07, Benedikt Grundmann <benedikt@cardexpert.net> wrote:
> Hi everybody,
>
> I'm having a problem with a syntax extension I'm trying to write, the
> smallest sample that I could come up with, that still shows the
> problem is the following:
>
> (*pp camlp4orf *)
>
> open Camlp4.PreCast
>
> let test _loc =
> let num = 0 in
> let acc = <:match_case<>> in
> (*
> <:match_case< true -> $expr:num$ | $acc$ >>
> *)
> <:match_case< true -> 0 | $acc$ >>
>
> If I comment out the last line and instead enable the line above I get
> this error:
>
> ocamlc -c -pp "camlp4orf " -thread -g -I
> /home/bene/godi/lib/ocaml/std-lib/camlp4 sample.ml
> File "sample.ml", line 8, characters 23-25:
> While expanding quotation "match_case" in a position of "expr":
> Parse error: "->" expected after [opt_when_expr] (in [match_case0])
First, "expr" in $expr:...$ is not a valid antiquotation name,
(perhaps it should be) but here you can use $exp:...$ or even just
$...$ since it's not ambiguous that after the "->" one waits an
expression.
Second, you try to put an integer right here.
You need to make a expression node for it (as told by other answers):
- A constant can be put directly: <:expr< 0 >>
- A string expression representing an integer can be put like that:
<:expr< $int:"0"$ >>
- An integer expression can be used with this sugar: <:expr< $`int:0$ >>
The last but not the least, in revised <:match_case< true -> 0 >> is
nothing more than <:match_case< _ -> 0 >>. Since the true constant is
spelled True with a capital T like any other data constructor.
Cheers,
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-07-03 8:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-02 22:04 problem with camlp4 Benedikt Grundmann
2007-07-02 22:14 ` [Caml-list] " Jon Harrop
2007-07-03 5:46 ` Bruno De Fraine
2007-07-03 7:05 ` Bruno De Fraine
2007-07-03 8:16 ` Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox