Skip to content

janestreet/camlp4-to-ppx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Convert from camlp4 + syntax extensions to regular OCaml + extension points and attributes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published