Ppxlib 0.34.0

We’re happy to announce that we just released ppxlib.0.34.0.

The full patch notes are available on the release page over here.

The main features are OCaml 5.3 compatibility, new AST pretty-printing utilities and the ppxlib-tools package, support for [@@deriving ...] on class types and the addition of missing Pprintast entry points.

Changes summary

5.3 compatibility

ppxlib.0.34.0 is the first official ppxlib release that’s compatible with the new 5.3 compiler.

The ppxlib driver now also comes with a -keywords CLI option, similar to the compiler’s that allow you to compile and preprocess with the 5.3 compiler code that uses effect as an identifier. This is pretty niche but it’s there should you need it.

Please note that means you can use ppx-es with a 5.3 compiler but not that ppx-es can consume/produce 5.3 language features. We’re currently working on a fix allowing you to use the effect syntax in files that require preprocessing as it’s not possible with 0.34.0. The fix should be released in the next few days as 0.34.1.

AST pretty-printing

We added a new Pp_ast module that allows you to pretty print AST fragments.

The only way ppxlib would print ASTs before were as S-expressions. In practice we found that it was not always helpful and wanted a more readable and human friendly way of displaying the AST.

The default output of those printer is a simplified version of the AST to keep things clear and avoid cluttering the output with information that is not always useful. For example, if you run Ppxlib.Pp_ast.Default.expression on the AST for x + 2, you’ll get the following:

Pexp_apply
  ( Pexp_ident (Lident "+")
  , [ ( Nolabel, Pexp_ident (Lident "x"))
    ; ( Nolabel, Pexp_constant (Pconst_integer ( "2", None)))
    ]
  )

The alert reader will note that there are no locations or attributes and that the expression record layer is omitted here.

You can of course configure the printer to display more information if you need to.

We’ve been using these new printers internally to debug migration code and they have been a huge help so we hope they will make working with ppxlib easier for you too.

In addition to this new module, we also added a command line utility called ppxlib-pp-ast to pretty print ASTs from source files, source code fragments or even marshalled AST files. It is very similar to the old ppx_tools’s dumpast.

Note that it will print ppxlib’s internal AST after it’s been migrated from the installed compiler’s version. This is something that we could not simply achieve with OCaml’s own -dparsetree.

This should be a useful tool for debugging ppx related bugs or learning about the AST and we hope ppx authors and users will like it.

Other changes

As mentioned above, we also added some missing Pprintast* entries such as binding, longident and payload.

It is now possible to use [@@deriving ...] on class type declarations and therefore to write derivers for class types.

*: To the confused readers: Pprintast is entirely different from Pp_ast mentioned above as it prints the source code corresponding to a given AST.

Special thanks

We wanted to thank our external contributors for this release: @hhugo, @nojb and @dra27 for their help on the 5.3 compat and @mattiasdrp for bringing the Pprintast module up to speed.

Special thanks as well to @pedrobslisboa who started integrating their excellent ppx-by-example into ppxlib’s documentation.

Finally, I’d also like to thank the OCaml Software Foundation who’s been funding all my work on ppxlib and made this release possible!

Happy preprocessing to you all!

See full changelog
  • Add initial OCaml 5.3 support (#487, @NathanReb, @hhugo, @nojb)

  • Initialise OCaml 5.3's lexer with the keywords setting from OCAMLPARAM or the new -keywords driver's CLI option to allow the standalone ppx driver to process old packages using effect as an identifier (#535, @dra27, @NathanReb)

  • Add Pprintast.binding, longident and payload (#542, @mattiasdrp)

  • Fix deriving_inline round-trip check so that it works with 5.01 <-> 5.02 migrations (#519, @NathanReb)

  • Add ppxlib's AST pretty-printing utilities in Ppxlib.Pp_ast and a ppxlib-pp-ast executable in a new separate ppxlib-tools package (#517, #525, #537, @NathanReb)

  • Change -dparsetree from a sexp output to a pretty printed AST, closer to what the compiler's -dparsetree is. (#530, @NathanReb)

  • Add Parsetree documentation comments to Ast_builder functions (#518, @patricoferris)

  • Support class type declarations in derivers with the new, optional arguments {str,sig}_class_type_decl in Deriving.add (#538, @patricoferris)