Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ocaml

camlp4

ppx

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!

like image 459
Trung Ta Avatar asked Jun 14 '16 11:06

Trung Ta


People also ask

What is PPX in OCaml?

ppx is the main syntax extension format supported by OCaml. It allows for many features that aren't included in the core language to be added on, particularly ones that involve reducing boilerplate code. For example, there's usually no need to write code manually for the serialization or comparison of types.

What is PPX code?

What is a PPX? PPX rewriters or PPX-es are preprocessors that are applied to your code before passing it on to the compiler. They don't operate on your code directly but on the Abstract Syntax Tree or AST resulting from its parsing.


1 Answers

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.

like image 84
camlspotter Avatar answered Oct 17 '22 09:10

camlspotter