caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: blue storm <bluestorm.dylc@gmail.com>
To: Andre Nathan <andre@sneakymustard.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Camlp4 help
Date: Sat, 21 Mar 2009 18:24:30 +0100	[thread overview]
Message-ID: <527cf6bc0903211024n11ab84c2u940c8b64ad7f2582@mail.gmail.com> (raw)
In-Reply-To: <1237652076.6137.15.camel@homesick>

On 3/21/09, Andre Nathan <andre@sneakymustard.com> wrote:
> I think I understand, although I thought the "x = expr" rule in the sum
> form definition meant that before "plus" any expression would be
> allowed.

What you wanted is   let a = b in (a plus b). The expression is not
before plus, plus is inside the expression. Your rule means that
inside plus, the left member can be an expression (eg. (let a = b in
a) plus b).

> I want to allow any expression inside a "sum" block, which I think I
> could do by defining it as a new rule in "expr", but I'd like "plus"
> expressions to only be allowed inside a "sum" block, which I'm not sure
> how to do.

I see (but there may be a better choice) two solutions :
- create a new structure expression_inside_sum wich is a complete copy
of "expr" with sums added. This is ugly and redundant.
- use a "marker" trick in two pass :
   - in your grammar you "mark" plus nodes by translating them into a
specific AST node (wich cannot be produced by any usual camlp4
construct), for example "a plus b" -> <:expr< $id:"camlp4.plus"$ a b
>>
   - then you use an Ast.map or a Camlp4Filter to explore the
resulting AST, translating the marked nodes (the ones with
"camlp4.plus" as identifiers) into different things depending on
wether you're inside a sum-block or not (or possibly raising an error
outside a sum-block).

If you want an example, I used a similar trick in my "pa_holes"
extension : "\1"-like identifiers are allowed only inside a (\ ... )
block; at first they're allowed everywhere (the "ident" rule is
changed), then they're transformed into a valid camlp4 construction
inside the (\ ... ) blocks ("expr" rule), and finally the AST is
explored and any remaining \n raise an error (Remove_holes filter).

This solution is also ugly, but has little redudancy.


  reply	other threads:[~2009-03-21 17:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-21  3:41 Andre Nathan
2009-03-21 15:26 ` [Caml-list] " blue storm
2009-03-21 16:14   ` Andre Nathan
2009-03-21 17:24     ` blue storm [this message]
2009-03-21 17:26       ` blue storm
  -- strict thread matches above, loose matches on Subject: below --
2009-04-13  0:05 Andre Nathan
2009-04-13 19:08 ` [Caml-list] " Andre Nathan
2005-07-15  8:39 camlp4 help Pietro Abate
2005-07-15 20:24 ` [Caml-list] " Martin Jambon
2005-07-18 10:12 ` Hendrik Tews
2005-07-19  5:23   ` Pietro Abate
2005-07-20  7:37     ` Hendrik Tews
2005-07-20  9:57       ` Gerd Stolpmann

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=527cf6bc0903211024n11ab84c2u940c8b64ad7f2582@mail.gmail.com \
    --to=bluestorm.dylc@gmail.com \
    --cc=andre@sneakymustard.com \
    --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).