lib/antelope/generation/recognizer/rule.rb in antelope-0.2.4 vs lib/antelope/generation/recognizer/rule.rb in antelope-0.3.0

- old
+ new

@@ -11,26 +11,26 @@ # information for other reasons. class Rule # The left-hand side of the rule. # - # @return [Ace::Token::Nonterminal] + # @return [Grammar::Token::Nonterminal] attr_reader :left # The right-hand side of the rule. # - # @return [Array<Ace::Token>] + # @return [Array<Grammar::Token>] attr_reader :right # The current position inside of the rule. # # @return [Numeric] attr_reader :position # The block to be executed on production match. # - # @deprecated Use {Ace::Production#block} instead. + # @deprecated Use {Grammar::Production#block} instead. # @return [String] attr_reader :block # The lookahead set for this specific rule. Contains nothing # unless {#final?} returns true. @@ -45,23 +45,23 @@ # @return [String, Numeric] attr_accessor :id # The precedence for this rule. # - # @return [Ace::Precedence] + # @return [Grammar::Precedence] attr_accessor :precedence # The associated production. # - # @return [Ace::Production] + # @return [Grammar::Production] attr_reader :production include Comparable # Initialize the rule. # - # @param production [Ace::Production] the production + # @param production [Grammar::Production] the production # that this rule is based off of. # @param position [Numeric] the position that this rule is in # the production. # @param inherited [nil] do not use. def initialize(production, position, inherited = false) @@ -69,11 +69,11 @@ @position = position @lookahead = Set.new @precedence = production.prec @production = production @block = production.block - @id = "%10x" % object_id + @id = format('%10x', object_id) if inherited @left, @right = inherited else @right = production.items.map(&:dup) @@ -83,11 +83,11 @@ # Give a nice representation of the rule as a string. # # @return [String] def inspect "#<#{self.class} id=#{id} left=#{left} " \ - "right=[#{right.join(" ")}] position=#{position}>" + "right=[#{right.join(' ')}] position=#{position}>" end # Give a nicer representation of the rule as a string. Shows # the id of the rule, the precedence, and the actual # production; if the given argument is true, it will show a @@ -95,20 +95,20 @@ # # @param dot [Boolean] show the current position of the rule. # @return [String] def to_s(dot = true) "#{id}/#{precedence.type.to_s[0]}#{precedence.level}: " \ - "#{left} → #{right[0, position].join(" ")}" \ - "#{" • " if dot}#{right[position..-1].join(" ")}" + "#{left} → #{right[0, position].join(' ')}" \ + "#{' • ' if dot}#{right[position..-1].join(' ')}" end # Returns the active token. If there is no active token, it - # returns a blank {Ace::Token}. + # returns a blank {Grammar::Token}. # - # @return [Ace::Token] + # @return [Grammar::Token] def active - right[position] or Ace::Token.new(nil) + right[position] || Grammar::Token.new(nil) end # Creates the rule after this one by incrementing the position # by one. {#succ?} should be called to make sure that this # rule exists. @@ -172,13 +172,13 @@ # # @param other [Object] the object to compare. # @return [Numeric] def ===(other) if other.is_a? Rule - left === other.left and right.size == other.right.size and - right.each_with_index. - all? { |e, i| e === other.right[i] } + left === other.left && right.size == other.right.size && + right.each_with_index + .all? { |e, i| e === other.right[i] } else super end end @@ -204,10 +204,10 @@ # Creates an array representation of this class. # # @note This is not intended for use. It is only defined to # make equality checking easier, and to create a hash. # @private - # @return [Array<(Ace::Token::Nonterminal, Array<Ace::Token>, Numeric)>] + # @return [Array<(Grammar::Token::Nonterminal, Array<Grammar::Token>, Numeric)>] def to_a @_array ||= [left, right, position] end end end