P.O.T.

Parser of Toml powered by Muncher

Build Status Released API docs Latest Version

About

The most important thing about this toml parser is that it maintains the structure of the original parsed file (whitespace, comments, ect.). For toml formatting tools like cargo sort check this feature is essential, this is the only reason something like toml-rs cannot be used unfortunatly :(.

Use

toml [dependencies] toml-parse = "0.2.7"

Examples

Parsing

```rust use tomlparse::{parseit, SyntaxNodeExtTrait};

let file = r#"[deps] alpha = "beta" number = 1234 array = [ true, false, true ] inline-table = { date = 1988-02-03T10:32:10, } "#;

let parsed = parseit(file).expect("parse failed"); let root = parsed.syntax(); asserteq!(root.token_text(), file) `` The parse tree is a [rowan](https://docs.rs/rowan/0.9.1/rowan/)SyntaxNodethat can be manipulated and traversed freely. TheSyntaxNodeExtTrait` allows easy to string representation of the tokens (the source file text).

Sorting

```rust use tomlparse::{parseit, SyntaxNodeExtTrait};

let file = r#"# comment [dependencies] number = 1234

comment

alpha = "beta" "#; let parsed = parseit(file).expect("parse failed").syntax(); let parsed2 = parseit(file).expect("parse failed").syntax();

assert!(parsed.deep_eq(&parsed2));

let sorted = sorttomlitems(&parsed, &HEADER);

assert!(!parsed.deep_eq(&sorted)); `` The sorted tree is a [rowan](https://docs.rs/rowan/0.9.1/rowan/)SyntaxNode` that can be manipulated and traversed freely.

Formatting

```rust use tomlparse::{parseit, Formatter};

let parsed = parseit(&input).expect("").syntax(); let fmted = Formatter::new(&parsed).format(); assertne!(fmted.to_string(), input); ```

Structured (Coming soonish)

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.