Search code examples
ocamlcamlp4ppx

Writing a parser for a DSL in OCaml using ppx and extension point


Recently, it was announced in OCaml official github that Camlp4 is replaced by ppx rewriters and extension points (https://github.com/ocaml/camlp4):

Camlp4 was part of the official OCaml distribution until its version 4.01.0. Since then it has been replaced by a simpler system which is easier to maintain and to learn: ppx rewriters and extension points.

I have been using Camlp4 to write parsers for DSL (separated syntax from OCaml).

So, I would like to ask if the ppx rewriters tool can do the same thing?

Thank you for taking time to read my question!


Solution

  • No. PPX is specialized to extend OCaml language functionality keeping its syntax, possibly using attributes and extension points. It does not provide a parser generator like CamlP4. If you are building a syntax completely different from OCaml, just stick to P4. PPX does not help you.

    CamlP4 is not discontinued. It became an independent tool of OCaml compiler: https://github.com/ocaml/camlp4 You should also be able to install it using opam install camlp4.