24 releases (12 breaking)

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

#229 in Parser implementations

Download history 1574/week @ 2023-12-23 3480/week @ 2023-12-30 9346/week @ 2024-01-06 10149/week @ 2024-01-13 9576/week @ 2024-01-20 9352/week @ 2024-01-27 10497/week @ 2024-02-03 12019/week @ 2024-02-10 12052/week @ 2024-02-17 12455/week @ 2024-02-24 16339/week @ 2024-03-02 15479/week @ 2024-03-09 16564/week @ 2024-03-16 17266/week @ 2024-03-23 12932/week @ 2024-03-30 9939/week @ 2024-04-06

59,699 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
~161K SLoC