I am trying to hook into the compilation process of my code to generate some additional files, in a way similar to ppx_deriving. Now it looks like ppx_type_conv is the easiest way to do so, but I can’t get my deriver to be picked by ppx_driver, when compiling ppx_type_conv complains: rror: ppx_type_conv: 'foo' is not a supported type type-conv generator.
My ppx_foo_conv looks like this:
open Ppx_type_conv.Std
open Ppx_core
let name = "foo"
let () =
Type_conv.add name
~extension:(fun ~loc ~path:_ ty -> [%expr ()])
|> Type_conv.ignore
My example.ml looks like this:
type foo = {
bar: int;
baz: string;
} [@@deriving flow]
type qux = {
quux: foo;
corge: string;
} [@@deriving flow]
Yes, your foo/flow deriver is actually registered.
The problem is that it is defined as an “extension”, but then used
as a “str_type_decl”. Your registration should look like:
Here are the kinds of generators that can be registered:
str_type_decl;
str_type_ext;
str_exception;
sig_type_decl;
sig_type_ext;
sig_exception;
extension.
The str_xyz generators are for structures/implementations, while the sig_xyz generators are for signatures/interfaces. extension can be used only in structures (it generates an expression).
Then, xyz_type_decl is for type declarations (i.e.type t =(…)[@@deriving foo]), xyz_exception is for exception declarations (i.e.exception E [@@deriving foo]), and xyz_type_ext is for type extensions (i.e.type t += A [@@deriving foo] after type t = ..). Finally, extension is expected to be used like that: let _ = [%foo : t].