Keep track of item set in-links

This commit is contained in:
Josh Holtrop 2021-09-21 21:25:45 -04:00
parent a2795bb531
commit 997f34a1e4
2 changed files with 10 additions and 0 deletions

View File

@ -34,6 +34,10 @@ class Imbecile
@item_sets.each do |item_set|
process_item_set(item_set)
puts "Item set #{item_set.id}:"
ids = item_set.in_sets.map(&:id)
if ids.size > 0
puts " (in from #{ids.join(", ")})"
end
puts item_set
item_set.follow_item_set.each do |follow_symbol, follow_item_set|
if follow_symbol.is_a?(Token)
@ -54,6 +58,7 @@ class Imbecile
unless follow_symbol == @token_eof
follow_set = @item_sets_set[item_set.build_follow_set(follow_symbol)]
item_set.follow_item_set[follow_symbol] = follow_set
follow_set.in_sets << item_set
end
end
end

View File

@ -11,9 +11,14 @@ class Imbecile
# Maps a follow symbol to its item set.
attr_reader :follow_item_set
# @return [Set]
# Item sets leading to this item set.
attr_reader :in_sets
def initialize(items)
@items = Set.new(items)
@follow_item_set = {}
@in_sets = Set.new
close!
end