[ruby-core:117984] [Ruby master Misc#20503] Dedenting heredoc line continuation

Issue #20503 has been reported by kddnewton (Kevin Newton). ---------------------------------------- Misc #20503: Dedenting heredoc line continuation https://bugs.ruby-lang.org/issues/20503 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- When there is a line continuation inside a dedenting heredoc, occasionally it will impact the dedent calculation in interesting ways. I'm not sure if it's a bug, or if my understanding is incorrect. ```ruby <<~eos TEXT eos ``` In this case the string is `"TEXT\n", because the common whitespace is 2 and it's removed from the only line. However if there is a line continuation: ```ruby <<~eos \ TEXT eos ``` then the results is `" TEXT\n"`. To me this seems incorrect, because the second line is supposed to be considered as part of the first, which would mean it should have the same result as the first one. So either my understanding is incorrect or this is a bug. Could someone clarify? Thanks! -- https://bugs.ruby-lang.org/

Issue #20503 has been updated by kddnewton (Kevin Newton). For additional context, if you have: ```ruby <<~eos TEXT1 TEXT2 eos ``` you will get `"TEXT1\nTEXT2\n"`. But with a line continuation: ```ruby <<~eos \ TEXT1 TEXT2 eos ``` you get: `" TEXT1\n TEXT2\n"`. Even this seems incorrect because there is clearly common leading whitespace on both lines. ---------------------------------------- Misc #20503: Dedenting heredoc line continuation https://bugs.ruby-lang.org/issues/20503#change-108409 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- When there is a line continuation inside a dedenting heredoc, occasionally it will impact the dedent calculation in interesting ways. I'm not sure if it's a bug, or if my understanding is incorrect. ```ruby <<~eos TEXT eos ``` In this case the string is `"TEXT\n", because the common whitespace is 2 and it's removed from the only line. However if there is a line continuation: ```ruby <<~eos \ TEXT eos ``` then the results is `" TEXT\n"`. To me this seems incorrect, because the second line is supposed to be considered as part of the first, which would mean it should have the same result as the first one. So either my understanding is incorrect or this is a bug. Could someone clarify? Thanks! -- https://bugs.ruby-lang.org/

Issue #20503 has been updated by nobu (Nobuyoshi Nakada). Line continuations work before (or in an under layer of) here documents. For example, this is a syntax error, because `eos` line is continuing. ```ruby <<eos \ eos ``` Does this explanation make sense? ---------------------------------------- Misc #20503: Dedenting heredoc line continuation https://bugs.ruby-lang.org/issues/20503#change-108440 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- When there is a line continuation inside a dedenting heredoc, occasionally it will impact the dedent calculation in interesting ways. I'm not sure if it's a bug, or if my understanding is incorrect. ```ruby <<~eos TEXT eos ``` In this case the string is `"TEXT\n", because the common whitespace is 2 and it's removed from the only line. However if there is a line continuation: ```ruby <<~eos \ TEXT eos ``` then the results is `" TEXT\n"`. To me this seems incorrect, because the second line is supposed to be considered as part of the first, which would mean it should have the same result as the first one. So either my understanding is incorrect or this is a bug. Could someone clarify? Thanks! -- https://bugs.ruby-lang.org/

Issue #20503 has been updated by kddnewton (Kevin Newton). I'm not sure I understand. If they work before heredocs, shouldn't: ``` <<~eos \ TEXT1 TEXT2 eos ``` be equivalent to: ``` <<~eos TEXT1 TEXT2 eos ``` ? ---------------------------------------- Misc #20503: Dedenting heredoc line continuation https://bugs.ruby-lang.org/issues/20503#change-108451 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- When there is a line continuation inside a dedenting heredoc, occasionally it will impact the dedent calculation in interesting ways. I'm not sure if it's a bug, or if my understanding is incorrect. ```ruby <<~eos TEXT eos ``` In this case the string is `"TEXT\n", because the common whitespace is 2 and it's removed from the only line. However if there is a line continuation: ```ruby <<~eos \ TEXT eos ``` then the results is `" TEXT\n"`. To me this seems incorrect, because the second line is supposed to be considered as part of the first, which would mean it should have the same result as the first one. So either my understanding is incorrect or this is a bug. Could someone clarify? Thanks! -- https://bugs.ruby-lang.org/

Issue #20503 has been updated by akr (Akira Tanaka). A line continuation (backslash at the end of a line) in a string is a kind of escape sequence. Currently (I believe) "removing white spaces in line head" is done before "interpret escape sequences". The current behavior seems reasonable to me. If we exchange the order of "removing white spaces in line head" and "interpreting escape sequences", spaces after the escaped newline are considered as line head. I think it is not reasonable. For example, the following heredoc will be evaluated as "\nfoo\n". ``` <<~"EOS" \n foo EOS ``` The documentation can be improved: line continuation should be documented as an escape sequence. ---------------------------------------- Misc #20503: Dedenting heredoc line continuation https://bugs.ruby-lang.org/issues/20503#change-108453 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- When there is a line continuation inside a dedenting heredoc, occasionally it will impact the dedent calculation in interesting ways. I'm not sure if it's a bug, or if my understanding is incorrect. ```ruby <<~eos TEXT eos ``` In this case the string is `"TEXT\n", because the common whitespace is 2 and it's removed from the only line. However if there is a line continuation: ```ruby <<~eos \ TEXT eos ``` then the results is `" TEXT\n"`. To me this seems incorrect, because the second line is supposed to be considered as part of the first, which would mean it should have the same result as the first one. So either my understanding is incorrect or this is a bug. Could someone clarify? Thanks! -- https://bugs.ruby-lang.org/

Issue #20503 has been updated by kddnewton (Kevin Newton). I'm sorry I still seem to not be able to understand this. Maybe I am missing something. This heredoc: ```ruby <<-HERE \ TEXT1 TEXT2 HERE ``` gives `" TEXT1\n TEXT2\n"`. So it is exactly equivalent to: ```ruby <<-HERE TEXT1 TEXT2 HERE ``` In this case there are 2 common spaces at the beginning of the lines. Even if the line continuation were a kind of escape sequence, like `\a`, it would be: ```ruby <<-HERE \aTEXT1 TEXT2 HERE ``` there would still be 2 common spaces. So in either case, shouldn't the `<<~` be removing the common whitespace? ---------------------------------------- Misc #20503: Dedenting heredoc line continuation https://bugs.ruby-lang.org/issues/20503#change-108462 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- When there is a line continuation inside a dedenting heredoc, occasionally it will impact the dedent calculation in interesting ways. I'm not sure if it's a bug, or if my understanding is incorrect. ```ruby <<~eos TEXT eos ``` In this case the string is `"TEXT\n", because the common whitespace is 2 and it's removed from the only line. However if there is a line continuation: ```ruby <<~eos \ TEXT eos ``` then the results is `" TEXT\n"`. To me this seems incorrect, because the second line is supposed to be considered as part of the first, which would mean it should have the same result as the first one. So either my understanding is incorrect or this is a bug. Could someone clarify? Thanks! -- https://bugs.ruby-lang.org/

Issue #20503 has been updated by kddnewton (Kevin Newton). Status changed from Open to Closed I'm sorry I have misread what you said and I believe I understand now. If I am understanding correctly, line continuations cannot effect common whitespace calculations. So it is as if they were on different lines, and the second line has no leading whitespace so nothing is dedented. Thank you for your explanation and patience! ---------------------------------------- Misc #20503: Dedenting heredoc line continuation https://bugs.ruby-lang.org/issues/20503#change-108464 * Author: kddnewton (Kevin Newton) * Status: Closed ---------------------------------------- When there is a line continuation inside a dedenting heredoc, occasionally it will impact the dedent calculation in interesting ways. I'm not sure if it's a bug, or if my understanding is incorrect. ```ruby <<~eos TEXT eos ``` In this case the string is `"TEXT\n", because the common whitespace is 2 and it's removed from the only line. However if there is a line continuation: ```ruby <<~eos \ TEXT eos ``` then the results is `" TEXT\n"`. To me this seems incorrect, because the second line is supposed to be considered as part of the first, which would mean it should have the same result as the first one. So either my understanding is incorrect or this is a bug. Could someone clarify? Thanks! -- https://bugs.ruby-lang.org/
participants (3)
-
akr (Akira Tanaka)
-
kddnewton (Kevin Newton)
-
nobu (Nobuyoshi Nakada)