Currently, Prism::Translation::Parser always operates in Ruby 3.4 mode.
This means it will not parse as Ruby 3.3 even if TargetRubyVersion: 80_82_73_83_77.33 is specified.
Therefore, the it introduced in Ruby 3.4 is parsed incompatibly with Ruby 3.3. In Ruby 3.3,
the expected name for an lvar is :it, not :"0it".
A private method named convert_for_prism is prepared to convert the version from Parser to the version expected by Prism.
For example, a Parser-compatible value is 3.3, whereas Prism expects "3.3.0".
Parser#version is not used in RuboCop, but it's unclear how it is utilized in other libraries that rely on the Parser gem.
Therefore, logic to maintain compatibility between Parser and Prism is implemented.
[ruby/prism] Support multi-versioning for
Prism::Translation::Parser
Summary¶
Fixes https://github.com/ruby/prism/pull/2356.
I'm working on integrating Prism into RuboCop.
This PR introduces
Prism::Translation::Parser33
andPrism::Translation::Parser34
, namedin accordance with the following comments.
https://github.com/rubocop/rubocop/issues/12600#issuecomment-1932707748
Currently,
Prism::Translation::Parser
always operates in Ruby 3.4 mode.This means it will not parse as Ruby 3.3 even if
TargetRubyVersion: 80_82_73_83_77.33
is specified.Therefore, the
it
introduced in Ruby 3.4 is parsed incompatibly with Ruby 3.3. In Ruby 3.3,the expected name for an
lvar
is:it
, not:"0it"
.Expected AST¶
The following is an expected AST when parsing Ruby 3.3 code:
Actual AST¶
The following is an actual AST when parsing Ruby 3.3 code:
Prism::Translation::Parser33
andPrism::Translation::Parser34
aim to correspond to Ruby 3.3 and Ruby 3.4, respectively.And, The hack of specifying
TargetRubyVersion: 80_82_73_83_77.33
is expected to become unnecessary in the future,but the behavior will be maintained until RuboCop's support is finalized:
https://github.com/rubocop/rubocop/issues/12600#issuecomment-1933657732
Additional Information¶
A private method named
convert_for_prism
is prepared to convert theversion
from Parser to theversion
expected by Prism.For example, a Parser-compatible value is
3.3
, whereas Prism expects"3.3.0"
.Parser#version
is not used in RuboCop, but it's unclear how it is utilized in other libraries that rely on the Parser gem.Therefore, logic to maintain compatibility between Parser and Prism is implemented.
https://github.com/ruby/prism/commit/62d3991e22