ruby-changes:45016
From: nobu <ko1@a...>
Date: Fri, 16 Dec 2016 10:27:51 +0900 (JST)
Subject: [ruby-changes:45016] nobu:r57089 (trunk): multiline heredoc identifier
nobu 2016-12-16 10:27:47 +0900 (Fri, 16 Dec 2016) New Revision: 57089 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57089 Log: multiline heredoc identifier * parse.y (parser_heredoc_identifier): reject multiline here document identifier, which never matches single line. Modified files: trunk/parse.y trunk/test/ruby/test_syntax.rb Index: parse.y =================================================================== --- parse.y (revision 57088) +++ parse.y (revision 57089) @@ -6434,13 +6434,20 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6434 while ((c = nextc()) != -1 && c != term) { if (tokadd_mbchar(c) == -1) return 0; if (c == '\n') newline = 1; + else if (newline) newline = 2; } if (c == -1) { compile_error(PARSER_ARG "unterminated here document identifier"); return 0; } - if (newline) { - rb_warn0("here document identifier contains newline"); + switch (newline) { + case 1: + rb_warn0("here document identifier ends with a newline"); + if (--tokidx > 0 && tokenbuf[tokidx] == '\r') --tokidx; + break; + case 2: + compile_error(PARSER_ARG "here document identifier across newlines, never match"); + return -1; } break; Index: test/ruby/test_syntax.rb =================================================================== --- test/ruby/test_syntax.rb (revision 57088) +++ test/ruby/test_syntax.rb (revision 57089) @@ -746,7 +746,7 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L746 end def test_heredoc_newline - assert_warn(/contains newline/) do + assert_warn(/ends with a newline/) do eval("<<\"EOS\n\"\nEOS\n") end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/