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

ruby-changes:30456

From: nobu <ko1@a...>
Date: Mon, 12 Aug 2013 16:00:06 +0900 (JST)
Subject: [ruby-changes:30456] nobu:r42535 (trunk): parse.y: CR in middle

nobu	2013-08-12 15:59:57 +0900 (Mon, 12 Aug 2013)

  New Revision: 42535

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42535

  Log:
    parse.y: CR in middle
    
    * parse.y (parser_whole_match_p): treat CR in middle of a line as a
      mere whitespace.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42534)
+++ ChangeLog	(revision 42535)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Aug 12 15:59:50 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (parser_whole_match_p): treat CR in middle of a line as a
+	  mere whitespace.
+
 Mon Aug 12 15:16:58 2013  Koichi Sasada  <ko1@a...>
 
 	* class.c (rb_prepend_module): make T_ICLASS object shady because
Index: parse.y
===================================================================
--- parse.y	(revision 42534)
+++ parse.y	(revision 42535)
@@ -6375,7 +6375,11 @@ parser_whole_match_p(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L6375
 	while (*p && ISSPACE(*p)) p++;
     }
     n = lex_pend - (p + len);
-    if (n < 0 || (n > 0 && p[len] != '\n' && p[len] != '\r')) return FALSE;
+    if (n < 0) return FALSE;
+    if (n > 0 && p[len] != '\n') {
+	if (p[len] != '\r') return FALSE;
+	if (n <= 1 || p[len+1] != '\n') return FALSE;
+    }
     return strncmp(eos, p, len) == 0;
 }
 
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 42534)
+++ test/ruby/test_syntax.rb	(revision 42535)
@@ -377,6 +377,14 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L377
     EOS
   end
 
+  def test_heredoc_cr
+    assert_syntax_error("puts <<""EOS\n""ng\n""EOS\r""NO\n", /can't find string "EOS" anywhere before EOF/)
+  end
+
+  def test__END___cr
+    assert_syntax_error("__END__\r<<<<<\n", /unexpected <</)
+  end
+
   private
 
   def not_label(x) @result = x; @not_label ||= nil end

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

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