[wg-camlp4] My uses of syntax extension
Alain Frisch
alain at frisch.fr
Tue Jan 29 10:45:17 GMT 2013
On 01/29/2013 11:19 AM, Fabrice Le Fessant wrote:
> I would strongly argue for a convention that has to be obeyed by all
> preprocessors. If you leave it to the preprocessor, you will have to
> call the preprocessor during the parsing, not during the typing, i.e.
> you won't have access to the typing environment while expanding macros.
If we extend the grammar with quotations, they can be rewritten by -ppx
filters. This is useful, and not incompatible with OCaml Templates
(which can interpret remaining quotations, not rewritten by -ppx). Many
current uses of quotations really don't need access to typing
information, and there are advantages in doing the expansion during
parsing, not type-checking:
- ocamldep can run the -ppx filters in order to get a precise idea of
dependencies, after expansion has occurred.
- OCaml Templates requires to load expanders in the same process as
the type-checker, but this would force to use Dynlink in the compiler
(or re-link statically you compilers with your expanders). Dynlink in
native code is not available on all platform.
- An expansion done by a -ppx rewriter can benefit from other
rewriters applied afterwards. It is not clear if we should apply the
-ppx rewriters to each fragment produced by OCaml Templates.
I'm not arguing against OCaml Templates, which has very interesting
usage scenarios, but it should be thought as an addition to expanders
implemented with -ppx, for those cases where type information is
actually required and the downsides mentioned above are not problematic.
Of course, we should share the same quotation syntax.
Alain
More information about the wg-camlp4
mailing list