From a6a85a0cb755f4e65fd15c2554c5bcd529c66ed9 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 26 Aug 2013 07:25:08 +0000 Subject: [PATCH] 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 --- ChangeLog | 5 +++++ parse.y | 15 ++++++++++++--- test/ruby/test_syntax.rb | 7 +++++++ 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 + + * 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 * 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 <