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

ruby-changes:30612

From: nobu <ko1@a...>
Date: Mon, 26 Aug 2013 16:25:15 +0900 (JST)
Subject: [ruby-changes:30612] nobu:r42691 (trunk): parse.y: warn CR

nobu	2013-08-26 16:25:08 +0900 (Mon, 26 Aug 2013)

  New Revision: 42691

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

  Log:
    parse.y: warn CR
    
    * parse.y (parser_nextc): warn carriage return in middle of line.
      [ruby-core:56240] [Feature #8699]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42690)
+++ ChangeLog	(revision 42691)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Aug 26 16:24:58 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (parser_nextc): warn carriage return in middle of line.
+	  [ruby-core:56240] [Feature #8699]
+
 Mon Aug 26 15:27:39 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/timeout.rb (Timeout#timeout): should not be caught by rescue
Index: parse.y
===================================================================
--- parse.y	(revision 42690)
+++ parse.y	(revision 42691)
@@ -270,6 +270,8 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L270
 
     int parser_yydebug;
 
+    int last_cr_line;
+
 #ifndef RIPPER
     /* Ruby core only */
     NODE *parser_eval_tree_begin;
@@ -5329,6 +5331,7 @@ yycompile0(VALUE arg) https://github.com/ruby/ruby/blob/trunk/parse.y#L5331
 	    ruby_coverage = coverage(ruby_sourcefile_string, ruby_sourceline);
 	}
     }
+    parser->last_cr_line = ruby_sourceline - 1;
 
     parser_prepare(parser);
     deferred_nodes = 0;
@@ -5611,9 +5614,15 @@ parser_nextc(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L5614
 	}
     }
     c = (unsigned char)*lex_p++;
-    if (c == '\r' && peek('\n')) {
-	lex_p++;
-	c = '\n';
+    if (c == '\r') {
+	if (peek('\n')) {
+	    lex_p++;
+	    c = '\n';
+	}
+	else if (ruby_sourceline > parser->last_cr_line) {
+	    parser->last_cr_line = ruby_sourceline;
+	    rb_compile_warn(ruby_sourcefile, ruby_sourceline, "encountered \\r in mddile of line, treat as a mere space");
+	}
     }
 
     return c;
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 42690)
+++ test/ruby/test_syntax.rb	(revision 42691)
@@ -385,6 +385,13 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L385
     assert_syntax_error("__END__\r<<<<<\n", /unexpected <</)
   end
 
+  def test_warning_for_cr
+    feature8699 = '[ruby-core:56240] [Feature #8699]'
+    assert_warning(/encountered \\r/, feature8699) do
+      eval("\r""__id__\r")
+    end
+  end
+
   private
 
   def not_label(x) @result = x; @not_label ||= nil end

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

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