[wg-camlp4] A new branch to experiment with extension points

Leo White lpw25 at cam.ac.uk
Fri Mar 1 17:52:11 GMT 2013


Looking at the code, I don't think that it is taking the correct approach 
to defining the extension syntaxes.

The standard way to define a delimiter like "(:", in keeping with how the 
rest of OCaml is parsed, is to make it a single token from the lexer.

This (dramatically) restricts our choice of delimiters but it also makes it 
much easier to use precedences to parse the extensions in more positions.

After looking through the parser in detail to find safe delimiters, I have 
created a (untested) patch of your implementation that provides the 
following syntaxes:

1. Extensions:

     (: ident expr_opt ) 

   Used as a structure item, signature item, expression or type expression.

2. Attributes:

     [: ident expr_opt ]

   Attached postfix to structure items, signature items, expressions or 
   type expressions.

3. With Attributes

     with ident ( expr), ident, ident (expr) 

   Attached postfix to structure items or signature items.

There are two attribute syntaxes because it is difficult to have a single 
attribute syntax that can be used easily across all these categories. I 
also think that the "with" syntax is particularly nice with types and 
encourages a sensible kind of meta-programming.

The patch is available at:

  http://www.cl.cam.ac.uk/~lpw25/extension_points.diff

Regards,

Leo




More information about the wg-camlp4 mailing list