aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-26 07:25:08 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-26 07:25:08 +0000
commita6a85a0cb755f4e65fd15c2554c5bcd529c66ed9 (patch)
tree35754fad15d6ece5bf7871c0bdea66aff4581494
parent1a3bcf103c582b20e9ea70dfed0ee68b24243f55 (diff)
downloadruby-a6a85a0cb755f4e65fd15c2554c5bcd529c66ed9.tar.gz
parse.y: warn CR
* parse.y (parser_nextc): warn carriage return in middle of line. [ruby-core:56240] [Feature #8699] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--parse.y15
-rw-r--r--test/ruby/test_syntax.rb7
3 files changed, 24 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index b1c05dedbb..13a4787221 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Aug 26 16:24:58 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* lib/timeout.rb (Timeout#timeout): should not be caught by rescue
diff --git a/parse.y b/parse.y
index 76fc9e7104..4af44c0d77 100644
--- a/parse.y
+++ b/parse.y
@@ -270,6 +270,8 @@ struct parser_params {
int parser_yydebug;
+ int last_cr_line;
+
#ifndef RIPPER
/* Ruby core only */
NODE *parser_eval_tree_begin;
@@ -5329,6 +5331,7 @@ yycompile0(VALUE arg)
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 *parser)
}
}
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;
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index f5ff8a7810..04fcd20a56 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -385,6 +385,13 @@ eom
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