ruby-changes:47267
From: rhe <ko1@a...>
Date: Fri, 21 Jul 2017 13:29:53 +0900 (JST)
Subject: [ruby-changes:47267] rhe:r59382 (trunk): ripper: add kwrest_param parser event
rhe 2017-07-21 13:29:46 +0900 (Fri, 21 Jul 2017) New Revision: 59382 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59382 Log: ripper: add kwrest_param parser event * parse.y (f_kwrest): Dispatch kwrest_param event. This is especially useful for unnamed kwrest parameter for which we expose the internal ID currently. [ruby-core:75528] [Feature #12387] * test/ripper/dummyparser.rb (on_kwrest_param): Add handler for kwrest_param parser event. * test/ripper/test_parser_events.rb (test_params): Adapt to the change in DummyParser. (test_kwrest_param): Test that kwrest_param event handler is called. Modified files: trunk/parse.y trunk/test/ripper/dummyparser.rb trunk/test/ripper/test_parser_events.rb Index: test/ripper/dummyparser.rb =================================================================== --- test/ripper/dummyparser.rb (revision 59381) +++ test/ripper/dummyparser.rb (revision 59382) @@ -153,6 +153,10 @@ class DummyParser < Ripper https://github.com/ruby/ruby/blob/trunk/test/ripper/dummyparser.rb#L153 "*#{var}" end + def on_kwrest_param(var) + "**#{var}" + end + def on_blockarg(var) "&#{var}" end Index: test/ripper/test_parser_events.rb =================================================================== --- test/ripper/test_parser_events.rb (revision 59381) +++ test/ripper/test_parser_events.rb (revision 59382) @@ -893,7 +893,7 @@ class TestRipper::ParserEvents < Test::U https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L893 thru_params = false parse('a {|**x|}', :on_params) {|_, *v| thru_params = true; arg = v} assert_equal true, thru_params - assert_equal [nil, nil, nil, nil, nil, "x", nil], arg + assert_equal [nil, nil, nil, nil, nil, "**x", nil], arg end def test_params_mlhs @@ -1079,6 +1079,15 @@ class TestRipper::ParserEvents < Test::U https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L1079 assert_equal true, thru_rest_param end + def test_kwrest_param + thru_kwrest = false + parse('def a(**) end', :on_kwrest_param) {|n, val| thru_kwrest = val} + assert_equal nil, thru_kwrest + thru_kwrest = false + parse('def a(**x) end', :on_kwrest_param) {|n, val| thru_kwrest = val} + assert_equal "x", thru_kwrest + end + def test_retry thru_retry = false parse('retry', :on_retry) {thru_retry = true} Index: parse.y =================================================================== --- parse.y (revision 59381) +++ parse.y (revision 59382) @@ -4492,12 +4492,20 @@ kwrest_mark : tPOW https://github.com/ruby/ruby/blob/trunk/parse.y#L4492 f_kwrest : kwrest_mark tIDENTIFIER { shadowing_lvar(get_id($2)); + /*%%%*/ $$ = $2; + /*% + $$ = dispatch1(kwrest_param, $2); + %*/ } | kwrest_mark { + /*%%%*/ $$ = internal_id(); arg_var($$); + /*% + $$ = dispatch1(kwrest_param, Qnil); + %*/ } ; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/