summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-02-28 14:52:06 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-02-28 14:52:06 +0000
commita6da4f8ac7147cf2c7b29c54dc9f395f0038f30c (patch)
tree3c49edd2335a71185d8e3c0ea4f2e36be4623bd9 /parse.y
parent1cc19523c25029d66df15086de65b01a7dbe98f7 (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_4@67147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y21
1 files changed, 19 insertions, 2 deletions
diff --git a/parse.y b/parse.y
index ec2b056358..e25aac5b1c 100644
--- a/parse.y
+++ b/parse.y
@@ -6187,7 +6187,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;
@@ -6265,6 +6272,7 @@ parser_tokadd_string(struct parser_params *parser,
}
tokadd(c);
}
+ terminate:
*encp = enc;
return c;
}
@@ -6718,6 +6726,7 @@ parser_here_document(struct parser_params *parser, NODE *here)
long len;
VALUE str = 0;
rb_encoding *enc = current_enc;
+ int bol;
eos = RSTRING_PTR(here->nd_lit);
len = RSTRING_LEN(here->nd_lit) - 1;
@@ -6754,7 +6763,14 @@ parser_here_document(struct parser_params *parser, NODE *here)
heredoc_restore(lex_strterm);
return 0;
}
- if (was_bol() && whole_match_p(eos, len, indent)) {
+ bol = was_bol();
+ /* `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);
return tSTRING_END;
@@ -6825,6 +6841,7 @@ parser_here_document(struct parser_params *parser, NODE *here)
goto restore;
}
if (c != '\n') {
+ if (c == '\\') heredoc_line_indent = -1;
flush:
set_yylval_str(STR_NEW3(tok(), toklen(), enc, func));
flush_string_content(enc);