[wg-camlp4] Request for feedback

Leo White lpw25 at cam.ac.uk
Wed Mar 13 17:30:56 GMT 2013


Alain Frisch <alain.frisch at lexifi.com> writes:

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

That seems reasonable.
>
> we can also write:
>
>   ((@id arg) expr)
>
> which is equivalent to:
>
>   (expr (@id arg))

As long as you meant

    ([@id arg] expr)

then this is also a good idea.

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

I have to agree with Gabriel here, these things are a pain to get
right. If you don't handle it in the lexer then you allow things like:

   let% lwt x =  (* defining a lwt function? *) 

or

  let % lwt x = (* defining the % operator? *)

which is definitly undesirable. It also allows comments and newlines to
be inserted in awkward places.

This means that you must lex "let%lwt" as a single token which can be a
bit awkward. It is probably ok for a few specific cases, but expanding
it to all keywords is asking for trouble.

> And if we do the same for the parenthesized expressions, we could write:
>
>  (%foo expr)
>
> which would be equivalent to:
>
>  [%foo expr]
>

I don't think this is a good idea because you are parsing '%' as a
strange prefix operator, so that all of the following are allowed:

(% foo expr) ( %foo expr ) ( % foo expr )

((* hello world*)%
  foo expr
)

this is probably a bad idea, and disagrees with how every other two
character delimiter in OCaml is parsed.

And lexing '(%' as single token conflicts with other places in the
grammar.



More information about the wg-camlp4 mailing list