summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--parse.y20
2 files changed, 23 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index d5733fb4e3..9e328147ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Apr 21 12:15:46 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (parser_yylex): warn confusing binary operators after
+ local variable.
+
Wed Apr 21 11:53:47 2010 Eric Hodel <drbrain@segment7.net>
* lib/rdoc: Update to RDoc 2.5.5. Fixes bugs in ri, Darkfish and
diff --git a/parse.y b/parse.y
index f8ff74e406..9603d61670 100644
--- a/parse.y
+++ b/parse.y
@@ -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 '$':