Autoformat can receive standalone comments in trailing decor after a completed node. Preserve that intent by trimming trailing decor carefully and formatting document/node trailing comments at the active indentation level, so comments align with sibling nodes instead of collapsing to a single leading space.
This also restores the broader autoformat regression by handling slashdash trailing decor and stale line-escape markers after node terminators, then unignores the test with current KDL v2 syntax and canonical formatter output.
Constraint: Fix formatter behavior in kdl-rs so downstream tools such as kdlfmt inherit the behavior
Rejected: Adding downstream-specific fixtures | tests should describe generic KDL formatter behavior
Rejected: Reworking parser attachment of comment decor fields | higher risk than needed for a targeted formatter fix
Confidence: high
Scope-risk: moderate
Directive: Re-check document and node trailing decor if parser attachment semantics change
Tested: nix shell nixpkgs#cargo nixpkgs#gcc -c cargo test --all-features
Tested: nix shell nixpkgs#cargo nixpkgs#rustfmt -c cargo fmt --check
This is kinda rough right now, since it involves actually pulling in the old kdl v1. Not ideal, but workable as a stepping stone while a real v1 parser gets written.
Fixes: https://github.com/kdl-org/kdl-rs/issues/32
This implements a proposed draft of a KQL engine,
allowing CSS selector-style querying of KDL documents (and nodes)
in a variety of different ways.
This necessitates passing the input around through all the sub-parsers so they
can compute their own sub-spans, which in turn necessitates making most of the
subparsers into nom-style 'function builders' by wrapping them in closures and
returning the closures.
The current impl hides this functionality behind an on-by-default "span" feature.
Some fallout of this change:
There is now a private parser::KdlParser type that must be constructed with the
full input for all span computation. The parser::parser method has been moved to
a method of this to make sure the full_input used for span computation is the
same one passed to parsing. In doing this a bug where the span of errors would
be incorrectly computed for non-ascii strings has been fixed.
Types now manually implement PartialEq and Hash to avoid incorporating the span
of the item into those computations.
All parser combinators must first have the KdlParser applied before using them,
making their signatures far more complex. Unfortunately KdlParser::parse can't
apply that for you because I don't think it's possible to express that complex
of a signature and not have the lifetimes get messed up.
In 4.3.0, the Display output for nested nodes always puts the trailing
braces on the left margin:
a {
b {
c {
}
}
}
This commit indents the trailing brace to match the node name, at least
when explicit trailing text is not provided.
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.
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`.