Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Piggy-backing on the great work by @wildmaples and team.
I want to keep the visitor pattern around because I think it's going to be very useful. However, I'm really not a fan of the
class_eval
approach. A couple of questions arise:I'd rather be very explicit about the names of the methods on the classes. Also, since their names (for the most part) come from ripper, I'd like to keep their visit methods as close to those as possible. For example, the ripper method for visiting string content is
def on_tstring_content
, the class name isTStringContent
, but the visit method would bedef visit_t_string_content
. I think that would be pretty surprising/confusing for new contributors.In this PR instead I've chosen to write out each one manually (don't worry, I generated it with syntax tree). I think this will be more maintainable and lead to better documentation. I've also provided a
Visitor.visit_method
method, which should hopefully make it easier to write visitors. You would use it like this:That
visit_method
call will ensure that you're naming the method correctly. If you have a typo (likevisit_coment
), then it will error. As a bonus, this PR usesDidYouMean
to give an ever better DX.For posterity, I generated the code below with the following script: