Skip to content

Implement visitor pattern for SyntaxTree::Node #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2022

Conversation

wildmaples
Copy link
Contributor

What, why?

This pattern will expand our horizons and allow us to do fun stuff with the nodes through the SyntaxTree::Visitor class. Right now we are using metaprogramming to create and #send to call our #visit_ methods the LSP. Ideally this would be a built in feature in syntax_tree so others can use it as well.

We've chosen to require the Visitor class in node.rb to make it clearer that the file requires it. Otherwise, we'd have to add it to lib/syntax_tree.rb in an order-dependent way, which we decided was less desirable.

Who

Co-authored-by: Kaan Ozkan [email protected]
Co-authored-by: Alexandre Terrasa [email protected]
Co-authored-by: Vinicius Stock [email protected]
Co-authored-by: Emily Giurleo [email protected]
Co-authored-by: Rafael Franca [email protected]

This pattern will expand our horizons and allow us to do fun stuff with the nodes through the SyntaxTree::Visitor class.

We've chosen to require the Visitor class in node.rb to make it clear that the file requires it. Otherwise, we'd have to add it to lib/syntax_tree.rb in an order-dependent way, which is undesirable.

Co-authored-by: Kaan Ozkan <[email protected]>
Co-authored-by: Alexandre Terrasa <[email protected]>
Co-authored-by: Vinicius Stock <[email protected]>
Co-authored-by: Emily Giurleo <[email protected]>
Co-authored-by: Rafael Franca <[email protected]>
@kddnewton
Copy link
Member

Thank you all so much for the work on this!

Are you relying on visit_method_name in any way or is that just used to make it so that it's easy to do the metaprogramming here?

I think I'd be much more keen to actually write out the visit nodes. The current underscore algorithm feels a little arbitrary. I'd rather we keep the names closer to what ripper has internally since that's what folks coming from Ruby core will know.

That being said, this is a great start, and I'm going to merge it as is for now.

@kddnewton kddnewton merged commit 5fcec5e into ruby-syntax-tree:main Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants