class RLTK::CFG::Item
Attributes
@return [Integer] Index of the next symbol in this item.
Public Class Methods
Instantiates a new Item
object with a dot located before the symbol at index dot of the right-hand side. The remaining arguments (args) should be as specified by {Production#initialize}.
@param [Integer] dot Location of the dot in this Item
. @param [Array<Object>] args (see {Production#initialize})
RLTK::CFG::Production::new
# File lib/rltk/cfg.rb, line 631 def initialize(dot, *args) super(*args) # The Dot indicates the NEXT symbol to be read. @dot = dot end
Public Instance Methods
Compares two items.
@param [Item] other Another item to compare to.
@return [Boolean]
# File lib/rltk/cfg.rb, line 643 def ==(other) self.dot == other.dot and self.lhs == other.lhs and self.rhs == other.rhs end
Moves the items dot forward by one if the end of the right-hand side hasn’t already been reached.
@return [Integer, nil]
# File lib/rltk/cfg.rb, line 651 def advance if @dot < @rhs.length @dot += 1 end end
Tests to see if the dot is at the end of the right-hand side.
@return [Boolean]
# File lib/rltk/cfg.rb, line 660 def at_end? @dot == @rhs.length end
@return [Item] A new copy of this item.
# File lib/rltk/cfg.rb, line 665 def copy Item.new(@dot, @id, @lhs, @rhs.clone) end
Returns the symbol located after the dot.
@return [Symbol] Symbol located after the dot (at the index indicated by the {#dot} attribute).
# File lib/rltk/cfg.rb, line 672 def next_symbol @rhs[@dot] end
Returns a string representation of this item.
@param [Integer] padding The ammount of padding spaces to add to the beginning of the string.
@return [String]
# File lib/rltk/cfg.rb, line 681 def to_s(padding = 0) "#{format("%-#{padding}s", @lhs)} -> #{@rhs.map { |s| s.to_s }.insert(@dot, '·').join(' ') }" end