25 unstable releases

1.0.0-alpha.6 Jun 28, 2020
1.0.0-alpha.4 May 26, 2020
0.13.2 Jul 31, 2024
0.13.0 Feb 1, 2024
0.4.0 Nov 18, 2020

#255 in Parser implementations

Download history 7755/week @ 2024-08-01 6568/week @ 2024-08-08 6781/week @ 2024-08-15 5469/week @ 2024-08-22 5617/week @ 2024-08-29 6770/week @ 2024-09-05 6065/week @ 2024-09-12 5932/week @ 2024-09-19 6339/week @ 2024-09-26 7512/week @ 2024-10-03 7866/week @ 2024-10-10 8576/week @ 2024-10-17 8562/week @ 2024-10-24 8423/week @ 2024-10-31 9691/week @ 2024-11-07 6912/week @ 2024-11-14

35,117 downloads per month
Used in 12 crates (11 directly)

MIT license

235KB
7K SLoC

About

The main purpose of the library is to provide tools for analyzing TOML data where the layout must be preserved and the original position of every parsed token must be known. It can also format TOML documents.

It uses Rowan for the syntax tree, and every character is preserved from the input, including all comments and white space.

A DOM can be constructed for data-oriented analysis where each node wraps a part of the syntax tree with additional information and functionality.

Features

  • time: Use time for TOML dates and times

  • serde: Support for serde serialization of the DOM nodes.

  • schema: Enable JSON-schema generation for formatter configuration.

Usage

A TOML document has to be parsed with parse first, it will build a syntax tree that can be traversed.

If there were no syntax errors during parsing, then a dom::Node can be constructed. It will build a DOM tree and validate the TOML document according to the specification. A DOM tree can be constructed even with syntax errors present, however parts of it might be missing.

use taplo::parser::parse;
const SOURCE: &str =
"value = 1
value = 2

[table]
string = 'some string'";

let parse_result = parse(SOURCE);

// Check for syntax errors.
// These are not carried over to DOM errors.
assert!(parse_result.errors.is_empty());

let root_node = parse_result.into_dom();

// Check for semantic errors.
// In this example "value" is a duplicate key.
assert!(root_node.validate().is_err());

Dependencies

~11MB
~163K SLoC