ruby-changes:44200
From: nobu <ko1@a...>
Date: Tue, 27 Sep 2016 23:22:37 +0900 (JST)
Subject: [ruby-changes:44200] nobu:r56273 (trunk): parse.y: fix up r56198
nobu 2016-09-27 23:22:33 +0900 (Tue, 27 Sep 2016) New Revision: 56273 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56273 Log: parse.y: fix up r56198 * parse.y (symbol, dsym, parser_set_number_literal): set state to ENDARG, so that `do` after a literal should be `do_block` and bound to the outer method. [ruby-core:72482] [Bug #11873] * parse.y (parse_ident): revert r56198. * parse.y (warn_balanced): the state of symbol and numeric literals is now EXPR_ENDARG, do not exclude it. Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ruby/test_syntax.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 56272) +++ ChangeLog (revision 56273) @@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Sep 27 23:22:31 2016 Nobuyoshi Nakada <nobu@r...> + + * parse.y (symbol, dsym, parser_set_number_literal): set state to + ENDARG, so that `do` after a literal should be `do_block` and + bound to the outer method. [ruby-core:72482] [Bug #11873] + + * parse.y (parse_ident): revert r56198. + + * parse.y (warn_balanced): the state of symbol and numeric + literals is now EXPR_ENDARG, do not exclude it. + Tue Sep 27 22:59:42 2016 URABE Shyouhei <shyouhei@r...> * NEWS: news about Warning.warning. Index: parse.y =================================================================== --- parse.y (revision 56272) +++ parse.y (revision 56273) @@ -4261,7 +4261,7 @@ string_dvar : tGVAR https://github.com/ruby/ruby/blob/trunk/parse.y#L4261 symbol : tSYMBEG sym { - SET_LEX_STATE(EXPR_END); + SET_LEX_STATE(EXPR_ENDARG); /*%%%*/ $$ = $2; /*% @@ -4278,7 +4278,7 @@ sym : fname https://github.com/ruby/ruby/blob/trunk/parse.y#L4278 dsym : tSYMBEG xstring_contents tSTRING_END { - SET_LEX_STATE(EXPR_END); + SET_LEX_STATE(EXPR_ENDARG); /*%%%*/ $$ = dsym_node($2); /*% @@ -6637,6 +6637,7 @@ parser_set_number_literal(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6637 type = tIMAGINARY; } set_yylval_literal(v); + SET_LEX_STATE(EXPR_ENDARG); return type; } @@ -7228,7 +7229,7 @@ parser_prepare(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L7229 #define ambiguous_operator(op, syn) dispatch2(operator_ambiguous, ripper_intern(op), rb_str_new_cstr(syn)) #endif #define warn_balanced(op, syn) ((void) \ - (!IS_lex_state_for(last_state, EXPR_CLASS|EXPR_DOT|EXPR_FNAME|EXPR_ENDFN|EXPR_ENDARG) && \ + (!IS_lex_state_for(last_state, EXPR_CLASS|EXPR_DOT|EXPR_FNAME|EXPR_ENDFN) && \ space_seen && !ISSPACE(c) && \ (ambiguous_operator(op, syn), 0))) @@ -7921,7 +7922,7 @@ parse_ident(struct parser_params *parser https://github.com/ruby/ruby/blob/trunk/parse.y#L7922 if (COND_P()) return keyword_do_cond; if (CMDARG_P() && !IS_lex_state_for(state, EXPR_CMDARG)) return keyword_do_block; - if (IS_lex_state_for(state, (EXPR_BEG | EXPR_END | EXPR_ENDARG))) + if (IS_lex_state_for(state, (EXPR_BEG | EXPR_ENDARG))) return keyword_do_block; return keyword_do; } Index: test/ruby/test_syntax.rb =================================================================== --- test/ruby/test_syntax.rb (revision 56272) +++ test/ruby/test_syntax.rb (revision 56273) @@ -844,6 +844,10 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L844 assert_valid_syntax %q{a b(c d), :e do end}, bug11873 assert_valid_syntax %q{a b{c(d)}, :e do end}, bug11873 assert_valid_syntax %q{a b(c(d)), :e do end}, bug11873 + assert_valid_syntax %q{a b{c d}, 1 do end}, bug11873 + assert_valid_syntax %q{a b(c d), 1 do end}, bug11873 + assert_valid_syntax %q{a b{c(d)}, 1 do end}, bug11873 + assert_valid_syntax %q{a b(c(d)), 1 do end}, bug11873 end def test_block_after_cmdarg_in_paren @@ -867,6 +871,15 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L871 end end + def test_do_after_local_variable + obj = Object.new + def obj.m; yield; end + result = assert_nothing_raised(SyntaxError) do + obj.instance_eval("m = 1; m do :ok end") + end + assert_equal(:ok, result) + end + private def not_label(x) @result = x; @not_label ||= nil end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/