Class: Rley::Parser::ParseEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/rley/parser/parse_entry.rb

Overview

Responsibilities:

  • To know whether the vertex is a start, end or item vertex
  • To know the next symbol to expect

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aVertex, theOrigin) ⇒ ParseEntry

Returns a new instance of ParseEntry.

Parameters:



26
27
28
29
30
# File 'lib/rley/parser/parse_entry.rb', line 26

def initialize(aVertex, theOrigin)
  @vertex = valid_vertex(aVertex)
  @origin = theOrigin
  @antecedents = []
end

Instance Attribute Details

#antecedentsArray<ParseEntry> (readonly)

Returns Links to preceding parse entries.

Returns:

  • (Array<ParseEntry>)

    Links to preceding parse entries



17
18
19
# File 'lib/rley/parser/parse_entry.rb', line 17

def antecedents
  @antecedents
end

#originInteger (readonly)

the position in the input that matches the beginning of the rhs of the production.

Returns:

  • (Integer)


22
23
24
# File 'lib/rley/parser/parse_entry.rb', line 22

def origin
  @origin
end

#vertexGFG::Vertex (readonly)

Returns Link to a vertex of the GFG.

Returns:



14
15
16
# File 'lib/rley/parser/parse_entry.rb', line 14

def vertex
  @vertex
end

Instance Method Details

#==(other) ⇒ Object

Equality comparison. A parse entry behaves as a value object.



53
54
55
56
57
# File 'lib/rley/parser/parse_entry.rb', line 53

def ==(other)
  return true if equal? other

  (vertex == other.vertex) && (origin == other.origin)
end

#add_antecedent(anAntecedent) ⇒ Object

Add a link to an antecedent parse entry

Parameters:



48
49
50
# File 'lib/rley/parser/parse_entry.rb', line 48

def add_antecedent(anAntecedent)
  antecedents << anAntecedent unless antecedents.include?(anAntecedent)
end

#dotted_entry?Boolean

Returns true iff the vertex corresponds to a dotted item X => Y

Returns:

  • (Boolean)


78
79
80
# File 'lib/rley/parser/parse_entry.rb', line 78

def dotted_entry?
  vertex.kind_of?(GFG::ItemVertex)
end

#end_entry?Boolean

Returns true iff the vertex is an end vertex (i.e. of the form: X.)

Returns:

  • (Boolean)


88
89
90
# File 'lib/rley/parser/parse_entry.rb', line 88

def end_entry?
  vertex.kind_of?(GFG::EndVertex)
end

#entry_entry?Boolean

Returns true iff the vertex is at the start of rhs (i.e. of the form: X => .Y

Returns:

  • (Boolean)


70
71
72
73
74
# File 'lib/rley/parser/parse_entry.rb', line 70

def entry_entry?
  return false unless vertex.kind_of?(GFG::ItemVertex)

  vertex.dotted_item.at_start?
end

#exit_entry?Boolean

Returns true iff the vertex is at end of rhs (i.e. of the form: X => Y.)

Returns:

  • (Boolean)


83
84
85
# File 'lib/rley/parser/parse_entry.rb', line 83

def exit_entry?
  vertex.complete?
end

#hashObject



59
60
61
# File 'lib/rley/parser/parse_entry.rb', line 59

def hash
  @hash ||= (vertex.oid_str + "-#{origin}").hash
end

#inspectString

Returns a string containing a human-readable representation of the production.

Returns:

  • (String)


35
36
37
38
39
40
41
42
43
44
# 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

#next_symbolObject

Return the symbol after the dot (if any)



98
99
100
# File 'lib/rley/parser/parse_entry.rb', line 98

def next_symbol
  vertex.next_symbol
end

#orphan?Boolean

Return true if the entry has no antecedent entry

Returns:

  • (Boolean)


103
104
105
# File 'lib/rley/parser/parse_entry.rb', line 103

def orphan?
  antecedents.empty?
end

#prev_symbolObject

Return the symbol before the dot (if any)



93
94
95
# File 'lib/rley/parser/parse_entry.rb', line 93

def prev_symbol
  vertex.prev_symbol
end

#start_entry?Boolean

Returns true iff the vertex is a start vertex (i.e. of the form: .X)

Returns:

  • (Boolean)


64
65
66
# File 'lib/rley/parser/parse_entry.rb', line 64

def start_entry?
  vertex.kind_of?(GFG::StartVertex)
end

#to_sString

Give a String representation of itself. The format of the text representation is "format of dotted rule" + " | " + origin

Returns:

  • (String)


142
143
144
# File 'lib/rley/parser/parse_entry.rb', line 142

def to_s
  vertex.label + " | #{origin}"
end