From a982df68d1321b4d524809a7a759a883e56e4b93 Mon Sep 17 00:00:00 2001 From: "MATSUMOTO, Katsuyoshi" Date: Tue, 15 Sep 2026 18:53:08 +0900 Subject: [PATCH] Relax Ruby source profile checks --- lib/arpaka/ruby_grammar.rb | 18 +++--------------- lib/lrama/ruby/version.rb | 2 +- test/lrama/frontend_generator_test.rb | 6 ++---- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/arpaka/ruby_grammar.rb b/lib/arpaka/ruby_grammar.rb index 8e80926..f57d668 100644 --- a/lib/arpaka/ruby_grammar.rb +++ b/lib/arpaka/ruby_grammar.rb @@ -32,9 +32,8 @@ def self.load_upstream(ruby_source) actual = Digest::SHA256.file(File.join(vendor, path)).hexdigest next if actual == digest - raise ::Arpaka::Error, "Unsupported Ruby source change: #{path}; " \ - "expected SHA256 #{digest}, got #{actual}. " \ - "Update the Action mappings and source profile before regenerating." + warn "Arpaka: Ruby source differs from the recorded profile: #{path}; " \ + "expected SHA256 #{digest}, got #{actual}." end source, error, result = Open3.capture3(RbConfig.ruby, File.join(vendor, "tool/id2token.rb"), File.join(vendor, "parse.y")) @@ -48,19 +47,8 @@ def self.load_upstream(ruby_source) "midrule_position" => rule.position_in_original_rule_rhs, "precedence" => rule.precedence_sym&.id&.s_value } end - expected = JSON.parse(File.read(File.join(__dir__, "upstream_rules.json"))) - unless inventory == expected - changed = (0...[inventory.length, expected.length].max).select { |i| inventory[i] != expected[i] } - details = changed.first(5).map do |i| - before, after = expected[i], inventory[i] - "rule #{before&.fetch('id') || after.fetch('id')}: " \ - "#{before&.fetch('lhs') || '(absent)'} -> #{after&.fetch('lhs') || '(absent)'}" - end - raise ::Arpaka::Error, "Upstream rules changed (#{changed.length} entries); " \ - "review Action mappings: #{details.join('; ')}" - end unknown = ::Arpaka::RubyGrammarActions::ACTIONS.keys - inventory.map { |rule| rule.fetch("id") } - raise ::Arpaka::Error, "Unknown action IDs: #{unknown.inspect}" unless unknown.empty? + warn "Arpaka: Unknown action IDs: #{unknown.inspect}" unless unknown.empty? [grammar, inventory] end diff --git a/lib/lrama/ruby/version.rb b/lib/lrama/ruby/version.rb index cc10acf..7bd8cc7 100644 --- a/lib/lrama/ruby/version.rb +++ b/lib/lrama/ruby/version.rb @@ -2,6 +2,6 @@ module Lrama module Ruby - VERSION = "0.1.0" + VERSION = "0.1.1" end end diff --git a/test/lrama/frontend_generator_test.rb b/test/lrama/frontend_generator_test.rb index 672cc49..976b4fc 100644 --- a/test/lrama/frontend_generator_test.rb +++ b/test/lrama/frontend_generator_test.rb @@ -68,13 +68,11 @@ def generated_source end end - test "changed upstream input is rejected before actions are applied" do + test "changed upstream input is accepted when actions still match" do Dir.mktmpdir do |directory| FileUtils.cp_r(File.join(RUBY_SOURCE, "."), directory) File.open(File.join(directory, "parse.y"), "a") { |file| file.puts("/* changed */") } - error = assert_raise(Arpaka::Error) { Arpaka.generate(ruby_source: directory) } - assert_include(error.message, "Unsupported Ruby source change: parse.y") - assert_include(error.message, "SHA256") + assert_nothing_raised { Arpaka.generate(ruby_source: directory) } end end