mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
1a3bcf103c
commit
a6a85a0cb7
3 changed files with 24 additions and 3 deletions
|
@ -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>
|
Mon Aug 26 15:27:39 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/timeout.rb (Timeout#timeout): should not be caught by rescue
|
* lib/timeout.rb (Timeout#timeout): should not be caught by rescue
|
||||||
|
|
15
parse.y
15
parse.y
|
@ -270,6 +270,8 @@ struct parser_params {
|
||||||
|
|
||||||
int parser_yydebug;
|
int parser_yydebug;
|
||||||
|
|
||||||
|
int last_cr_line;
|
||||||
|
|
||||||
#ifndef RIPPER
|
#ifndef RIPPER
|
||||||
/* Ruby core only */
|
/* Ruby core only */
|
||||||
NODE *parser_eval_tree_begin;
|
NODE *parser_eval_tree_begin;
|
||||||
|
@ -5329,6 +5331,7 @@ yycompile0(VALUE arg)
|
||||||
ruby_coverage = coverage(ruby_sourcefile_string, ruby_sourceline);
|
ruby_coverage = coverage(ruby_sourcefile_string, ruby_sourceline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
parser->last_cr_line = ruby_sourceline - 1;
|
||||||
|
|
||||||
parser_prepare(parser);
|
parser_prepare(parser);
|
||||||
deferred_nodes = 0;
|
deferred_nodes = 0;
|
||||||
|
@ -5611,9 +5614,15 @@ parser_nextc(struct parser_params *parser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c = (unsigned char)*lex_p++;
|
c = (unsigned char)*lex_p++;
|
||||||
if (c == '\r' && peek('\n')) {
|
if (c == '\r') {
|
||||||
lex_p++;
|
if (peek('\n')) {
|
||||||
c = '\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;
|
return c;
|
||||||
|
|
|
@ -385,6 +385,13 @@ eom
|
||||||
assert_syntax_error("__END__\r<<<<<\n", /unexpected <</)
|
assert_syntax_error("__END__\r<<<<<\n", /unexpected <</)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def not_label(x) @result = x; @not_label ||= nil end
|
def not_label(x) @result = x; @not_label ||= nil end
|
||||||
|
|
Loading…
Reference in a new issue