Skip to content

Conversation

@Earlopain
Copy link
Collaborator

I want to be able to add new node types to the parser translator, for example itblock. The bulk of the work is already done by prism itself. In the parser builder, this would be a 5-line change at most but we don't control that here.

Instead, we can add our own builder and either overwrite the few methods we need, or just inline the complete builder. I'm not sure yet which would be better.

rubocop-ast uses its own custom builder for parser. For this to correctly work with RuboCop, it must explicitly choose to extend the prism builder and use it, same as it currently chooses to use a different parser when prism is used: https://github.com/rubocop/rubocop-ast/blob/02b8d0faeeebc3ba6b5284c9e66569bbae836941/lib/rubocop/ast/processed_source.rb#L330

I'd like to enforce that the builder for prism extends its custom one since it will lead to some pretty weird issues when it uses the one from parser otherwise. But first, I'd like to change rubocop-ast to make use of this.


It does mean that further node changes when they happen will be decided by prism, and not parser. I also have no good idea yet how it would be tested since currently it only checks against a single ruby version. But these are things to think about after. I think this would definitely be the first step.

@koic, please let me know what you think about this PR and what I've written above.

I want to add new node types to the parser translator, for example `itblock`. The bulk of the work is already done by prism itself. In the `parser`
builder, this would be a 5-line change at most but we don't control that here.

Instead, we can add our own builder and either overwrite the few methods we need,
or just inline the complete builder. I'm not sure yet which would be better.

`rubocop-ast` uses its own builder for `parser`. For this to correctly work, it must explicitly choose to extend the
prism builder and use it, same as it currently chooses to use a different parser when prism is used.

I'd like to enforce that the builder for prism extends its custom one since it will lead to
some pretty weird issues otherwise. But first, I'd like to change `rubocop-ast` to make use of this.
@Earlopain
Copy link
Collaborator Author

Here's a PR for rubocop-ast showing how it could use this: rubocop/rubocop-ast#354

@bbatsov
Copy link
Contributor

bbatsov commented Feb 25, 2025

@kddnewton Please, take a look at this when you can, as it's kind of important for RuboCop.

@Earlopain
Copy link
Collaborator Author

Oh, sorry. When I asked in the rubocop issue I was kind of asking for someone from rubocop core to give it an ok (or not)

I asked for koics opinion here so I think it's reasonable that it isn't merged yet since this largely only impacts RuboCop.

@bbatsov
Copy link
Contributor

bbatsov commented Feb 25, 2025

@Earlopain I did review your suggestion first, and I does make sense to me. 😉

@kddnewton kddnewton merged commit 35dceb5 into ruby:main Feb 25, 2025
59 checks passed
Earlopain added a commit to Earlopain/prism that referenced this pull request Feb 25, 2025
Earlopain added a commit to Earlopain/prism that referenced this pull request Feb 25, 2025
Caused by ruby#3478 and ruby#3443

I also made the builder reference more explicit to clearly distinquish
between `::Parser` and `Prism::Translation::Parser`
@Earlopain Earlopain mentioned this pull request Feb 25, 2025
koic added a commit to koic/prism that referenced this pull request Feb 25, 2025
ruby#3443 and ruby#3478 conflicted,
resulting in different `initialize` method definitions.
This PR resolves the conflict and updates it to a unified `initialize` method.
matzbot pushed a commit to ruby/ruby that referenced this pull request Feb 25, 2025
Caused by ruby/prism#3478 and ruby/prism#3443

I also made the builder reference more explicit to clearly distinquish
between `::Parser` and `Prism::Translation::Parser`

ruby/prism@d52aaa75b6
@koic
Copy link
Contributor

koic commented Feb 26, 2025

I was late in responding, but in reality, this approach seems to be the better one.

Moving forward, there may be cases where node design in Prism::Translation::Parser precedes that of the Parser gem. To ensure compatibility with the Parser gem, which may adopt changes later, it would be beneficial to proactively share node names and other relevant details with the Parser gem developers as needed.

cc @whitequark @iliabylich

kddnewton pushed a commit to kddnewton/ruby that referenced this pull request Mar 18, 2025
Caused by ruby/prism#3478 and ruby/prism#3443

I also made the builder reference more explicit to clearly distinquish
between `::Parser` and `Prism::Translation::Parser`

ruby/prism@d52aaa75b6
kddnewton pushed a commit to ruby/ruby that referenced this pull request Mar 18, 2025
Caused by ruby/prism#3478 and ruby/prism#3443

I also made the builder reference more explicit to clearly distinquish
between `::Parser` and `Prism::Translation::Parser`

ruby/prism@d52aaa75b6
@Earlopain Earlopain deleted the parser-translator-builder branch October 3, 2025 10:37
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.

4 participants