diff --git a/lib/imbecile/parser.rb b/lib/imbecile/parser.rb index 9c43bf2..0544b9c 100644 --- a/lib/imbecile/parser.rb +++ b/lib/imbecile/parser.rb @@ -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 diff --git a/lib/imbecile/parser/item_set.rb b/lib/imbecile/parser/item_set.rb index 86d683a..99d6d9d 100644 --- a/lib/imbecile/parser/item_set.rb +++ b/lib/imbecile/parser/item_set.rb @@ -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