diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-21 03:15:49 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-21 03:15:49 +0000 |
commit | 2e1efa94993dee9b54ac4c9f4c58a06f41ed3232 (patch) | |
tree | 45633416f13d08b625a135810bad0b2046ab9438 /parse.y | |
parent | a7df5ace7e13760c9c175a6de3273bffb50346d4 (diff) | |
download | ruby-2e1efa94993dee9b54ac4c9f4c58a06f41ed3232.tar.gz |
* parse.y (parser_yylex): warn confusing binary operators after
local variable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -6418,6 +6418,15 @@ parser_prepare(struct parser_params *parser) #define IS_BEG() (lex_state == EXPR_BEG || lex_state == EXPR_MID || lex_state == EXPR_VALUE || lex_state == EXPR_CLASS) #define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c)) +#ifndef RIPPER +#define ambiguous_operator(op, syn) ( \ + rb_warning0("`"op"' after local variable is interpreted as binary operator"), \ + rb_warning0("even though it seems like "syn"")) +#else +#define ambiguous_operator(op, syn) dispatch2(operator_ambiguous, ripper_intern(op), rb_str_new_cstr(syn)) +#endif +#define warn_balanced(op, syn) (space_seen && !ISSPACE(c) && (ambiguous_operator(op, syn), 0)) + static int parser_yylex(struct parser_params *parser) { @@ -6463,7 +6472,7 @@ parser_yylex(struct parser_params *parser) /* white spaces */ case ' ': case '\t': case '\f': case '\r': case '\13': /* '\v' */ - space_seen++; + space_seen = 1; #ifdef RIPPER while ((c = nextc())) { switch (c) { @@ -6514,7 +6523,7 @@ parser_yylex(struct parser_params *parser) switch (c) { case ' ': case '\t': case '\f': case '\r': case '\13': /* '\v' */ - space_seen++; + space_seen = 1; break; case '.': { if ((c = nextc()) != '.') { @@ -6566,6 +6575,7 @@ parser_yylex(struct parser_params *parser) c = tSTAR; } else { + warn_balanced("*", "argument prefix"); c = '*'; } } @@ -6686,6 +6696,7 @@ parser_yylex(struct parser_params *parser) return tOP_ASGN; } pushback(c); + warn_balanced("<<", "here document"); return tLSHFT; } pushback(c); @@ -6836,6 +6847,7 @@ parser_yylex(struct parser_params *parser) c = tAMPER; } else { + warn_balanced("&", "argument prefix"); c = '&'; } switch (lex_state) { @@ -6897,6 +6909,7 @@ parser_yylex(struct parser_params *parser) } lex_state = EXPR_BEG; pushback(c); + warn_balanced("+", "unary operator"); return '+'; case '-': @@ -6928,6 +6941,7 @@ parser_yylex(struct parser_params *parser) } lex_state = EXPR_BEG; pushback(c); + warn_balanced("-", "unary operator"); return '-'; case '.': @@ -7230,6 +7244,7 @@ parser_yylex(struct parser_params *parser) default: lex_state = EXPR_BEG; break; } + warn_balanced("/", "regexp literal"); return '/'; case '^': @@ -7422,6 +7437,7 @@ parser_yylex(struct parser_params *parser) lex_state = EXPR_BEG; break; } pushback(c); + warn_balanced("%%", "string literal"); return '%'; case '$': |