lib/antelope/generation/recognizer/rule.rb in antelope-0.1.4 vs lib/antelope/generation/recognizer/rule.rb in antelope-0.1.5

- old
+ new

@@ -16,21 +16,21 @@ # @return [Ace::Token::Nonterminal] attr_reader :left # The right-hand side of the rule. # - # @return [Ace::Token] - attr_reader :right + # @return [Array<Ace::Token>] + attr_accessor :right # The current position inside of the rule. # # @return [Numeric] attr_reader :position # The block to be executed on production match. # - # @deprecated Use {Ace::Grammar::Production#block} instead. + # @deprecated Use {Ace::Production#block} instead. # @return [String] attr_reader :block # The lookahead set for this specific rule. Contains nothing # unless {#final?} returns true. @@ -50,18 +50,18 @@ # @return [Ace::Precedence] attr_accessor :precedence # The associated production. # - # @return [Ace::Grammar::Production] + # @return [Ace::Production] attr_reader :production include Comparable # Initialize the rule. # - # @param production [Ace::Grammar::Production] the production + # @param production [Ace::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) @@ -72,13 +72,13 @@ @production = production @block = production.block @id = SecureRandom.hex if inherited - @right = inherited + @left, @right = inherited else - @right = production.items.map(&:dup).freeze + @right = production.items.map(&:dup) end end # Give a nice representation of the rule as a string. # @@ -113,11 +113,11 @@ # by one. {#succ?} should be called to make sure that this # rule exists. # # @return [Rule] def succ - Rule.new(production, position + 1) + Rule.new(production, position + 1, [left, right]) end # Checks to see if a rule can exist after this one; i.e. the # position is not equal to the size of the right side of the # rule. @@ -173,10 +173,19 @@ else super end end + # Produces a clone of the rule; any modifications made to the + # contents of that rule do not reflect the contents of this + # rule. + # + # @return [Rule] + def clone + Rule.new(production, position) + end + # Generates a hash for this class. # # @note This is not intended for use. It is only defined to be # compatible with Hashs (and by extension, Sets). # @private @@ -192,10 +201,10 @@ # @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)>] def to_a - [left, right, position] + [left, right, position].flatten end end end end end