-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KDL 2.0.0 compliance for implementations #372
Comments
please consider pinging tree-sitter-kdl. thanks |
What's the file marker that differentiates v1 from v2? File extension |
There's no file marker, but the data model is exactly the same--it should be very easy to heuristically detect whether you're looking at 1.0 or 2.0 and react accordingly if you're working on a dual parser, and the resulting data will be the same in both cases. |
What is the heuristic in a non-code syntax file to tell apart a syntax error of I'd say that's an oversight of the v2 version, why not have something like |
you detect which one parses and go from there, basically :) So, if you run into Personally, I'm just going to support 2.0 for parsers I maintain going forward instead of trying to support both versions. Folks can use older versions of the parser to use 1.0 until they're ready to migrate. When discussing it, we came to the conclusion that the burden of always having to tag your 2.0 files wasn't worth it when KDL is still relatively low usage and we expect 2.0 to quickly become the dominant format going forward. |
I can't really use that trick since this isn't a parser in a programming lanuage where you have that kind of flexibility also you can have both v1 and v2 errors, so this rule won't help you determine the version
That's fine, put the burden on the v1 users! Or use a file extension. Also, after KDL becomes (world)dominant there might be v3! This future-proofs it. So you'd have a rule like: |
We can't. v1 users are already not tagging their content as v1. And adding something now for users to produce v1 content going forward isn't worth anyone's time; they should be writing v2, as that's what most parsers will be expected to (likely exclusively) accept going forward.
And if there are, we can figure out compat at that point. Note that "make v1 documents tag themselves, v2 can be assumed" is not compatible with a future v3 either; it'll mean that v3 also has required tagging (since a missing tag would indicate v2). So we don't need to worry about it right now; if a v3 ever appears, it'll need to be tagged anyway, so we can introduce the tag then.
This absolutely does not work, fwiw, unless the language is carefully designed to be back/forward-compatible, and losing data is acceptable. (CSS, for example, has this model.) A data format can't really do this. |
And as long as they don't encounter any v2 requiremens, they can continue to do so.
And what about all v1s that have already been written? I don't get it, why should there be no mechanism to differentiate them?
then it'd be much more painful due to higher scale
Well, you could add |
There are also emacs support packages at:
|
This is not possible. There are files valid both in v1 and v2 that produce different data. Example from my app:
If I understand the v2 change correctly, this will change meaning with v2, resulting in the |
No, v2 makes |
The same goes for the other keywords: Likewise, there's the very rare "gotcha" where you might have a node name called Scanning again through the changelog, the vast majority of changes make v2 more strict or use incompatible-with-v1 syntax, so it would be an error in either one. The only change I can think of that could "silently" change the data without being a syntax error in v1 or v2 is the new multiline string indentation stripping, where the following string means two different things whether you're in v1 or v2:
in v1, this yields:
and in v2:
There's no way to distinguish which of these is v1 and v2. |
I see, thanks for the clarification. As long as no v1 document can change meaning in v2 without syntax error, migrations would be much smoother. |
As ckdl is a single-pass streaming parser (and I want to keep it that way), I couldn't do a "if KDLv2 gives a syntax error, retry with the v1 parser" loop. Still, it was pretty straightforward to build a parser that starts out agnostic about the KDL version until the first time it sees a construct that is only valid in one version or the other. The (experimental/draft) hybrid parser in ckdl processes all valid KDLv2 documents correctly and (currently) only compromises on KDLv1 compatibility in a few cases (that I know of), if they occur before any v1-only construct:
I really wouldn't expect other hybrid parser implementations to have a compatibility story worse than this. |
Hi, I'm updating kdl-nim to match KDL v2 draft 4 and from what I see on the SPEC, the BOM (U+FEFF) code point is only allowed as the first character in a KDL file, so that means it is disallowed anywhere else and I think it should be included in the Disallowed Literal Points section in the SPEC. |
@Patitotective As far as I can see, it is included in that section. https://github.com/kdl-org/kdl/blob/kdl-v2/SPEC.md#disallowed-literal-code-points |
@tjol You're right! Seems like I was confused because the tag for 2.0.0-draft.4 is not actually the latest draft but 9 months old, I'll be looking at latest commit then 😅 |
@juh9870 worth noting here, by the way, that as of the latest (probably final) draft of 2.0.0, parsing v1 vs v2 is completely unambiguous. Multiline strings are now syntactically distinguishable and the only documents that will parse as both v1 and v2 are documents that will result in the exact same data. |
That is amazing! Sadly, my app will likely have to release with v1 specs support only, since the kdl lib I'm using is no longer getting updates (knuffel) |
@juh9870 There's now a fork of knuffel over at https://github.com/TheLostLambda/knus by @TheLostLambda, and they're planning on adding v2 support at some point. I'm also thinking about somehow integrating knus directly into |
Hi @zkat! Personally I'd love to integrate the two — I've not quite been keeping up, but does kdl-rs handle 2.0 and 1.0 as a fallback currently? I think a sort of |
@TheLostLambda the main branch does. I need to fix some formatting-related stuff that has already been there for a while, and then I'm gonna do another 6.0 prerelease, though. If it happens after tomorrow, it's very likely not even going to be a prerelease, since the 2.0 spec is getting published tomorrow barring any final, sudden blockers. What I want for kdl-rs is to have a "proper" Serde implementation that works kinda like quick-xml, but that's a lot of work and serde is hard, so I was thinking of just having a feature flag that pulled in knuffel (now knus) as a dependency, and then soft-fork knus-derive to just make it so attribute labels are |
@zkat Sounds like a good plan! I'll take a look and try to gauge the effort involved in some sort of I'd also prefer things to be done via |
@TheLostLambda yeah that sounds good. Though honestly, I think I'm going to semi-integrate knus as a stopgap because I want serde-like behavior now, and even though serde is the ideal, it's going to take a lot of time and effort to write. And integrating knus is going to be practically trivial (including having it "support" v2). For that latter piece, my evil plan is to parse a v2 doc normally, then format it into a valid v1 string if it completes the parse, and then pass it to knus for the data bit. Not the most efficient thing in the world, but it means you get kdl-rs' error reporting, which is REALLY rich (it can resume parsing and collect most errors in a single pass, instead of one at a time). knus, then, would effectively never fail, or shouldn't, unless there's a bug, because bad kdl will never make it to it, so I don't have to worry about translating its errors or anything. Writing a v2 -> v1 translation layer is fairly easy if your goal is just to convert it to a string. |
@zkat I'm a big fan of that evil plan! I'm happy to help with that if needed! The fork of Is your plan to have EDIT: Also, does the V2 -> V1 conversion exist already? |
@TheLostLambda I'm perfectly happy with
Not yet. I just did the v1 -> v2 conversion last night and tbh it would really not be a lot of work at all, especially since we don't need to preserve formatting/comments/etc when passing things down to All that needs to be done is implement the inverse of this |
Anyway I'm working on the -> v1 formatter now. Hopefully ready tonight |
@zkat I checked off kdl-rb in the list, I hope that's ok. Also can we add Swift to the list: danini-the-panini/kdl-swift#1 |
@danini-the-panini done! |
This issue is for tracking full test suite compliance for KDL implementations that support the new KDL 2.0.0 spec.
Implementations:
knuffel KDL 2.0 compliance tailhook/knuffel#35deprecatedknuffel
)The text was updated successfully, but these errors were encountered: