kdl icon indicating copy to clipboard operation
kdl copied to clipboard

Shebang workarounds

Open zkat opened this issue 1 year ago • 2 comments

Discussed in https://github.com/kdl-org/kdl/discussions/472

Originally posted by jaxter184 January 9, 2025 I've found KDL to be well-designed to use as a base for a domain-specific scripting language, and shebangs can make scripts more ergonomic to run. Unfortunately, most shebangs are KDL syntax errors (usually because of path separators, but also potentially for other reasons depending on the contents).

I don't think it's a huge deal because the script interpreter can just choose to ignore the first line if it starts with a #! before it passes it into a KDL parser, but my goal in making a discussion about this is to see if anyone's got any better suggestions or examples of this kind of logic being used in the wild. Also, not sure how this kind of workaround would interact with LSPs and syntax highlighters.

There was a mention of shebangs here while discussing a similar syntax: https://github.com/kdl-org/kdl/issues/402, but as far as I can tell, there wasn't an explicit discussion or decision made on whether or not that would be a reasonable thing to do. I wish I had thought about this before the v2 release so they could have maybe been treated as comments (I think that's how the Rust compiler does it?). But such is life.

zkat avatar Jan 14 '25 18:01 zkat

I think it would have been good to treat a document-initial (possibly preceded by a bom) #! as a line comment, and would, personally, be ok with still sneaking it in.

In the absence of that, I don't see any ways around it. Either you write a valid KDL document without a shebang, or you write a script where the interpreter knows to discard the shebang. (Or you get "lucky" and write a valid KDL document with a confusing starting node.)

I'm lightly in favor of sucking it up and just issuing v2 errata.

tabatkins avatar Jan 14 '25 22:01 tabatkins

I think that’s why, rather than errata, we could try and do it as part of the IETF RFC, which will likely be slightly different from 2.0.0, and will almost definitely be asked to change by peer reviewers outside of our little community here

zkat avatar Jan 15 '25 00:01 zkat