ruby-changes:42154
From: nobu <ko1@a...>
Date: Tue, 22 Mar 2016 14:19:09 +0900 (JST)
Subject: [ruby-changes:42154] nobu:r54228 (trunk): parse.y: lambda indentation check
nobu 2016-03-22 14:19:01 +0900 (Tue, 22 Mar 2016) New Revision: 54228 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54228 Log: parse.y: lambda indentation check * parse.y (lambda_body, parser_yylex): warn mismatched indentation of lambda block. Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ruby/test_rubyoptions.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 54227) +++ ChangeLog (revision 54228) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Mar 22 14:18:59 2016 Nobuyoshi Nakada <nobu@r...> + + * parse.y (lambda_body, parser_yylex): warn mismatched indentation + of lambda block. + Tue Mar 22 11:36:49 2016 NAKAMURA Usaku <usa@r...> * time.c (wmul): wrong condition. Index: parse.y =================================================================== --- parse.y (revision 54227) +++ parse.y (revision 54228) @@ -767,10 +767,10 @@ static void parser_compile_error(struct https://github.com/ruby/ruby/blob/trunk/parse.y#L767 #endif #endif -static void token_info_push(struct parser_params*, const char *token, size_t len); -static void token_info_pop(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_pop(token) token_info_pop(parser, (token), rb_strlen_lit(token)) +static void token_info_push_gen(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_gen(parser, (token), rb_strlen_lit(token)) +#define token_info_pop(token) token_info_pop_gen(parser, (token), rb_strlen_lit(token)) %} %pure-parser @@ -3587,9 +3587,10 @@ f_larglist : '(' f_args opt_bv_decl ')' https://github.com/ruby/ruby/blob/trunk/parse.y#L3587 lambda_body : tLAMBEG compstmt '}' { + token_info_pop("}"); $$ = $2; } - | keyword_do_LAMBDA compstmt keyword_end + | keyword_do_LAMBDA compstmt k_end { $$ = $2; } @@ -5372,9 +5373,8 @@ token_info_has_nonspaces(struct parser_p https://github.com/ruby/ruby/blob/trunk/parse.y#L5373 return 0; } -#undef token_info_push 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; const char *t = lex_p - len; @@ -5390,9 +5390,8 @@ token_info_push(struct parser_params *pa https://github.com/ruby/ruby/blob/trunk/parse.y#L5390 parser->token_info = ptinfo; } -#undef token_info_pop 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; token_info *ptinfo = parser->token_info; @@ -8527,6 +8526,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8526 } if (c == '>') { SET_LEX_STATE(EXPR_ENDFN); + token_info_push("->"); return tLAMBDA; } if (IS_BEG() || (IS_SPCARG(c) && arg_ambiguous('-'))) { Index: test/ruby/test_rubyoptions.rb =================================================================== --- test/ruby/test_rubyoptions.rb (revision 54227) +++ test/ruby/test_rubyoptions.rb (revision 54228) @@ -395,6 +395,7 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L395 [ "begin", "if false", "for _ in []", "while false", "def foo", "class X", "module M", + ["-> do", "end"], ["-> {", "}"], ].each do |b, e = 'end'| src = ["#{b}\n", " #{e}\n"] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/