Project

General

Profile

Feature #12387 ยป 0001-ripper-dispatch-new-parser-event-kwrest_param-on-f_k.patch

rhenium (Kazuki Yamaguchi), 05/16/2016 10:42 AM

View differences:

parse.y
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);
%*/
}
;
test/ripper/dummyparser.rb
"*#{var}"
end
def on_kwrest_param(var)
"**#{var}"
end
def on_blockarg(var)
"&#{var}"
end
test/ripper/test_parser_events.rb
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_paren
......
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}
    (1-1/1)