# Overriding the ocaml compiler format string parser

**URL:** <https://discuss.ocaml.org/t/overriding-the-ocaml-compiler-format-string-parser/13433>\
**Category:** Learning\
**Created:** [November 16, 2023, 11:09am UTC](https://discuss.ocaml.org/t/overriding-the-ocaml-compiler-format-string-parser/13433 "2023-11-16T11:09:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daiwen](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/daiwen/32/1378_2.png) [@Daiwen](https://discuss.ocaml.org/u/Daiwen)\
**Post date:** [November 16, 2023, 11:09am UTC](https://discuss.ocaml.org/t/overriding-the-ocaml-compiler-format-string-parser/13433/1 "2023-11-16T11:09:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [November 16, 2023, 12:28pm UTC](https://discuss.ocaml.org/t/overriding-the-ocaml-compiler-format-string-parser/13433/2 "2023-11-16T12:28:05Z")

</div>

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:

- [GitHub - Octachron/babilim: Localization plugin for OCaml](https://github.com/Octachron/babilim) is a prototype library designed to implement internationalization for the OCaml compiler (which does implement positional specifiers)
- [GitHub - Octachron/ffmt: Format string experimentations](https://github.com/Octachron/ffmt) for a series of experiment on implementing different format string formats, interpreters, and backends.
