[ANN] OTOML 0.9.0 — a compliant and flexible TOML parsing, manipulation, and pretty-printing library

OTOML 0.9.2 is now available from the OPAM repository.

Breaking changes

It makes a breaking change to the get_array accessor: it now has type Otoml.get_array now has type ?strict:bool -> (t -> 'a) -> t -> 'a list , that is, it requires an accessor function that will be applied to every item of the array.

For example, you can use Otoml.find t (Otoml.get_array Otoml.get_string) ["foo"] to retrieve an array of strings from a TOML document’s key foo .

The motivation for the change is that it allows retrieving arrays of unwrapped OCaml values in one step. The old behaviour can still be emulated using an identify function for the accessor, for example the built-in Otoml.get_value : 'a -> 'a .

New features

New Otoml.path_exists t ["some"; "table"; "key"] allows checking if a key path exists in a TOML document.

Otoml.Printer.to_string/to_channel functions now provide ~force_table_array option. When set to true, it forces every array that contains nothing but tables to be rendered using the `[[…]]`` table array syntax.

Bug fixes

Unicode escape sequences are now printed correctly.

If a table has subtables and non-table items, the non-table items are forcibly moved before the first subtable for printing. This way the output parses correctly, otherwise the non-table items would be mistakenly treated as subtable members. This way hand-constructed TOML tables are always formatted correctly even if the user inserts non-table items after a subtable.

Testing

I added a minimal test suite for the read-write interface. If anyone wants to contribute to it, that will be much appreciated. Ideally, all lookup functions and all accessors/constructors should be tested to work as expected.

Both parser and formatter are now tested with the github.com/BurntSushi/toml-test and are fully compliant (one formatter test is skipped because the test itself is malformed).

Future plan

My idea was to call it 1.0.0 when it passes both parsing and formatter tests. That goal is reached now, but I’d like to see if anyone has any more ideas for the API that cannot be implemented without breaking changes. If not, I’ll call it 1.0.0 in the next release.

8 Likes