diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-05-15 10:24:44 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-05-16 19:41:42 +0900 |
commit | 334cb185b7189ab5449210b77e684ec8559712f4 (patch) | |
tree | a42a0a5a617ed22ff1c5410bd115238ae9d521ab /lib/test | |
parent | e143a741913fd970e27eb83e3d809d9694038f9f (diff) | |
download | ruby-topic/ripper-unnamed-kwrest.tar.gz |
ripper: dispatch new parser event 'kwrest_param' on f_kwresttopic/ripper-unnamed-kwrest
Ripper has an issue in handling bare kwrest:
$ ruby -rpp -rripper -e'pp Ripper.sexp("def a(**) end")'
[:program,
[[:def,
[:@ident, "a", [1, 4]],
[:paren, [:params, nil, nil, nil, nil, nil, 183, nil]],
[:bodystmt, [[:void_stmt]], nil, nil, nil]]]]
The mysterious 183 is the problem: this is an ID generated by
internal_id(). This patch introduces a new 'kwrest_param' parser event
that works just like 'rest_param' event that corresponds to rest params
(def a(*rest) end). After applying this, the result will be:
$ ruby -rpp -rripper -e'pp Ripper.sexp("def a(**name) end")'
[:program,
[[:def,
[:@ident, "a", [1, 4]],
[:paren,
[:params,
nil,
nil,
nil,
nil,
nil,
[:kwrest_param, [:@ident, "name", [1, 8]]],
nil]],
[:bodystmt, [[:void_stmt]], nil, nil, nil]]]]
$ ruby -rpp -rripper -e'pp Ripper.sexp("def a(**) end")'
[:program,
[[:def,
[:@ident, "a", [1, 4]],
[:paren, [:params, nil, nil, nil, nil, nil, [:kwrest_param, nil], nil]],
[:bodystmt, [[:void_stmt]], nil, nil, nil]]]]
* parse.y (f_kwrest): dispatch kwrest_param event, just like rest_param.
* test/ripper/dummyparser.rb (on_kwrest_param): add kwrest_param parser
event handler.
* test/ripper/test_parser_events.rb (test_params): adjust.
* test/ripper/test_parser_events.rb (test_kwrest_param): test that
kwrest_param event handler is properly called.
Diffstat (limited to 'lib/test')
0 files changed, 0 insertions, 0 deletions