Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ruby/ruby
...
head fork: nobu/ruby
compare: warn_unary_space
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Nov 20, 2012
@nobu nobu parse.y: space after unary
* parse.y (warn_unary_space, parser_yylex): warn spaces after an unary
  operator.  [Bug #7331]
8775a3d
Showing with 7 additions and 0 deletions.
  1. +7 −0 parse.y
View
7 parse.y
@@ -6748,13 +6748,16 @@ parser_prepare(struct parser_params *parser)
#define ambiguous_operator(op, syn) ( \
rb_warning0("`"op"' after local variable is interpreted as binary operator"), \
rb_warning0("even though it seems like "syn""))
+#define space_after_unary(op) ((void)rb_warning0("space after unary `"op"' operator"))
#else
#define ambiguous_operator(op, syn) dispatch2(operator_ambiguous, ripper_intern(op), rb_str_new_cstr(syn))
+#define space_after_unary(op) dispatch1(space_after_unary, ripper_intern(op))
#endif
#define warn_balanced(op, syn) ((void) \
(!(last_state & (EXPR_CLASS|EXPR_DOT|EXPR_FNAME|EXPR_ENDFN|EXPR_ENDARG)) && \
space_seen && !ISSPACE(c) && \
(ambiguous_operator(op, syn), 0)))
+#define warn_unary_space(c, op) (void)(ISSPACE(c) && (space_after_unary(op), 0))
static int
parser_yylex(struct parser_params *parser)
@@ -7204,6 +7207,7 @@ parser_yylex(struct parser_params *parser)
if (c == '@') {
return tUPLUS;
}
+ warn_unary_space(c, "+");
pushback(c);
return '+';
}
@@ -7219,6 +7223,7 @@ parser_yylex(struct parser_params *parser)
c = '+';
goto start_num;
}
+ warn_unary_space(c, "+");
return tUPLUS;
}
lex_state = EXPR_BEG;
@@ -7233,6 +7238,7 @@ parser_yylex(struct parser_params *parser)
if (c == '@') {
return tUMINUS;
}
+ warn_unary_space(c, "-");
pushback(c);
return '-';
}
@@ -7251,6 +7257,7 @@ parser_yylex(struct parser_params *parser)
if (c != -1 && ISDIGIT(c)) {
return tUMINUS_NUM;
}
+ warn_unary_space(c, "-");
return tUMINUS;
}
lex_state = EXPR_BEG;

No commit comments for this range

Something went wrong with that request. Please try again.