[wg-camlp4] Against the use of syntactically-valid OCaml code for syntax extension purposes

Leo White lpw25 at cam.ac.uk
Tue Jan 29 18:16:21 GMT 2013


>I propose to start discussing the addition of attributes to most 
>syntactic categories (expressions, type expressions, patterns, type 
>declarations, module expressions, structure/signature items, etc).  I 
>suggest to adopt "expressions" as the (default) nature of attribute's 
>content, because the syntax for expressions is quite flexible.  We need 
>some syntax to attach such an attribute to various syntactic categories. 
>  It might be a good idea to support both prefix and postfix attributes. 
>  Personally I don't care too much about the choice of syntax, and I'm 
>very bad at picking good syntax.  Good proposal are welcome! 

How about allowing {: foo }, {% foo }, {@ foo },
 <: foo < bar >>, <% foo < bar >>  and <@ foo < bar >> ?

The idea is that "{" means it is a valid OCaml expression as oppossed to 
"<" which means it is an unlexed string.

":" means that it is an expression/pattern/type on its own and the 
type-checker should raise an error if it still exists after all 
preprocessing is done.

"%" means it is a postfix attribute that can safely be ignored by the 
type-checker.

"@" means it is a prefix attribute that can safely be ignored by the type 
checker.

This seems fairly systematic and covers many possible use cases.



More information about the wg-camlp4 mailing list