summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-02-11 11:04:41 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-02-11 11:04:41 +0000
commit76ee1d849414321047fed683b81583bc2ab14d4c (patch)
tree6b12d5ca96284ab1cd3ff4b2da6480972047060e /parse.y
parent9b80483fc832267ed733b1e239d5be1869414b08 (diff)
merge revision(s) 62872,62873: [Backport #14621]
parse.y: unindent continued line * parse.y (tokadd_string): stop at continued line in dedented here documents, to dedent for each lines before removing escaped newlines. [ruby-core:86236] [Bug #14621] parse.y: terminator at continued line * parse.y (here_document): a continuing line is not the terminator. [ruby-core:86283] [Bug #14621] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y19
1 files changed, 17 insertions, 2 deletions
diff --git a/parse.y b/parse.y
index 1348842b91..3b3bd7a4ca 100644
--- a/parse.y
+++ b/parse.y
@@ -6394,7 +6394,14 @@ parser_tokadd_string(struct parser_params *parser,
switch (c) {
case '\n':
if (func & STR_FUNC_QWORDS) break;
- if (func & STR_FUNC_EXPAND) continue;
+ if (func & STR_FUNC_EXPAND) {
+ if (!(func & STR_FUNC_INDENT) || (heredoc_indent < 0))
+ continue;
+ if (c == term) {
+ c = '\\';
+ goto terminate;
+ }
+ }
tokadd('\\');
break;
@@ -6475,6 +6482,7 @@ parser_tokadd_string(struct parser_params *parser,
}
tokadd(c);
}
+ terminate:
if (enc) *encp = enc;
return c;
}
@@ -7019,7 +7027,13 @@ parser_here_document(struct parser_params *parser, rb_strterm_heredoc_t *here)
return 0;
}
bol = was_bol();
- if (bol && whole_match_p(eos, len, indent)) {
+ /* `heredoc_line_indent == -1` means
+ * - "after an interpolation in the same line", or
+ * - "in a continuing line"
+ */
+ if (bol &&
+ (heredoc_line_indent != -1 || (heredoc_line_indent = 0)) &&
+ whole_match_p(eos, len, indent)) {
dispatch_heredoc_end();
heredoc_restore(&lex_strterm->u.heredoc);
lex_strterm = 0;
@@ -7090,6 +7104,7 @@ parser_here_document(struct parser_params *parser, rb_strterm_heredoc_t *here)
goto restore;
}
if (c != '\n') {
+ if (c == '\\') heredoc_line_indent = -1;
flush:
str = STR_NEW3(tok(), toklen(), enc, func);
flush_str: