class Rley::Parser::ParseEntry
Responsibilities:
-
To know whether the vertex is a start, end or item vertex
-
To know the next symbol to expect
Attributes
@return [Array<ParseEntry>] Links to preceding parse entries
the position in the input that matches the beginning of the rhs of the production. @return [Integer]
@return [GFG::Vertex] Link to a vertex of the GFG
Public Class Methods
Source
# File lib/rley/parser/parse_entry.rb, line 26 def initialize(aVertex, theOrigin) @vertex = valid_vertex(aVertex) @origin = theOrigin @antecedents = [] end
@param aVertex [GFG::Vertex] @param theOrigin [Integer]
Public Instance Methods
Source
# File lib/rley/parser/parse_entry.rb, line 53 def ==(other) return true if equal? other (vertex == other.vertex) && (origin == other.origin) end
Equality comparison. A parse entry behaves as a value object.
Source
# File lib/rley/parser/parse_entry.rb, line 48 def add_antecedent(anAntecedent) antecedents << anAntecedent unless antecedents.include?(anAntecedent) end
Add a link to an antecedent parse entry @param anAntecedent
Source
# File lib/rley/parser/parse_entry.rb, line 78 def dotted_entry? vertex.is_a?(GFG::ItemVertex) end
Returns true iff the vertex corresponds to a dotted item X => Y
Source
# File lib/rley/parser/parse_entry.rb, line 88 def end_entry? vertex.is_a?(GFG::EndVertex) end
Returns true iff the vertex is an end vertex (i.e. of the form: X.)
Source
# File lib/rley/parser/parse_entry.rb, line 70 def entry_entry? return false unless vertex.is_a?(GFG::ItemVertex) vertex.dotted_item.at_start? end
Returns true iff the vertex is at the start of rhs (i.e. of the form: X => .Y
Source
# File lib/rley/parser/parse_entry.rb, line 83 def exit_entry? vertex.complete? end
Returns true iff the vertex is at end of rhs (i.e. of the form: X => Y.)
Source
# File lib/rley/parser/parse_entry.rb, line 59 def hash @hash ||= (vertex.oid_str + "-#{origin}").hash end
Source
# File lib/rley/parser/parse_entry.rb, line 35 def inspect result = selfie result << ' @antecedents=[' antecedents.each do |antec| result << antec.selfie end result << ']>' result end
Returns a string containing a human-readable representation of the production. @return [String]
Source
# File lib/rley/parser/parse_entry.rb, line 98 def next_symbol vertex.next_symbol end
Return the symbol after the dot (if any)
Source
# File lib/rley/parser/parse_entry.rb, line 103 def orphan? antecedents.empty? end
Return true if the entry has no antecedent entry
Source
# File lib/rley/parser/parse_entry.rb, line 93 def prev_symbol vertex.prev_symbol end
Return the symbol before the dot (if any)
Source
# File lib/rley/parser/parse_entry.rb, line 64 def start_entry? vertex.is_a?(GFG::StartVertex) end
Returns true iff the vertex is a start vertex (i.e. of the form: .X)
Source
# File lib/rley/parser/parse_entry.rb, line 142 def to_s vertex.label + " | #{origin}" end
Give a String representation of itself. The format of the text representation is “format of dotted rule” + “ | ” + origin @return [String]
Protected Instance Methods
Source
# File lib/rley/parser/parse_entry.rb, line 150 def selfie result = +"#<#{self.class.name}:#{object_id}" result << " @vertex=<#{vertex.class.name}:#{vertex.object_id}" result << " label=#{vertex.label}>" result << " @origin=#{origin}" result end
Returns a human-readable and partial representation of itself. @return [String]
Private Instance Methods
Source
# File lib/rley/parser/parse_entry.rb, line 163 def valid_vertex(aVertex) raise StandardError, 'GFG vertex cannot be nil' if aVertex.nil? aVertex end
Return the validated GFG
vertex