Class: Rley::SPPF::AlternativeNode

Inherits:
CompositeNode show all
Defined in:
lib/rley/sppf/alternative_node.rb

Overview

A node in a parse forest that is a child of a parent node with :or refinement

Instance Attribute Summary collapse

Attributes inherited from CompositeNode

#signatures, #subnodes

Attributes inherited from SPPFNode

#range

Instance Method Summary collapse

Methods inherited from CompositeNode

#add_edge_signatures, #add_subnode, #inspect, #key, #signature_exist?

Methods inherited from SPPFNode

#origin

Constructor Details

#initialize(aVertex, aRange) ⇒ AlternativeNode

Returns a new instance of AlternativeNode.

Parameters:

  • aVertex (GFG::ItemVertex)

    A GFG vertex that corresponds to a dotted item with the dot at the end) for the alternative under consideration.

  • aRange (Lexical::TokenRange)

    A range of token indices corresponding to this node.



21
22
23
24
25
# File 'lib/rley/sppf/alternative_node.rb', line 21

def initialize(aVertex, aRange)
  super(aRange)
  @label = aVertex.label
  @symbol = aVertex.dotted_item.lhs
end

Instance Attribute Details

#labelString (readonly)

Returns GFG vertex label.

Returns:

  • (String)

    GFG vertex label



11
12
13
# File 'lib/rley/sppf/alternative_node.rb', line 11

def label
  @label
end

#symbolSyntax::NonTerminal (readonly)

Returns Link to lhs symbol.

Returns:



14
15
16
# File 'lib/rley/sppf/alternative_node.rb', line 14

def symbol
  @symbol
end

Instance Method Details

#accept(aVisitor) ⇒ Object

Part of the 'visitee' role in Visitor design pattern.

Parameters:



36
37
38
# File 'lib/rley/sppf/alternative_node.rb', line 36

def accept(aVisitor)
  aVisitor.visit_alternative(self)
end

#to_string(indentation) ⇒ String

Emit a (formatted) string representation of the node. Mainly used for diagnosis/debugging purposes.

Returns:

  • (String)


30
31
32
# File 'lib/rley/sppf/alternative_node.rb', line 30

def to_string(indentation)
  "Alt(#{label})#{range.to_string(indentation)}"
end