[wg-camlp4] Request for feedback

Alain Frisch alain.frisch at lexifi.com
Fri Mar 8 09:19:15 GMT 2013


I've generalized the "attribute on the opening keyword" form to all 
kinds of expressions starting with a keyword, a sequence of keywords 
(let open, let module), and even delimiters.  In the same way that we 
can write:

   let[@id arg] p = e1 in e2

for:

   (let p = e1 in e2)[@id arg]

we can also write:

   ((@id arg) expr)

which is equivalent to:

   (expr (@id arg))

(We see the first form as an attribute of the opening delimiter of the 
construction "(expr)".)

I think it is nice to be able to use the same syntax and essentially get 
prefix attributes as well.  Do you guy agree?  Or do you believe that 
this creates too much confusion?


On 03/07/2013 06:07 PM, Gabriel Scherer wrote:
> However, non-delimited syntaxes such as for%lwt open a new
> parsing can of worms

Actually, I believe this works quite well, and I'm playing with the idea 
that this could be the (only) syntax for extension nodes.

We could actually extend the idea above of putting attributes on opening 
keywords/delimiters to support also an optional extension identifier. 
For instance:

   let%foo p = e1 in e2

would be equivalent to:

   [%foo let p = e1 in e2]

Doing that for the "lwt" example would not only give a more compact 
syntax, but also make use of extensions instead of attributes, which can 
be preferred in that case (so that the compiler fails cleanly if we 
don't compile with "-ppx lwt" instead of giving weird error messages).


The "bitstring" example could then be written:

match%bit bits with ...

instead of

[%bit match bits with ...]



And if we do the same for the parenthesized expressions, we could write:

  (%foo expr)

which would be equivalent to:

  [%foo expr]

At this point, if we do that, it makes little sense to keep the original 
form for extensions ([%id expr]), and we could use (%id expr) instead, 
for all categories (not only expressions).

What do you think?


Alain


More information about the wg-camlp4 mailing list