Overriding the ocaml compiler format string parser

Hi,
I am writing a compiler, and would like to support internationalisation. I was pondering the possibility of interpreting format strings differently than the way provided by the ocaml compiler.
In particular, supporting things like %1s which would reference the first argument provided when printing something using this format.

It would be convenient to override the default parser provided by the compiler.

Is there a way to do just that? What would you recommend doing?

You cannot override the format string parser, and it would be insufficient since the printf interpreters can only work on the format GADT defined by the standard library. What you can do is use ppx library to define your own format string syntax and GADT data types:
I have few examples, that I could explain in more details:

4 Likes