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.
This commit is contained in:
Josh Holtrop 2024-07-08 10:14:09 -04:00
parent 911e9505b7
commit d76e12fea1
3 changed files with 46 additions and 46 deletions

View File

@ -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:"

View File

@ -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

View File

@ -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<ItemSet>]
# 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<Token, RuleSet>]
# 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<Item>]
# 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