From dcf2048f4668e3f941a21517b11e9186b7d9a561 Mon Sep 17 00:00:00 2001 From: ydah Date: Sun, 6 Sep 2026 11:02:53 +0900 Subject: [PATCH] Fix IELR follow-kernel item filtering --- lib/lrama/states.rb | 5 ++--- spec/lrama/states_spec.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/lrama/states.rb b/lib/lrama/states.rb index ddce627df..e7d919111 100644 --- a/lib/lrama/states.rb +++ b/lib/lrama/states.rb @@ -661,9 +661,8 @@ def compute_follow_kernel_items base_function = compute_goto_bitmaps Digraph.new(set, relation, base_function).compute.each do |goto, follow_kernel_items| state = goto.from_state - state.follow_kernel_items[goto] = state.kernels.map {|kernel| - [kernel, Bitmap.to_bool_array(follow_kernel_items, state.kernels.count)] - }.to_h + bools = Bitmap.to_bool_array(follow_kernel_items, state.kernels.count) + state.follow_kernel_items[goto] = state.kernels.zip(bools).to_h end end diff --git a/spec/lrama/states_spec.rb b/spec/lrama/states_spec.rb index 28c217e2a..fed0ac1fa 100644 --- a/spec/lrama/states_spec.rb +++ b/spec/lrama/states_spec.rb @@ -1876,6 +1876,24 @@ class go to state 5 end describe '#compute_ielr' do + it 'stores a boolean for each follow kernel item' do + path = "integration/ielr.y" + y = File.read(fixture_path(path)) + grammar = Lrama::Parser.new(y, path).parse + grammar.prepare + grammar.validate! + states = Lrama::States.new(grammar, Lrama::Tracer.new(Lrama::Logger.new)) + states.compute + states.compute_ielr + + values = states.states.flat_map do |state| + state.follow_kernel_items.values.compact.flat_map(&:values) + end + + expect(values).to include(false) + expect(values).to all(satisfy("be a boolean") { |value| value == true || value == false }) + end + it 'recompute states' do path = "integration/ielr.y" y = File.read(fixture_path(path))