caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "Benedikt Grundmann" <benedikt@cardexpert.net>
Cc: Caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] problem with camlp4
Date: Tue, 3 Jul 2007 10:16:43 +0200	[thread overview]
Message-ID: <cd67f63a0707030116n2543f02cqeb83c87dcdc54a8e@mail.gmail.com> (raw)
In-Reply-To: <9b415f950707021504q6bad7f65o3adde4cdafea97d5@mail.gmail.com>

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


      parent reply	other threads:[~2007-07-03  8:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-02 22:04 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 message]

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=cd67f63a0707030116n2543f02cqeb83c87dcdc54a8e@mail.gmail.com \
    --to=nicolas.pouillard@gmail.com \
    --cc=benedikt@cardexpert.net \
    --cc=caml-list@inria.fr \
    /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).