Skip to content

Comments

Use Prism for Ruby source parsing on Ruby >= 3.3#144

Open
flavorjones wants to merge 2 commits intomasterfrom
ruby-4-support
Open

Use Prism for Ruby source parsing on Ruby >= 3.3#144
flavorjones wants to merge 2 commits intomasterfrom
ruby-4-support

Conversation

@flavorjones
Copy link
Member

@flavorjones flavorjones commented Feb 7, 2026

Summary

Adding support for Ruby >= 4.0

  • Use Prism::Translation::ParserCurrent instead of Parser::CurrentRuby on Ruby >= 3.3, for forward-compatibility with Ruby 4.0+
  • On older Rubies, continue using the parser gem as before
  • Add Console1984.ruby_parser and Console1984.require_ruby_parser_dependencies to centralize parser selection
  • Have .command_parser.rb require its own dependencies instead of relying on Supervisor to manage load ordering
  • Backfill test coverage for constant assignment validation

Closes #131 which requested Ruby 4.0 support.

cc @jeremy

Both ForbiddenConstantReferenceValidation and ForbiddenReopeningValidation
check constant_assignments but neither had test coverage for that path.
The whitequark/parser gem does not support Ruby 3.4+ syntax and will
not be updated. On Ruby 4.0 it falls back to its Ruby 3.3 parser,
meaning it cannot parse new syntax like logical operators at line
beginning.

Prism, which is bundled with Ruby 3.3+, provides a translation layer
(Prism::Translation::ParserCurrent) that is a drop-in replacement for
Parser::CurrentRuby. It produces the same Parser::AST::Node objects, so
CommandParser (which inherits from Parser::AST::Processor) continues to
work unchanged.

Two new methods on Console1984:

- require_ruby_parser_dependencies: loads parser+prism on Ruby >= 3.3,
  or parser/current on older Rubies. Called by .command_parser.rb itself
  rather than requiring the supervisor to manage load ordering.

- ruby_parser: returns the appropriate parser class for the running
  Ruby version.

On older Rubies (< 3.3), everything continues to use the parser gem
as before.
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.

Support ruby 3.4

1 participant