kdl-org / kdl

the kdl document language specifications
https://kdl.dev
Other
1.1k stars 61 forks source link

Differentiation between "no children" and "empty children" #218

Closed djmattyg007 closed 2 years ago

djmattyg007 commented 2 years ago

I'm wondering if implementations should be explicit about the difference between the following two documents:

node
node {
}

At the moment, I'm interpreting them identically. When it comes time to serialise the document, both inputs would be encoded as the first example. Is this correct?

zkat commented 2 years ago

This is fine as long as your parser is a data-oriented parser. Document-oriented parsers should probably preserve the empty child block, but they're already preserving a lot of extraneous things like whitespace so it's not a big deal to do it either way.

tabatkins commented 2 years ago

Strong agree on both. The distinction doesn't matter for data parsers, and it already matters for document parsers that want to preserve the original structure as much as possible. So it shouldn't be part of the KDL data model itself.

hkolbeck commented 2 years ago

kdl4j exposes the difference in the model objects it uses to represent nodes, but I don't think that needs to be a general requirement. On the output side, printing empty children is a config setting.

tabatkins commented 2 years ago

I'm just now implementing children (only comments left!) and it looks like the test suite does expect you to retain the difference between "no kids" and "empty kids" in the data model, since all of the empty_child*.kdl tests expect to have a {\n} after the node.

So, either the existence of an empty child list is reflected in the data model, or the tests needs to be fixed (I can provide a PR for the latter).

hkolbeck commented 2 years ago

My inclination is to make the tests translate empty child -> no child, and add a note to the test README.

zkat commented 2 years ago

I feel like we should make a call either way. There should definitely be a decision.

I'm also inclined towards empty child -> no child, mostly because that means that you don't allocate unnecessarily ;p

tabatkins commented 2 years ago

cool, PR incoming shortly