Convert from camlp4 + syntax extensions to regular OCaml + extension points and attributes
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
plugins
.gitignore
LICENSE.txt
Makefile
README.md
_tags

README.md

Camlp4 to PPX conversion tool

The aim of this project is to automatically convert OCaml source files using camlp4 syntax extensions to their equivalent in the ppx world while preserving comments and the layout. We used a variation of this tool at Jane Street to convert our code base.

For instance it will translate:

type t =
  | A of int (* blah *)
  | B of string
  with sexp, bin_io

let x = <:sexp_of< t * int >> (A 42, 10)

into:

type t =
  | A of int (* blah *)
  | B of string
  [@@deriving sexp, bin_io]

let x = [%sexp_of: t * int ] (A 42, 10)

For each syntax extension to convert a plugin needs to be written.

Plugins

This repository has plugins for all old jane street camlp4 syntax extensions. The ocsigen fork has plugins for deriving, eliom, and other ocsigen related syntax extensions.

How does it work?

It works by writing a dummy camlp4 syntax extension that only register substitutions using locations. After parsing the input file all the substitutions are applied to the original file and the result is printed.

To add a new plugin, add a file to the plugins/ directory and the corresponding line in bin/main.ml. pa_ounit.ml should be a good model to understand how it works.