Fixes#46
When comparing two different `KdlNode` or `KdlDocument`, it's useful to
have a "canonical" representation where formatting differences do not
matter.
`clear_fmt` removes all formatting from a `KdlNode`, but does not apply
recursively, as a result, it doesn't create a canonical representation.
`clear_fmt_recursive` solves this by applying `clear_fmt` recursively to
the contents of the node.
While the type of entries was parsed, there was no way for the library
user to access it. This commit let the user access the `ty` field of the
`KdlEntry` struct. It mirrors the accessors on the `value` field.
This commit includes a whole bunch of fixes, some of which are significant changes to the parser and some related functionality. But I consider all changes to be bugfixes because they were compliance failures.
This new version of kdl-rs is a complete rewrite that introduces
a formatting-aware-and-preserving parser, much like toml_edit et al.
BREAKING CHANGE: Completely new API and bumped MSRV to 1.56.0.
* Add From impls for KdlNodeValue
Most clients probably don't need to create these directly, but we may as
well make it easy for them.
* Add TryFrom impls to convert from KdlNodeValue to underlying types
This includes converting from borrowed values, which will produce `&str`
instead of `String`.
* Add line and column numbers to KdlError
These numbers are calculated using our `newline` rule, as I'm not aware
of any standard for how to calculate line numbers in error messages.
The error retains the original `offset` field as well, but it's now
expressed in characters rather than bytes.
* Clean up error handling in parse_document()
We don't need to worry about `Incomplete` errors, the `complete` family
of parsers (which we're using) doesn't ever produce those. We can use
the `.finish()` function to unwrap the error instead, so we don't have
to worry about the underlying error types.
Using the `ignore` marker makes `cargo test` think this is rust code
that should be ignored, which means it prints an "ignored" line in the
test output. It also makes `cargo doc --document-private-items` attempt
to colorize it as rust code. Marking this as `text` instead fixes both
issues.