I am making a ppx extension rewriter as part of a code library
Ideally the library will be usable with some range of OCaml versions
I have noticed that when building AST nodes to output from my rewriter it is unavoidable to have to construct some records, whose structure is specific to a particular OCaml AST version
For example, when building a variant type declaration we have to define a record like:
{
pcd_name = {txt = name; loc};
pcd_args = Pcstr_tuple [];
pcd_res = None;
pcd_loc = loc;
pcd_attributes = [];
}
Which is the constructor_declaration
type
However this AST type differs between OCaml 4.13 and OCaml 4.14
I am hoping that mostly the ppxlib Ast_builder
helpers take care of generating the correct AST version for whatever OCaml version I'm compiling my library under.
But in the places where I have to manually define one of these record instances then presumably I need to detect the current OCaml version and return the correct record format that way?
I found this:
utop # Sys.ocaml_version;;
- : string = "4.12.1"
So presumably I should parse this string into int * int * int
so that I can do a safe comparison for versions newer than 4.14.0
Is there a better way, or something different I should do instead?