@unlambda the data model is exactly the same, fortunately, with the exception of v2 explicitly supporting #inf
, #-inf
, and #nan
for floats.
Besides that, documents that parse correctly in both v1 and v2 will represent the same exact data--with the exception of multiline strings, which are both stricter in v2 (so it's less likely to have a conflict), and the fact that v2 dedents multiline strings.
So this document:
my-string "
foo
"
will evaluate to "\n foo\n "
in v1, and "foo"
in v2. I'm debating whether we should tweak the multiline syntax so this corner case isn't possible, but it seems relatively minor.
What that means is that once I finish rewriting the v1 parser for kdl-rs, you'll be able to do something basically like kdl::v2::parse(input).or_else(|_| kdl::v1::parse(input))
and it should be able to consume any KDL doc. In fact, I might make it so that's the actual FromStr implementation (and you can be more strict by invoking the parsers directly).
And since the data models are identical, all you have to do to convert from v1 to v2 is:
let mut doc = kdl::v1::parse(input)?;
doc.autoformat(); // v2 formatting by default
print!("{doc}");