ruby/lib/prism/translation/parser_current.rb
Earlopain ab8b199be8 [ruby/prism] Add Prism::Translation::ParserCurrent
It's not my favorite api but for users that currently use the same thing
from `parser`, moving over is more difficult
than it needs to be.

If you plan to support both old and new ruby versions, you definitly need to
branch somewhere on the ruby version
to either choose prism or parser.
But with prism you then need to enumerate all the versions again and choose the correct one.

Also, don't recommend to use `Prism::Translation::Parser` in docs. It's version-less
but actually always just uses Ruby 3.4 which is probably
not what the user intended.

Note: parser also warns when the patch version doesn't match what it expects. But I don't think prism has such a concept,
and anyways it would require releases anytime ruby releases, which I don't think is very desirable

77177f9e92
2025-03-20 21:20:23 +00:00

21 lines
516 B
Ruby

# frozen_string_literal: true
# typed: ignore
module Prism
module Translation
case RUBY_VERSION
when /^3\.3\./
ParserCurrent = Parser33
when /^3\.4\./
ParserCurrent = Parser34
when /^3\.5\./
ParserCurrent = Parser35
else
# Keep this in sync with released Ruby.
parser = Parser34
warn "warning: `Prism::Translation::Current` is loading #{parser.name}, " \
"but you are running #{RUBY_VERSION.to_f}."
ParserCurrent = parser
end
end
end