[前][次][番号順一覧][スレッド一覧]

ruby-changes:45012

From: nobu <ko1@a...>
Date: Thu, 15 Dec 2016 21:59:06 +0900 (JST)
Subject: [ruby-changes:45012] nobu:r57085 (trunk): parse.y: newline in heredoc identifier

nobu	2016-12-15 21:58:59 +0900 (Thu, 15 Dec 2016)

  New Revision: 57085

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57085

  Log:
    parse.y: newline in heredoc identifier
    
    * parse.y (parser_heredoc_identifier): warn newline in here
      document identifier.

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 57084)
+++ test/ruby/test_syntax.rb	(revision 57085)
@@ -745,6 +745,12 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L745
     assert_syntax_error("puts <<""EOS\n""ng\n""EOS\r""NO\n", /can't find string "EOS" anywhere before EOF/)
   end
 
+  def test_heredoc_newline
+    assert_warn(/contains newline/) do
+      eval("<<\"EOS\n\"\nEOS\n")
+    end
+  end
+
   def test__END___cr
     assert_syntax_error("__END__\r<<<<<\n", /unexpected <</)
   end
Index: parse.y
===================================================================
--- parse.y	(revision 57084)
+++ parse.y	(revision 57085)
@@ -6406,6 +6406,7 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6406
     int c = nextc(), term, func = 0;
     int token = tSTRING_BEG;
     long len;
+    int newline = 0;
 
     if (c == '-') {
 	c = nextc();
@@ -6432,11 +6433,15 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6433
 	term = c;
 	while ((c = nextc()) != -1 && c != term) {
 	    if (tokadd_mbchar(c) == -1) return 0;
+	    if (c == '\n') newline = 1;
 	}
 	if (c == -1) {
 	    compile_error(PARSER_ARG "unterminated here document identifier");
 	    return 0;
 	}
+	if (newline) {
+	    rb_warn0("here document identifier contains newline");
+	}
 	break;
 
       default:

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]