From d76e12fea1ff2be71064c2e75408b3d66ab03edd Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 8 Jul 2024 10:14:09 -0400 Subject: [PATCH] Rename "following" to "next" - #25 The term "following" could potentially imply an association with the "follow set", however it was used in a non-closed manner. --- lib/propane/parser.rb | 34 +++++++++++++++++----------------- lib/propane/parser/item.rb | 24 ++++++++++++------------ lib/propane/parser/item_set.rb | 34 +++++++++++++++++----------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/propane/parser.rb b/lib/propane/parser.rb index 599c1c9..ee97a87 100644 --- a/lib/propane/parser.rb +++ b/lib/propane/parser.rb @@ -23,10 +23,10 @@ class Propane item_set.id = @item_sets.size @item_sets << item_set @item_sets_set[item_set] = item_set - item_set.following_symbols.each do |following_symbol| - unless following_symbol.name == "$EOF" - following_set = item_set.build_following_item_set(following_symbol) - eval_item_sets << following_set + item_set.next_symbols.each do |next_symbol| + unless next_symbol.name == "$EOF" + next_item_set = item_set.build_next_item_set(next_symbol) + eval_item_sets << next_item_set end end end @@ -48,15 +48,15 @@ class Propane @shift_table = [] @reduce_table = [] @item_sets.each do |item_set| - shift_entries = item_set.following_symbols.map do |following_symbol| + shift_entries = item_set.next_symbols.map do |next_symbol| state_id = - if following_symbol.name == "$EOF" + if next_symbol.name == "$EOF" 0 else - item_set.following_item_set[following_symbol].id + item_set.next_item_set[next_symbol].id end { - symbol_id: following_symbol.id, + symbol_id: next_symbol.id, state_id: state_id, } end @@ -87,11 +87,11 @@ class Propane end def process_item_set(item_set) - item_set.following_symbols.each do |following_symbol| - unless following_symbol.name == "$EOF" - following_set = @item_sets_set[item_set.build_following_item_set(following_symbol)] - item_set.following_item_set[following_symbol] = following_set - following_set.in_sets << item_set + item_set.next_symbols.each do |next_symbol| + unless next_symbol.name == "$EOF" + next_item_set = @item_sets_set[item_set.build_next_item_set(next_symbol)] + item_set.next_item_set[next_symbol] = next_item_set + next_item_set.in_sets << item_set end end end @@ -183,9 +183,9 @@ class Propane # tokens to form the lookahead token set. item_sets.each do |item_set| item_set.items.each do |item| - if item.following_symbol == rule_set + if item.next_symbol == rule_set (1..).each do |offset| - case symbol = item.following_symbol(offset) + case symbol = item.next_symbol(offset) when nil rule_set = item.rule.rule_set unless checked_rule_sets.include?(rule_set) @@ -242,8 +242,8 @@ class Propane @log.puts @log.puts " Incoming states: #{incoming_ids.join(", ")}" @log.puts " Outgoing states:" - item_set.following_item_set.each do |following_symbol, following_item_set| - @log.puts " #{following_symbol.name} => #{following_item_set.id}" + item_set.next_item_set.each do |next_symbol, next_item_set| + @log.puts " #{next_symbol.name} => #{next_item_set.id}" end @log.puts @log.puts " Reduce actions:" diff --git a/lib/propane/parser/item.rb b/lib/propane/parser/item.rb index e49d279..89815f1 100644 --- a/lib/propane/parser/item.rb +++ b/lib/propane/parser/item.rb @@ -56,7 +56,7 @@ class Propane # Return the set of Items obtained by "closing" the current item. # - # If the following symbol for the current item is another Rule name, then + # If the next symbol for the current item is another Rule name, then # this method will return all Items for that Rule with a position of 0. # Otherwise, an empty Array is returned. # @@ -81,17 +81,17 @@ class Propane @position == @rule.components.size end - # Get the following symbol for the Item. + # Get the next symbol for the Item. # - # That is, the symbol which follows the parse position marker in the + # That is, the symbol which is after the parse position marker in the # current Item. # # @param offset [Integer] # Offset from current parse position to examine. # # @return [Token, RuleSet, nil] - # Following symbol for the Item. - def following_symbol(offset = 0) + # Next symbol for the Item. + def next_symbol(offset = 0) @rule.components[@position + offset] end @@ -108,25 +108,25 @@ class Propane end end - # Get whether this Item is followed by the provided symbol. + # Get whether this Item's next symbol is the given symbol. # # @param symbol [Token, RuleSet] # Symbol to query. # # @return [Boolean] - # Whether this Item is followed by the provided symbol. - def followed_by?(symbol) - following_symbol == symbol + # Whether this Item's next symbol is the given symbol. + def next_symbol?(symbol) + next_symbol == symbol end - # Get the following item for this Item. + # Get the next item for this Item. # # That is, the Item formed by moving the parse position marker one place # forward from its position in this Item. # # @return [Item] - # The following item for this Item. - def following_item + # The next item for this Item. + def next_item Item.new(@rule, @position + 1) end diff --git a/lib/propane/parser/item_set.rb b/lib/propane/parser/item_set.rb index 980d4a6..0e2f24f 100644 --- a/lib/propane/parser/item_set.rb +++ b/lib/propane/parser/item_set.rb @@ -14,8 +14,8 @@ class Propane attr_accessor :id # @return [Hash] - # Maps a following symbol to its ItemSet. - attr_reader :following_item_set + # Maps a next symbol to its ItemSet. + attr_reader :next_item_set # @return [Set] # ItemSets leading to this item set. @@ -31,28 +31,28 @@ class Propane # Items in this ItemSet. def initialize(items) @items = Set.new(items) - @following_item_set = {} + @next_item_set = {} @in_sets = Set.new close! end - # Get the set of following symbols for all Items in this ItemSet. + # Get the set of next symbols for all Items in this ItemSet. # # @return [Set] - # Set of following symbols for all Items in this ItemSet. - def following_symbols - Set.new(@items.map(&:following_symbol).compact) + # Set of next symbols for all Items in this ItemSet. + def next_symbols + Set.new(@items.map(&:next_symbol).compact) end - # Build a following ItemSet for the given following symbol. + # Build a next ItemSet for the given next symbol. # # @param symbol [Token, RuleSet] - # Following symbol to build the following ItemSet for. + # Next symbol to build the next ItemSet for. # # @return [ItemSet] - # Following ItemSet for the given following symbol. - def build_following_item_set(symbol) - ItemSet.new(items_followed_by(symbol).map(&:following_item)) + # Next ItemSet for the given next symbol. + def build_next_item_set(symbol) + ItemSet.new(items_with_next(symbol).map(&:next_item)) end # Hash function. @@ -137,16 +137,16 @@ class Propane end end - # Get the Items followed by the given following symbol. + # Get the Items with the given next symbol. # # @param symbol [Token, RuleSet] - # Following symbol. + # Next symbol. # # @return [Array] - # Items followed by the given following symbol. - def items_followed_by(symbol) + # Items with the given next symbol. + def items_with_next(symbol) @items.select do |item| - item.followed_by?(symbol) + item.next_symbol?(symbol) end end