parse.y: lambda indentation check

* parse.y (lambda_body, parser_yylex): warn mismatched indentation
  of lambda block.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-03-22 05:19:01 +00:00
Родитель 8c22a641d9
Коммит bf99f85941
3 изменённых файлов: 15 добавлений и 9 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Tue Mar 22 14:18:59 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (lambda_body, parser_yylex): warn mismatched indentation
of lambda block.
Tue Mar 22 11:36:49 2016 NAKAMURA Usaku <usa@ruby-lang.org> Tue Mar 22 11:36:49 2016 NAKAMURA Usaku <usa@ruby-lang.org>
* time.c (wmul): wrong condition. * time.c (wmul): wrong condition.

18
parse.y
Просмотреть файл

@ -767,10 +767,10 @@ static void parser_compile_error(struct parser_params*, const char *fmt, ...);
#endif #endif
#endif #endif
static void token_info_push(struct parser_params*, const char *token, size_t len); static void token_info_push_gen(struct parser_params*, const char *token, size_t len);
static void token_info_pop(struct parser_params*, const char *token, size_t len); static void token_info_pop_gen(struct parser_params*, const char *token, size_t len);
#define token_info_push(token) token_info_push(parser, (token), rb_strlen_lit(token)) #define token_info_push(token) token_info_push_gen(parser, (token), rb_strlen_lit(token))
#define token_info_pop(token) token_info_pop(parser, (token), rb_strlen_lit(token)) #define token_info_pop(token) token_info_pop_gen(parser, (token), rb_strlen_lit(token))
%} %}
%pure-parser %pure-parser
@ -3587,9 +3587,10 @@ f_larglist : '(' f_args opt_bv_decl ')'
lambda_body : tLAMBEG compstmt '}' lambda_body : tLAMBEG compstmt '}'
{ {
token_info_pop("}");
$$ = $2; $$ = $2;
} }
| keyword_do_LAMBDA compstmt keyword_end | keyword_do_LAMBDA compstmt k_end
{ {
$$ = $2; $$ = $2;
} }
@ -5372,9 +5373,8 @@ token_info_has_nonspaces(struct parser_params *parser, const char *pend)
return 0; return 0;
} }
#undef token_info_push
static void static void
token_info_push(struct parser_params *parser, const char *token, size_t len) token_info_push_gen(struct parser_params *parser, const char *token, size_t len)
{ {
token_info *ptinfo; token_info *ptinfo;
const char *t = lex_p - len; const char *t = lex_p - len;
@ -5390,9 +5390,8 @@ token_info_push(struct parser_params *parser, const char *token, size_t len)
parser->token_info = ptinfo; parser->token_info = ptinfo;
} }
#undef token_info_pop
static void static void
token_info_pop(struct parser_params *parser, const char *token, size_t len) token_info_pop_gen(struct parser_params *parser, const char *token, size_t len)
{ {
int linenum; int linenum;
token_info *ptinfo = parser->token_info; token_info *ptinfo = parser->token_info;
@ -8527,6 +8526,7 @@ parser_yylex(struct parser_params *parser)
} }
if (c == '>') { if (c == '>') {
SET_LEX_STATE(EXPR_ENDFN); SET_LEX_STATE(EXPR_ENDFN);
token_info_push("->");
return tLAMBDA; return tLAMBDA;
} }
if (IS_BEG() || (IS_SPCARG(c) && arg_ambiguous('-'))) { if (IS_BEG() || (IS_SPCARG(c) && arg_ambiguous('-'))) {

Просмотреть файл

@ -395,6 +395,7 @@ class TestRubyOptions < Test::Unit::TestCase
[ [
"begin", "if false", "for _ in []", "while false", "begin", "if false", "for _ in []", "while false",
"def foo", "class X", "module M", "def foo", "class X", "module M",
["-> do", "end"], ["-> {", "}"],
].each do ].each do
|b, e = 'end'| |b, e = 'end'|
src = ["#{b}\n", " #{e}\n"] src = ["#{b}\n", " #{e}\n"]