[wg-camlp4] Support for extension points in Camlp4

Alain Frisch alain.frisch at lexifi.com
Wed Apr 3 18:55:44 BST 2013


Another topic where help would be much appreciated is the support of 
extension points in Camlp4.  Even if one of the goal of all this 
discussion is to replace some uses of Camlp4, there is no reason Camlp4 
could not support itself the three new syntactic features (attributes, 
extension nodes, quoted strings) in its parsers and its custom 
representation of the OCaml AST.  In addition to simplifying a migration 
phase (combining some Camp4 extensions and some -ppx rewriters), 
supporting extensions points in Camlp4 makes sense even for people who 
want (or will have) to continue using Camlp4:

  - AST mappers can then be written not only with -ppx but also as 
Camlp4 AST filters (which supports concrete syntax patterns and 
expressions).

  - It can be imagined that some extensions are split into an AST 
transformation part (to be processed by -ppx) and a change to the 
concrete syntax (with a Camlp4 extension which would only adds 
attributes and extension nodes to the AST).  This would make it possible 
to use the core feature of the extension without camlp4 and still 
provide ad hoc concrete syntax for those who insist on it.

  - Some external tools (a la Bisect) might start using attributes found 
in the parsetree or typedtree, and projects built with Camlp4 will need 
a way to embed such attributes in the source files.


The current state is that Camlp4 has been adapted to the new Parsetree 
(i.e. it generate valid fragments), but its internal representation of 
the OCaml AST and its parsers do not support the new features.  Adding 
this support should not be very difficult for someone familiar enough 
with the implementation of Camlp4.  Any volunteer?


Alain


More information about the wg-camlp4 mailing list