Ocaml-migrate-parsetree for bucklescript


#1

Is there anyone who ported ocaml-migrate-parsetree (omp) to bucklescript? I am investigating the usage of ppx that are common in the native world but with bucklescript. Most of the native ppx now depend on omp. So it would be very convenient to be able to compile it with bucklescript.

Then the same question would apply for ppxlib, but it seems to support only “recent” versions of ocaml. So it will have to wait for the port of bs to 4.06.


#2

I’ve been trying to make omp work with BuckleScript, but got stuck early in the process. I’m documenting it here with the hope it helps others, or someone can point out what I’m doing wrong.

The first thing I couldn’t make work is the preprocessing part of omp, that removes the (*IF_CURRENT *) comments in the Ast_40x.ml file that corresponds with the version of OCaml being used.

I managed to make bsb use omp pp binary with

  "ppx-flags": [
    "./tools/pp.exe 4.02"
  ],

But pp.exe is expecting to have the filename passed as argument, and with BuckleScript I only get arguments like /var/folders/ss/97gmv_jn031f29dsvb600f280000gn/T/camlppxcbb8b1, which doesn’t contain the original file name. I’ve tried several things but not sure how to fix this. :thinking:


The other main problem that I haven’t been able to solve is how to import compiler-libs in a BuckleScript project. I have tried hacking around it by adding:

    "sources": [{
      "dir": "node_modules/bs-platform/vendor/ocaml/parsing",
      "files": [
        "ast_helper.mli",
        "ast_helper.ml",
        "asttypes.mli",
        "docstrings.mli",
        "docstrings.ml",
        "location.mli",
        "location.ml",
        "longident.mli",
        "parsetree.mli"
      ]
    }]

to bsconfig. But this just keeps erroring because dependencies are missing, until I reach a point where it asks for config.ml but the vendor/ocaml/utils folder has a config.mlp which seems to need some preprocessing as well.

There must be easier ways to accomplish this, I wonder if @bobzhang has any ideas?

I’ve also been thinking this would be much easier if dune could be used with a BuckleScript project. I found out there is some work being done by @zploskey in https://github.com/zploskey/hello-esy-dune-bsb/ that seems to be starting, but is very promising :slight_smile: See also https://github.com/ocaml/dune/issues/140.