Skip to content
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

\ at EOL should escape all whitespace after it and treat it as a single one #213

Closed
zkat opened this issue Sep 28, 2021 · 4 comments · Fixed by #290
Closed

\ at EOL should escape all whitespace after it and treat it as a single one #213

zkat opened this issue Sep 28, 2021 · 4 comments · Fixed by #290
Labels
breaking This can only be done for the next major version of KDL enhancement New feature or request

Comments

@zkat
Copy link
Member

zkat commented Sep 28, 2021

in one of their streams, @Lucretiel pointed out that Rust strings let you do this:

let foo = "x\
    y\
    z\
    ";

I think this is a GREAT compromise for not automatically collecting indentation? I think we should do this too.

My one question is that I'm not 100% sure what Rust itself does, but I think whatever that is, we should probably just copy it.

@zkat zkat added breaking This can only be done for the next major version of KDL enhancement New feature or request labels Sep 28, 2021
@CAD97
Copy link
Contributor

CAD97 commented Sep 28, 2021

Rust escapes all whitespace until the next non-whitespace character.

Specifically,

fn main() {
    dbg!("x\
    y\
    z\
    ");
}
[src/main.rs:2] "x\
    y\
    z\
    " = "xyz"

In strings, this makes sense, but outside of strings, specifically for the purpose of KDL, I think treating \\\n\p{White_Space}*regex as one unit of whitespace (not linespace) is better from a practicality of use standpoint (no splitting lexer atoms over multiple lines).

@Lucretiel
Copy link
Contributor

Just to be clear, this proposal only applies to quoted string literals in KDL; it doesn't change the behavior of linespace / splitting nodes over multiple lines or anything about how KDL handles syntactic whitespace.

The Rust behavior is specifically that a backslash preceding a line break (newline or CRLF) consumes itself, the line break, and all succeeding literal whitespace at the beginning of the next line. I'd propose the simpler, more general rule, which is simply that a backslash consume all literal whitespace that succeeds it. In either cases, they notably only consume literal whitespace; they do not consume escaped whitespace. This means we can write things like:

node "\
    Header\n\
    \tIndented\n\
    \tIndented again\
"

This is exactly equivalent to:

node "Header
\tIndented
\tIndented again"

This was referenced Aug 31, 2022
@eugenesvk
Copy link
Contributor

Would a better rule be to consume only the same amount of whitespace, so to cut out the prefix whitespace in vertically aligned columns, but also allow non-prefix whitespace at line beginning

node "\
  Header\n\
    - item 1 with 2-spaces indent\n\
    - item 2 with 2-spaces indent\n\
  Continue\
"
node "Header
  - item 1 with 2-spaces indent
  - item 2 with 2-spaces indent
Continue"

@zkat
Copy link
Member Author

zkat commented Dec 13, 2023

This has been merged into the kdl-v2 branch

@zkat zkat closed this as completed Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This can only be done for the next major version of KDL enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants