From 4f3a8220faf8f76c071c3d8f1ee27c3b84a701c0 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Sun, 12 Jul 2026 15:39:12 -0700 Subject: [PATCH 1/4] ruby_parser: require timeout since it uses it. --- lib/prism/translation/ruby_parser.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/prism/translation/ruby_parser.rb b/lib/prism/translation/ruby_parser.rb index 42bc5ee658..54decd5bf3 100644 --- a/lib/prism/translation/ruby_parser.rb +++ b/lib/prism/translation/ruby_parser.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true # :markup: markdown +require "timeout" + begin require "sexp" rescue LoadError From 19938071b7bb71da708253d8cb89647ee59fddbc Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Sun, 12 Jul 2026 15:39:55 -0700 Subject: [PATCH 2/4] ruby_parser: add ability to track scopes across parses. --- lib/prism/translation/ruby_parser.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/prism/translation/ruby_parser.rb b/lib/prism/translation/ruby_parser.rb index 54decd5bf3..da6f02cd20 100644 --- a/lib/prism/translation/ruby_parser.rb +++ b/lib/prism/translation/ruby_parser.rb @@ -1625,17 +1625,23 @@ def visit_write_value(node) end private_constant :Compiler + attr_accessor :scopes # :nodoc: + + def initialize scopes:nil # :nodoc: + super() + self.scopes = [scopes] if scopes + end # Parse the given source and translate it into the seattlerb/ruby_parser # gem's Sexp format. def parse(source, filepath = "(string)") - translate(Prism.parse(source, filepath: filepath, partial_script: true), filepath) + translate(Prism.parse(source, filepath: filepath, partial_script: true, scopes: scopes), filepath) end # Parse the given file and translate it into the seattlerb/ruby_parser # gem's Sexp format. def parse_file(filepath) - translate(Prism.parse_file(filepath, partial_script: true), filepath) + translate(Prism.parse_file(filepath, partial_script: true, scopes: scopes), filepath) end # Parse the give file and translate it into the @@ -1649,14 +1655,14 @@ def process(ruby, file = "(string)", timeout = nil) class << self # Parse the given source and translate it into the seattlerb/ruby_parser # gem's Sexp format. - def parse(source, filepath = "(string)") - new.parse(source, filepath) + def parse(source, filepath = "(string)", scopes: nil) + new(scopes: scopes).parse(source, filepath) end # Parse the given file and translate it into the seattlerb/ruby_parser # gem's Sexp format. - def parse_file(filepath) - new.parse_file(filepath) + def parse_file(filepath, scopes: nil) + new(scopes: scopes).parse_file(filepath) end end From 02846a978acb4f7d96b44967f415a90123e29ec8 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Sun, 12 Jul 2026 15:40:51 -0700 Subject: [PATCH 3/4] ruby_parser: add ability to subclass compiler to override methods. --- lib/prism/translation/ruby_parser.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/prism/translation/ruby_parser.rb b/lib/prism/translation/ruby_parser.rb index da6f02cd20..505d6c21f8 100644 --- a/lib/prism/translation/ruby_parser.rb +++ b/lib/prism/translation/ruby_parser.rb @@ -1562,7 +1562,7 @@ def attach_comments(sexp, node) # Create a new compiler with the given options. def copy_compiler(in_def: self.in_def, in_pattern: self.in_pattern) - Compiler.new(file, in_def: in_def, in_pattern: in_pattern) + self.class.new(file, in_def: in_def, in_pattern: in_pattern) end # Create a new Sexp object from the given prism node and arguments. @@ -1624,7 +1624,6 @@ def visit_write_value(node) end end - private_constant :Compiler attr_accessor :scopes # :nodoc: def initialize scopes:nil # :nodoc: @@ -1677,7 +1676,7 @@ def translate(result, filepath) end result.attach_comments! - result.value.accept(Compiler.new(filepath)) + result.value.accept(self.class::Compiler.new(filepath)) end end end From d98f0abcfe83b5d1f8dbe2d80a0f63470c753364 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Sun, 12 Jul 2026 16:15:31 -0700 Subject: [PATCH 4/4] ruby_parser: Fix assert_parse to handle ruby 4 caller path changes. --- rakelib/seattlerb.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rakelib/seattlerb.rake b/rakelib/seattlerb.rake index 217d64ef4b..44708757a2 100644 --- a/rakelib/seattlerb.rake +++ b/rakelib/seattlerb.rake @@ -65,7 +65,9 @@ namespace :seattlerb do def assert_parse(source, _) entry = caller.find { _1.include?("test_ruby_parser.rb") } - name = entry[/\d+:in `(?:block (?:\(\d+ levels\) )?in )?(?:assert_|test_|?'/, 1] + + name = entry[/\d+:in [`'](?:block (?:\(\d+ levels\) )?in )?(?:assert_|test_|?'/, 1] + .sub(/^Test.+#(?:test|assert)_/, '') # 4.x backtrace incl class COLLECTED[name] << source super