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

Add a custom builder class for the parser translator #3443

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Earlopain
Copy link
Contributor

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
Contributor Author

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

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.

1 participant