Hello! I am pleased to announce tom v0.0.1, a new experimental TOML parser, which preserves all whitespace.
Note the 0.0.1 version: it means that the code is very much experimental/unimplemented!()
, and that you shouldn't use this crate for any serious project yet However, I'd like to publish it nevertheless to get feedback, hopefully in the form of PRs and issues
There are no API docs yet, but this API walkthrough should hopefully give you a general idea of what is available.
Some interesting features:
-
Lossless parsing by construction: the library does not use a traditional "nested enums" approach to AST: documents are represented as concrete syntax tree, all comments and whitespace are explicit nodes in the tree.
-
Powerful error recovery: the
parse
function does not return aResult
, any utf8-string is interpreted as a TOML document (which might be just a pile of syntax errors of course). -
Lossless editing: it is possible to create documents with arbitrary whitespace and comments. The API gives full control over placement of elements: you can insert a new key-value into the particular position, with specific whitespace around. It is even possible to create invalid TOML documents. You can totally win your local "ugly TOML" contest with this library
It is possible to build a less-powerful API which guarantees validity of documents on top of the raw API, provided by the library.
-
A nifty AST representation allows to create a generic type-safe/type-directed visitor in less than 50 lines of code. Using such visitor is also more convenient than the traditional approach of implementing a particular visitor interface.
Some notable missing pieces:
-
No high-level API. You'll need to figure out yourself that the following are equivalent (yep, TOML now has dotted keys):
foo.bar.baz = 1 [foo] bar.baz = 1 [foo.bar] baz = 1
-
No correctness guarantees: some valid toml documents might produce syntax errors, some invalid toml documents might be parsed as valid.
-
While I am pretty sure about the underlying data-structures and representation, the surface API could use some design work.