seattlerb / ruby_parser

ruby_parser is a ruby parser written in pure ruby. It outputs s-expressions which can be manipulated and converted back to ruby via the ruby2ruby gem.
http://www.zenspider.com/projects/ruby_parser.html
476 stars 100 forks source link

First cut at supporting argument forwarding #316

Closed presidentbeef closed 3 years ago

presidentbeef commented 3 years ago

Adds support for argument forwarding from Ruby 2.7.

However, it needs to be a syntax error if the triple-dot argument forwarding is used anywhere but inside a method definition that sets argument forwarding (i.e., def x(...); end).

Looks like in MRI they set some special argument variables to do the forwarding and check for their existence in the parser. (The current parser has abstracted this out into helper methods.)

Open to suggestions on how/where to track that information.

zenspider commented 3 years ago

This looks like the right mechanism, but prolly needs to be expanded to deal with different types of locals?

lib/ruby_lexer.rb
331:  def is_local_id id
337:    # TODO: (dyna_in_block? && dvar_defined?(id)) || local_id?(id)
963:    tok_id = :tIDENTIFIER if tok_id == :tCONSTANT && is_local_id(token)
presidentbeef commented 3 years ago

@zenspider Thoughts?

Gbeschbacher commented 3 years ago

@presidentbeef @zenspider any news on that PR?

zenspider commented 3 years ago

I overhauled this a bit: (https://github.com/seattlerb/ruby_parser/commit/731b4b749bed27ece3fd4f3c987e86cc3b23f455)

Gist is the same.

P.S. I kinda hate s(:forward_args)... was seriously tempted to do s(:"...") but I also hate quoted syms. P.P.S. Why does that sym need quoting?