Add a custom builder class for the parser translator #3443
+21
−0
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.
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 theparser
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 forparser
. 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#L330I'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 changerubocop-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.