Skip to content
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

Combine Elsif node with IfNode #299

Merged
merged 4 commits into from
Mar 8, 2023
Merged

Conversation

egiurleo
Copy link
Contributor

@egiurleo egiurleo commented Feb 8, 2023

Related to #278. Completed with @bitwise-aiden.

This PR eliminates the Elsif node and folds its functionality into IfNode. Now, elsif conditional statements will be represented with IfNodes that are the consequent of another IfNode. This eliminates an unnecessary node type from syntax tree, simplifies a lot of logic, and brings syntax tree closer to other AST representations of Ruby.

lib/syntax_tree/parser.rb Outdated Show resolved Hide resolved
lib/syntax_tree/node.rb Outdated Show resolved Hide resolved
lib/syntax_tree/node.rb Outdated Show resolved Hide resolved
lib/syntax_tree/translation/parser.rb Outdated Show resolved Hide resolved
lib/syntax_tree/translation/parser.rb Outdated Show resolved Hide resolved
lib/syntax_tree/translation/parser.rb Outdated Show resolved Hide resolved
lib/syntax_tree/visitor/field_visitor.rb Outdated Show resolved Hide resolved
lib/syntax_tree/visitor/mutation_visitor.rb Outdated Show resolved Hide resolved
@egiurleo egiurleo marked this pull request as ready for review February 8, 2023 19:42
@egiurleo
Copy link
Contributor Author

Hey @kddnewton just gently bumping this. I'd love a review when you have time!

Copy link
Member

@kddnewton kddnewton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of changes, thanks so much for this work!

lib/syntax_tree/node.rb Outdated Show resolved Hide resolved
lib/syntax_tree/node.rb Outdated Show resolved Hide resolved
lib/syntax_tree/node.rb Outdated Show resolved Hide resolved
lib/syntax_tree/parser.rb Outdated Show resolved Hide resolved
lib/syntax_tree/visitor/mutation_visitor.rb Outdated Show resolved Hide resolved
Many other Ruby ASTs do not have a separate node representing `elsif`
conditionals; instead, they use the same node as `if` but make it a
consequent of other `if` nodes. This commit removes the `Elsif` node and
combines its functionality with `IfNode`, ensuring that both the parsing and
formatting logic are still functional.
And add `beginning` kwarg to `IfNode` DSL method.
@egiurleo
Copy link
Contributor Author

egiurleo commented Mar 3, 2023

@kddnewton Thanks for the feedback! I think I've implemented all the changes you requested. The big ones were:

  • I changed the beginning attr on IfNode to be named keyword and kept it as a keyword rather than a string
  • I changed the formatting to just copy-paste the old Elsif formatting if the node represents an elsif

Copy link
Member

@kddnewton kddnewton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so good!

@kddnewton kddnewton changed the base branch from main to structure March 8, 2023 19:04
@kddnewton kddnewton merged commit 61eefa8 into ruby-syntax-tree:structure Mar 8, 2023
@kddnewton
Copy link
Member

@egiurleo I ended up merging this into the structure branch because it's a breaking change and I'd like to make more breaking changes, but in case there are bugs off main I'd still like to be able to release. So I'm going to keep structure around until we decide to release the breaking changes all at once.

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.

None yet

2 participants