ruby-changes:50705
From: nobu <ko1@a...>
Date: Wed, 21 Mar 2018 21:40:22 +0900 (JST)
Subject: [ruby-changes:50705] nobu:r62873 (trunk): parse.y: terminator at continued line
nobu 2018-03-21 21:40:16 +0900 (Wed, 21 Mar 2018) New Revision: 62873 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62873 Log: parse.y: terminator at continued line * parse.y (here_document): a continuing line is not the terminator. [ruby-core:86283] [Bug #14621] Modified files: trunk/parse.y trunk/test/ruby/test_syntax.rb Index: test/ruby/test_syntax.rb =================================================================== --- test/ruby/test_syntax.rb (revision 62872) +++ test/ruby/test_syntax.rb (revision 62873) @@ -725,6 +725,18 @@ e" https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L725 result = " 1\\\n" " 2\n" expected = "1\\\n" "2\n" assert_dedented_heredoc(expected, result) + assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't find string "TEXT"/) + begin; + <<-TEXT + \ + TEXT + end; + assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't find string "TEXT"/) + begin; + <<~TEXT + \ + TEXT + end; end def test_lineno_after_heredoc Index: parse.y =================================================================== --- parse.y (revision 62872) +++ parse.y (revision 62873) @@ -6301,7 +6301,13 @@ here_document(struct parser_params *p, r https://github.com/ruby/ruby/blob/trunk/parse.y#L6301 return 0; } bol = was_bol(p); - if (bol && whole_match_p(p, eos, len, indent)) { + /* `heredoc_line_indent == -1` means + * - "after an interpolation in the same line", or + * - "in a continuing line" + */ + if (bol && + (p->heredoc_line_indent != -1 || (p->heredoc_line_indent = 0)) && + whole_match_p(p, eos, len, indent)) { dispatch_heredoc_end(p); heredoc_restore(p, &p->lex.strterm->u.heredoc); p->lex.strterm = 0; @@ -6371,6 +6377,7 @@ here_document(struct parser_params *p, r https://github.com/ruby/ruby/blob/trunk/parse.y#L6377 goto restore; } if (c != '\n') { + if (c == '\\') p->heredoc_line_indent = -1; flush: str = STR_NEW3(tok(p), toklen(p), enc, func); flush_str: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/