1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
rhe 2017-07-21 04:29:46 +00:00
parent 0055f09bcc
commit c4dfd0ccfb
3 changed files with 22 additions and 1 deletions

View file

@ -4492,12 +4492,20 @@ kwrest_mark : tPOW
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);
%*/
}
;

View file

@ -153,6 +153,10 @@ class DummyParser < Ripper
"*#{var}"
end
def on_kwrest_param(var)
"**#{var}"
end
def on_blockarg(var)
"&#{var}"
end

View file

@ -893,7 +893,7 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
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::Unit::TestCase
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}