taplo/lib.rs
1#![allow(clippy::single_match)]
2//! # About
3//!
4//! The main purpose of the library is to provide tools for analyzing TOML data where the
5//! layout must be preserved and the original position of every parsed token must be known. It can
6//! also format TOML documents.
7//!
8//! It uses [Rowan](::rowan) for the syntax tree, and every character is preserved from the input,
9//! including all comments and white space.
10//!
11//! A [DOM](dom) can be constructed for data-oriented analysis where each node wraps a part of the
12//! syntax tree with additional information and functionality.
13//!
14//! # Features
15//!
16//! - **time**: Use [time](https://github.com/time-rs/time) for TOML dates and times
17//!
18//! - **serde**: Support for [serde](https://serde.rs) serialization of the DOM nodes.
19//! - **schema**: Enable JSON-schema generation for formatter configuration.
20//!
21//! # Usage
22//!
23//! A TOML document has to be parsed with [parse](parser::parse) first, it
24//! will build a syntax tree that can be traversed.
25//!
26//! If there were no syntax errors during parsing, then a [`dom::Node`]
27//! can be constructed. It will build a DOM tree and validate the TOML document according
28//! to the specification. A DOM tree can be constructed even with syntax errors present, however
29//! parts of it might be missing.
30//!
31//! ```
32//! use taplo::parser::parse;
33//! const SOURCE: &str =
34//! "value = 1
35//! value = 2
36//!
37//! [table]
38//! string = 'some string'";
39//!
40//! let parse_result = parse(SOURCE);
41//!
42//! // Check for syntax errors.
43//! // These are not carried over to DOM errors.
44//! assert!(parse_result.errors.is_empty());
45//!
46//! let root_node = parse_result.into_dom();
47//!
48//! // Check for semantic errors.
49//! // In this example "value" is a duplicate key.
50//! assert!(root_node.validate().is_err());
51//! ```
52
53pub mod dom;
54pub mod formatter;
55pub mod parser;
56pub mod syntax;
57pub mod util;
58
59pub use rowan;
60
61pub type HashMap<K, V> = ahash::AHashMap<K, V>;
62pub type HashSet<V> = ahash::AHashSet<V>;
63
64#[cfg(test)]
65mod tests;
66
67mod private {
68 pub trait Sealed {}
69}