Class: Rley::Parser::ParseEntry
- Inherits:
-
Object
- Object
- Rley::Parser::ParseEntry
- 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
-
#antecedents ⇒ Object
readonly
Links to preceding parse entries.
-
#origin ⇒ Object
readonly
the position in the input that matches the beginning of the rhs of the production.
-
#vertex ⇒ Object
readonly
Link to a vertex of the GFG.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Equality comparison.
-
#add_antecedent(anAntecedent) ⇒ Object
Add a link to an antecedent parse entry.
-
#dotted_entry? ⇒ Boolean
Returns true iff the vertex corresponds to a dotted item X => Y.
-
#end_entry? ⇒ Boolean
Returns true iff the vertex is an end vertex (i.e. of the form: X.).
-
#entry_entry? ⇒ Boolean
Returns true iff the vertex is at the start of rhs (i.e. of the form: X => .Y.
-
#exit_entry? ⇒ Boolean
Returns true iff the vertex is at end of rhs (i.e. of the form: X => Y.).
-
#initialize(aVertex, theOrigin) ⇒ ParseEntry
constructor
A new instance of ParseEntry.
-
#next_symbol ⇒ Object
Return the symbol after the dot (if any).
-
#orphan? ⇒ Boolean
Return true if the entry has no antecedent entry.
-
#prev_symbol ⇒ Object
Return the symbol before the dot (if any).
-
#start_entry? ⇒ Boolean
Returns true iff the vertex is a start vertex (i.e. of the form: .X).
-
#to_s ⇒ String
Give a String representation of itself.
Constructor Details
#initialize(aVertex, theOrigin) ⇒ ParseEntry
Returns a new instance of ParseEntry.
21 22 23 24 25 |
# File 'lib/rley/parser/parse_entry.rb', line 21 def initialize(aVertex, theOrigin) @vertex = valid_vertex(aVertex) @origin = theOrigin @antecedents = [] end |
Instance Attribute Details
#antecedents ⇒ Object (readonly)
Links to preceding parse entries
15 16 17 |
# File 'lib/rley/parser/parse_entry.rb', line 15 def antecedents @antecedents end |
#origin ⇒ Object (readonly)
the position in the input that matches the beginning of the rhs of the production.
19 20 21 |
# File 'lib/rley/parser/parse_entry.rb', line 19 def origin @origin end |
#vertex ⇒ Object (readonly)
Link to a vertex of the GFG
12 13 14 |
# File 'lib/rley/parser/parse_entry.rb', line 12 def vertex @vertex end |
Instance Method Details
#==(other) ⇒ Object
Equality comparison. A parse entry behaves as a value object.
33 34 35 36 37 38 |
# File 'lib/rley/parser/parse_entry.rb', line 33 def ==(other) return true if object_id == other.object_id result = (vertex == other.vertex) && (origin == other.origin) return result end |
#add_antecedent(anAntecedent) ⇒ Object
Add a link to an antecedent parse entry
28 29 30 |
# File 'lib/rley/parser/parse_entry.rb', line 28 def add_antecedent(anAntecedent) antecedents << anAntecedent end |
#dotted_entry? ⇒ Boolean
Returns true iff the vertex corresponds to a dotted item X => Y
55 56 57 |
# File 'lib/rley/parser/parse_entry.rb', line 55 def dotted_entry? return vertex.kind_of?(GFG::ItemVertex) end |
#end_entry? ⇒ Boolean
Returns true iff the vertex is an end vertex (i.e. of the form: X.)
65 66 67 |
# File 'lib/rley/parser/parse_entry.rb', line 65 def end_entry?() return 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
47 48 49 50 51 |
# File 'lib/rley/parser/parse_entry.rb', line 47 def entry_entry?() return false unless vertex.kind_of?(GFG::ItemVertex) return 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.)
60 61 62 |
# File 'lib/rley/parser/parse_entry.rb', line 60 def exit_entry?() return vertex.complete? end |
#next_symbol ⇒ Object
Return the symbol after the dot (if any)
76 77 78 |
# File 'lib/rley/parser/parse_entry.rb', line 76 def next_symbol() return vertex.next_symbol end |
#orphan? ⇒ Boolean
Return true if the entry has no antecedent entry
81 82 83 |
# File 'lib/rley/parser/parse_entry.rb', line 81 def orphan?() return antecedents.empty? end |
#prev_symbol ⇒ Object
Return the symbol before the dot (if any)
71 72 73 |
# File 'lib/rley/parser/parse_entry.rb', line 71 def prev_symbol() return vertex.prev_symbol end |
#start_entry? ⇒ Boolean
Returns true iff the vertex is a start vertex (i.e. of the form: .X)
41 42 43 |
# File 'lib/rley/parser/parse_entry.rb', line 41 def start_entry?() return vertex.kind_of?(GFG::StartVertex) end |
#to_s ⇒ String
Give a String representation of itself. The format of the text representation is "format of dotted rule" + " | " + origin
125 126 127 |
# File 'lib/rley/parser/parse_entry.rb', line 125 def to_s() return vertex.label + " | #{origin}" end |