22 releases (11 breaking)

1.0.0-alpha.6 Jun 28, 2020
1.0.0-alpha.4 May 26, 2020
0.12.0 Oct 31, 2022
0.9.0 Jun 12, 2022
0.4.0 Nov 18, 2020

#165 in Parser implementations

Download history 3774/week @ 2022-11-26 3158/week @ 2022-12-03 3211/week @ 2022-12-10 2093/week @ 2022-12-17 1153/week @ 2022-12-24 1775/week @ 2022-12-31 2400/week @ 2023-01-07 2440/week @ 2023-01-14 2369/week @ 2023-01-21 2665/week @ 2023-01-28 2673/week @ 2023-02-04 2592/week @ 2023-02-11 2610/week @ 2023-02-18 2856/week @ 2023-02-25 3149/week @ 2023-03-04 2019/week @ 2023-03-11

11,088 downloads per month
Used in 8 crates (7 directly)

MIT license

235KB
6.5K 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

~6.5MB
~138K SLoC