Class: Rley::GFG::Vertex
- Inherits:
-
Object
- Object
- Rley::GFG::Vertex
- Defined in:
- lib/rley/gfg/vertex.rb
Overview
Abstract class. Represents a vertex in a grammar flow graph Responsibilities:
- To know its outgoing edges
- To know its label
Direct Known Subclasses
Instance Attribute Summary collapse
-
#edges ⇒ Array<Edge>
readonly
The edges linking the successor vertices to this one.
-
#oid_str ⇒ String
readonly
Return the object id in string format.
Instance Method Summary collapse
-
#add_edge(anEdge) ⇒ Object
Add an graph edge to this vertex.
-
#complete? ⇒ Boolean
Determine if the vertex corresponds to an dotted item that has its dot at the end of a production (i.e. is a reduced item).
-
#initialize ⇒ Vertex
constructor
Constructor to extend in subclasses.
-
#inspect ⇒ String
Returns a string containing a human-readable representation of the vertex.
-
#next_symbol ⇒ GrmSymbol, NilClass
Retrieve the grammar symbol after the dot.
-
#prev_symbol ⇒ GrmSymbol, NilClass
Retrieve the grammar symbol before the dot.
-
#selfie ⇒ String
Returns a string containing a human-readable representation of the vertex without the edges.
Constructor Details
#initialize ⇒ Vertex
Constructor to extend in subclasses.
19 20 21 22 |
# File 'lib/rley/gfg/vertex.rb', line 19 def initialize @edges = [] @oid_str = object_id.to_s end |
Instance Attribute Details
#edges ⇒ Array<Edge> (readonly)
The edges linking the successor vertices to this one.
12 13 14 |
# File 'lib/rley/gfg/vertex.rb', line 12 def edges @edges end |
#oid_str ⇒ String (readonly)
Return the object id in string format
16 17 18 |
# File 'lib/rley/gfg/vertex.rb', line 16 def oid_str @oid_str end |
Instance Method Details
#add_edge(anEdge) ⇒ Object
Add an graph edge to this vertex.
67 68 69 70 |
# File 'lib/rley/gfg/vertex.rb', line 67 def add_edge(anEdge) arrow = check_add_edge(anEdge) edges << arrow end |
#complete? ⇒ Boolean
Determine if the vertex corresponds to an dotted item that has its dot at the end of a production (i.e. is a reduced item).
27 28 29 |
# File 'lib/rley/gfg/vertex.rb', line 27 def complete? false # Default implementation end |
#inspect ⇒ String
Returns a string containing a human-readable representation of the vertex.
34 35 36 37 38 39 40 41 42 |
# File 'lib/rley/gfg/vertex.rb', line 34 def inspect result = +'#<' result << selfie edges.each { |e| result << e.inspect } result << specific_inspect result << '>' result end |
#next_symbol ⇒ GrmSymbol, NilClass
Retrieve the grammar symbol after the dot.
61 62 63 |
# File 'lib/rley/gfg/vertex.rb', line 61 def next_symbol nil # Default implementation end |
#prev_symbol ⇒ GrmSymbol, NilClass
Retrieve the grammar symbol before the dot.
55 56 57 |
# File 'lib/rley/gfg/vertex.rb', line 55 def prev_symbol nil # Default implementation end |
#selfie ⇒ String
Returns a string containing a human-readable representation of the vertex without the edges.
47 48 49 50 51 |
# File 'lib/rley/gfg/vertex.rb', line 47 def selfie result = +"#{self.class.name}:#{object_id}" result << %( label="#{label}") result end |