P.O.T.
Parser of Toml powered by Muncher
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
[]
= "0.2.7"
Examples
Parsing
use ;
let file =
r#"[deps]
alpha = "beta"
number = 1234
array = [ true, false, true ]
inline-table = { date = 1988-02-03T10:32:10, }
"#;
let parsed = parse_it.expect;
let root = parsed.syntax;
assert_eq!
The parse tree is a rowan
SyntaxNode
that can be manipulated and traversed freely.
The SyntaxNodeExtTrait
allows easy to string representation of the tokens (the source file text).
Sorting
use ;
let file = r#"# comment
[dependencies]
number = 1234
# comment
alpha = "beta"
"#;
let parsed = parse_it.expect.syntax;
let parsed2 = parse_it.expect.syntax;
assert!;
let sorted = sort_toml_items;
assert!;
The sorted tree is a rowan
SyntaxNode
that can be manipulated and traversed freely.
Formatting
use ;
let parsed = parse_it.expect.syntax;
let fmted = new.format;
assert_ne!;