Skip to content

Use Prism::Translation::ParserCurrent in prism docs #1073

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions doc/PRISM_TRANSLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,17 @@ RUBY

## Using `prism` when parsing ruby for the currently running Ruby version

If you are using `Parser::CurrentRuby`, you need to do similar branching logic. Do note that `prism` has no concept of a parser for the currently executing ruby version. As an alternative, you can manually extract the necessary version from the `RUBY_VERSION` constant:
If you are using `Parser::CurrentRuby`, you need to do similar branching logic:

```rb
def parser_for_current_ruby
code_version = RUBY_VERSION.to_f

if code_version <= 3.3
if Gem::Version.new(RUBY_VERSION) <= '3.3'
require 'parser/current'
Parser::CurrentRuby
else
require 'prism'
case code_version
when 3.3
Prism::Translation::Parser33
when 3.4
Prism::Translation::Parser34
else
warn "Unknown Ruby version #{code_version}, using 3.4 as a fallback"
Prism::Translation::Parser34
end
# Only available on prism > 1.4.0
Prism::Translation::ParserCurrent
end
end

Expand Down