зеркало из https://github.com/github/ruby.git
Warn EOF char in comment
This commit is contained in:
Родитель
ade0388894
Коммит
69ec3f70fa
29
parse.y
29
parse.y
|
@ -6191,7 +6191,30 @@ parser_str_new(const char *ptr, long len, rb_encoding *enc, int func, rb_encodin
|
|||
return str;
|
||||
}
|
||||
|
||||
#define lex_goto_eol(p) ((p)->lex.pcur = (p)->lex.pend)
|
||||
static const char *
|
||||
eof_char(int c)
|
||||
{
|
||||
switch (c) {
|
||||
case '\0': return "\\0";
|
||||
case '\004': return "^D";
|
||||
case '\032': return "^Z";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
lex_goto_eol(struct parser_params *p)
|
||||
{
|
||||
const char *pcur = p->lex.pcur, *pend = p->lex.pend;
|
||||
for (; pcur < pend; pcur++) {
|
||||
const char *eof = eof_char(*pcur);
|
||||
if (eof) {
|
||||
rb_warning1("encountered %s in comment, just ignored in this version", WARN_S(eof));
|
||||
break;
|
||||
}
|
||||
}
|
||||
p->lex.pcur = pend; /* pcur */
|
||||
}
|
||||
#define lex_eol_p(p) ((p)->lex.pcur >= (p)->lex.pend)
|
||||
#define lex_eol_n_p(p,n) ((p)->lex.pcur+(n) >= (p)->lex.pend)
|
||||
#define peek(p,c) peek_n(p, (c), 0)
|
||||
|
@ -7398,9 +7421,7 @@ word_match_p(struct parser_params *p, const char *word, long len)
|
|||
if (p->lex.pcur + len == p->lex.pend) return 1;
|
||||
int c = (unsigned char)p->lex.pcur[len];
|
||||
if (ISSPACE(c)) return 1;
|
||||
switch (c) {
|
||||
case '\0': case '\004': case '\032': return 1;
|
||||
}
|
||||
if (eof_char(c)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -720,6 +720,15 @@ x = __ENCODING__
|
|||
assert_syntax_error("=begin", error)
|
||||
end
|
||||
|
||||
def test_embedded_rd_warning
|
||||
[["\0", "\\0"], ["\C-d", "^D"], ["\C-z", "^Z"]].each do |eof, mesg|
|
||||
mesg = /encountered #{Regexp.quote(mesg)}/
|
||||
assert_warning(mesg) {eval("=begin\n#{eof}\n=end")}
|
||||
assert_warning(mesg) {eval("=begin#{eof}\n=end")}
|
||||
assert_warning(mesg) {eval("=begin\n=end#{eof}\n")}
|
||||
end
|
||||
end
|
||||
|
||||
def test_float
|
||||
assert_equal(1.0/0, eval("1e10000"))
|
||||
assert_syntax_error('1_E', /trailing `_'/)
|
||||
|
|
|
@ -943,6 +943,12 @@ eom
|
|||
end
|
||||
end
|
||||
|
||||
def test_warning_for_eof_in_comment
|
||||
assert_warning(/encountered \\0/) {eval("#\0")}
|
||||
assert_warning(/encountered \^D/) {eval("#\C-d")}
|
||||
assert_warning(/encountered \^Z/) {eval("#\C-z")}
|
||||
end
|
||||
|
||||
def test_unexpected_fraction
|
||||
msg = /unexpected fraction/
|
||||
assert_syntax_error("0x0.0", msg)
|
||||
|
|
Загрузка…
Ссылка в новой задаче