ruby-changes:50733
From: naruse <ko1@a...>
Date: Sat, 24 Mar 2018 20:43:56 +0900 (JST)
Subject: [ruby-changes:50733] naruse:r62909 (ruby_2_5): merge revision(s) 62723, 62724: [Backport #14584]
naruse 2018-03-24 20:43:50 +0900 (Sat, 24 Mar 2018) New Revision: 62909 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62909 Log: merge revision(s) 62723,62724: [Backport #14584] parse.y: reduce duplicate code parse.y: fix interpolated string literal dedent * parse.y (heredoc_dedent): fix interpolated string literal dedent, remove indentations from only nodes with the newline flag. [ruby-core:85983] [Bug #14584] * parse.y (here_document): set the newline flag on literal string nodes starting at the beginning of line. Modified directories: branches/ruby_2_5/ Modified files: branches/ruby_2_5/parse.y branches/ruby_2_5/test/ruby/test_syntax.rb branches/ruby_2_5/version.h Index: ruby_2_5/test/ruby/test_syntax.rb =================================================================== --- ruby_2_5/test/ruby/test_syntax.rb (revision 62908) +++ ruby_2_5/test/ruby/test_syntax.rb (revision 62909) @@ -667,6 +667,12 @@ e" https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_syntax.rb#L667 assert_dedented_heredoc(expected, result) end + def test_dedented_heredoc_expr_string + result = ' one#{" two "}'"\n" + expected = 'one#{" two "}'"\n" + assert_dedented_heredoc(expected, result) + end + def test_lineno_after_heredoc bug7559 = '[ruby-dev:46737]' expected, _, actual = __LINE__, <<eom, __LINE__ Index: ruby_2_5/parse.y =================================================================== --- ruby_2_5/parse.y (revision 62908) +++ ruby_2_5/parse.y (revision 62909) @@ -6817,7 +6817,6 @@ static NODE * https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L6817 parser_heredoc_dedent(struct parser_params *parser, NODE *root) { NODE *node, *str_node; - int bol = TRUE; int indent = heredoc_indent; if (indent <= 0) return root; @@ -6829,15 +6828,15 @@ parser_heredoc_dedent(struct parser_para https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L6828 while (str_node) { VALUE lit = str_node->nd_lit; - if (bol) dedent_string(lit, indent); - bol = TRUE; + if (str_node->flags & NODE_FL_NEWLINE) { + dedent_string(lit, indent); + } str_node = 0; while ((node = node->nd_next) != 0 && nd_type(node) == NODE_ARRAY) { if ((str_node = node->nd_head) != 0) { enum node_type type = nd_type(str_node); if (type == NODE_STR || type == NODE_DSTR) break; - bol = FALSE; str_node = 0; } } @@ -6980,6 +6979,7 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L6979 long len; VALUE str = 0; rb_encoding *enc = current_enc; + int bol; eos = RSTRING_PTR(here->term); len = RSTRING_LEN(here->term) - 2; /* here->term includes term_len and func */ @@ -7018,7 +7018,8 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L7018 lex_strterm = 0; return 0; } - if (was_bol() && whole_match_p(eos, len, indent)) { + bol = was_bol(); + if (bol && whole_match_p(eos, len, indent)) { dispatch_heredoc_end(); heredoc_restore(&lex_strterm->u.heredoc); lex_strterm = 0; @@ -7056,10 +7057,7 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L7057 if (pend < lex_pend) rb_str_cat(str, "\n", 1); lex_goto_eol(parser); if (heredoc_indent > 0) { - set_yylval_str(str); - add_mark_object(str); - flush_string_content(enc); - return tSTRING_CONTENT; + goto flush_str; } if (nextc() == -1) { if (str) { @@ -7092,10 +7090,14 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L7090 goto restore; } if (c != '\n') { - VALUE lit; flush: - add_mark_object(lit = STR_NEW3(tok(), toklen(), enc, func)); - set_yylval_str(lit); + str = STR_NEW3(tok(), toklen(), enc, func); + flush_str: + set_yylval_str(str); + add_mark_object(str); +#ifndef RIPPER + if (bol) yylval.node->flags |= NODE_FL_NEWLINE; +#endif flush_string_content(enc); return tSTRING_CONTENT; } @@ -7118,6 +7120,9 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/ruby_2_5/parse.y#L7120 lex_strterm = NEW_STRTERM(func | STR_FUNC_TERM, 0, 0); set_yylval_str(str); add_mark_object(str); +#ifndef RIPPER + if (bol) yylval.node->flags |= NODE_FL_NEWLINE; +#endif return tSTRING_CONTENT; } Index: ruby_2_5/version.h =================================================================== --- ruby_2_5/version.h (revision 62908) +++ ruby_2_5/version.h (revision 62909) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.1" #define RUBY_RELEASE_DATE "2018-03-24" -#define RUBY_PATCHLEVEL 51 +#define RUBY_PATCHLEVEL 52 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 3 Index: ruby_2_5 =================================================================== --- ruby_2_5 (revision 62908) +++ ruby_2_5 (revision 62909) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r62723-62724 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/