Problems compiling ppx package

Im trying to make a ppx rewriter. It already compiled just fine, but now I want to test it. So I wrote a public_name into my dune and made a .opam file.

But I get the error: (according to opam migrate_parsetree is up to date)

# Error: Failed to create on-demand ppx rewriter for jsx_to_str_ppx; no ppx
# driver were found.
# Hint: Try upgrading or reinstalling ocaml-migrate-parsetree.

dune

(library
 (name jsx_to_str_ppx)
 (public_name jsx_to_str_ppx)
 (kind ppx_rewriter)
 (libraries ocaml-migrate-parsetree)
)

jsx_to_str_ppx.opam

opam-version: "2.0"
name: "jsx_to_str_ppx"
version: "0.1"
synopsis: "tranform reasonML JSX into string concatination"
description: """
tranform reasonML JSX into string concatination
"""
maintainer: "Name <email>"
authors: "Name <email>"
license: ""
homepage: ""
bug-reports: ""
dev-repo: ""
depends: [ "ocaml" "ocamlfind" "ocaml-migrate-parsetree" ]
build: ["dune" "build" "-p" name "-j" jobs]

js_to_str_ppx.re

open Migrate_parsetree
open Ast_412

open Asttypes
open Parsetree
open Ast_mapper

let jsx_mapper = _ =>
 .
 .
 .

register("jsx_to_str_ppx", jsx_mapper)

Hi @choltreppe, nice that you’re writing a PPX!

First of all as a heads-up: from your js_to_str_ppx I can see that you’re using the ocaml-migrate-parsetree API to define and register your PPX. Have you considered using the ppxlib API instead? To give more context: ocaml-migrate-parsetree is the old infrastructure to write PPXs, ppxlib is the new infrastructure. PPXs written with ocaml-migrate-parsetree aren’t compatible anymore with PPXs written in ppxlib, so nowadays PPXs are usually written in ppxlib and we also encourage folks strongly to do so. Ppxlib has several advantages over ocaml-migrate-parsetree, among them clear composition semantics and better performance.

Now, to get to your problem: is the version of ocaml-migrate-parsetree you have installed maybe a 2.x.x version? Since you’re saying that your ocaml-migrate-parsetree is up-do-date and given that dune is complaining about not finding a PPX driver, that’s quite likely. If you really wanted to use ocaml-migrate-parsetree (but again: I strongly advice you to use ppxlib instead, also to be compatible with other PPXs), you would need version 1.8.0.

Hey, thanks for the reply
yea I know about ppxlib being the better option, but I couldnt realy understand the system from the few resources I found for now :confused: but I found out about migrate-parsetree, which is much easier to understand. I can simply write some example code, dump the AST, analise it and then write my transformations. So for now I just want something to work for me. But in the long term I would reely like to use ppxlib. Maybe you know some good resources to learn ppxlib?

The verion 1.8.0 seems to solve that problem, but apparently theres no default_mapper in that version. Probably another reason to just use ppxlib :slight_smile:

Maybe you know some good resources to learn ppxlib?

That depends on what kind of transformations you’re writing. Are you writing extension node rewriters? (i.e. transformations that expand extension nodes like [%<extension_name> <payload>] to some “normal” OCaml code)

but apparently theres no default_mapper

Oh right, I didn’t think about that. Apart from using ocaml-migrate-parsetree <= 1.8.0, you’d also need to use an AST version <=4.11, whereas you’re using 4.12.

Probably another reason to just use ppxlib :slight_smile:

I agree :slight_smile:

That depends on what kind of transformations you’re writing. Are you writing extension node rewriters? (i.e. transformations that expand extension nodes like [%<extension_name> <payload>] to some “normal” OCaml code)

nope I want to modifie some expression marked with an attribute

I want to modifie some expression marked with an attribute

That sounds interesting! And it sounds like that kind of transormation might be possible to express as an extension node. Whenever that’s possible, expressing your PPX as an extension node or a deriver is the strongly recommended way. If you wanted to discuss that further, let’s open a new topic on that.

yes I saw that those are the common things to do but unfortunatly I cant chnage the syntax of what I need to transform because Its part of reasonml (JSX · Reason)

If you wanted to discuss that further, let’s open a new topic on that.

Ok, so should I just add new topic, or is there some way to fork from this topic or something

Oooh, are you aiming to implement JSX support within .ml files? rubs hands together :wink:

1 Like

yea that would be cool aswell, maybe I will try to make that when I got a hang of the ppx thing (but I think that would be a pp not a ppx because you would parse text directly instead of modifying the AST).
What I plan to do is a ppx that lets you use the JSX of reason when using the ocaml ecosystem. so my first plan was to just transform JSX to string concatination, but I think its more practical to have a ppx that lets you define a function that accepts the name of the tag and a list of args, then you can do whatever you want. But implementing JSX for OCaml would be sick too (1 reason for me using reason instead of ocaml (except its name :slight_smile: ) is the JSX thing. For most parts I prefer ocaml syntax)

1 Like