mirror of
https://github.com/ruby/ruby.git
synced 2025-08-26 14:34:39 +02:00
Warn if
and elsif
at EOL [EXPERIMENTAL]
It is unnatural and probably a typo.
This commit is contained in:
parent
cf377c5556
commit
ba35c14325
1 changed files with 22 additions and 0 deletions
22
parse.y
22
parse.y
|
@ -395,6 +395,12 @@ set_line_body(NODE *body, int line)
|
||||||
|
|
||||||
#define yyparse ruby_yyparse
|
#define yyparse ruby_yyparse
|
||||||
|
|
||||||
|
#define WARN_EOL(tok) \
|
||||||
|
(looking_at_eol_p(p) ? \
|
||||||
|
rb_warning0("`" tok "' at the end of line without an expression") : \
|
||||||
|
(void)0)
|
||||||
|
static int looking_at_eol_p(struct parser_params *p);
|
||||||
|
|
||||||
static NODE* cond(struct parser_params *p, NODE *node, const YYLTYPE *loc);
|
static NODE* cond(struct parser_params *p, NODE *node, const YYLTYPE *loc);
|
||||||
static NODE* method_cond(struct parser_params *p, NODE *node, const YYLTYPE *loc);
|
static NODE* method_cond(struct parser_params *p, NODE *node, const YYLTYPE *loc);
|
||||||
#define new_nil(loc) NEW_NIL(loc)
|
#define new_nil(loc) NEW_NIL(loc)
|
||||||
|
@ -3070,6 +3076,7 @@ k_begin : keyword_begin
|
||||||
|
|
||||||
k_if : keyword_if
|
k_if : keyword_if
|
||||||
{
|
{
|
||||||
|
WARN_EOL("if");
|
||||||
token_info_push(p, "if", &@$);
|
token_info_push(p, "if", &@$);
|
||||||
if (p->token_info && p->token_info->nonspc &&
|
if (p->token_info && p->token_info->nonspc &&
|
||||||
p->token_info->next && !strcmp(p->token_info->next->token, "else")) {
|
p->token_info->next && !strcmp(p->token_info->next->token, "else")) {
|
||||||
|
@ -3179,6 +3186,7 @@ k_else : keyword_else
|
||||||
|
|
||||||
k_elsif : keyword_elsif
|
k_elsif : keyword_elsif
|
||||||
{
|
{
|
||||||
|
WARN_EOL("elisif");
|
||||||
token_info_warn(p, "elsif", p->token_info, 1, &@$);
|
token_info_warn(p, "elsif", p->token_info, 1, &@$);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -6272,6 +6280,20 @@ pushback(struct parser_params *p, int c)
|
||||||
#define tok(p) (p)->tokenbuf
|
#define tok(p) (p)->tokenbuf
|
||||||
#define toklen(p) (p)->tokidx
|
#define toklen(p) (p)->tokidx
|
||||||
|
|
||||||
|
static int
|
||||||
|
looking_at_eol_p(struct parser_params *p)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
while ((c = nextc(p)) != -1) {
|
||||||
|
int eol = (c == '\n' || c == '#');
|
||||||
|
if (eol || !ISSPACE(c)) {
|
||||||
|
pushback(p, c);
|
||||||
|
return eol;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
newtok(struct parser_params *p)
|
newtok(struct parser_params *p)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue