kdl-org / kdl

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

Line continuations can be terminated with EOF only when a comment is present #337

Closed Bannerets closed 7 months ago

Bannerets commented 8 months ago

I thought this was already reported, but I can't seem to find any issue/discussion, so I'm opening a new one.

Right now, the line continuation is defined as

escline := '\\' ws* (single-line-comment | newline)

Where single-line-comment is (includes eof):

single-line-comment := '//' ^newline* (newline | eof)

This means that node \ // comment <EOF> is allowed as the last line, but node \ <EOF> is not, which feels weird. I think escline should probably include eof as well.

Patitotective commented 7 months ago

As far as I understand the line continuations breaks a node, let's say:

node 1 2 \
     3 4

So you can't really put nothing (or end the file) after \, that's why it expects a new line. Just like the KDL below is invalid, ending a file after a line continuation is invalid.

node 1 2 \
node

Instead a single line comment CAN end a file since it's not really part of a node, and it's not breaking a node.

Or at least that's why I understood from the specification :sweat_smile:.

zkat commented 7 months ago

probably what we want is something like (single-line-comment eof? | newline)

Bannerets commented 7 months ago

So you can't really put nothing (or end the file) after \, that's why it expects a new line.

It feels like it would be better UX if the file is valid regardless of the final newline (and regardless of whether the editor is configured the insert the final \n or not). FWIW, zsh (but not bash) seems to allow \ before EOF:

$ zsh -c "echo 1 \\"
1 
zkat commented 7 months ago

This has been merged into the kdl-v2 branch