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

#subnodes

Attributes inherited from SPPFNode

#range

Instance Method Summary collapse

Methods inherited from CompositeNode

#add_subnode, #inspect, #key

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.



19
20
21
22
23
# File 'lib/rley/sppf/alternative_node.rb', line 19

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



9
10
11
# File 'lib/rley/sppf/alternative_node.rb', line 9

def label
  @label
end

#symbolSyntax::NonTerminal (readonly)

Returns Link to lhs symbol.

Returns:



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

def symbol
  @symbol
end

Instance Method Details

#to_string(indentation) ⇒ String

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

Returns:

  • (String)


28
29
30
# File 'lib/rley/sppf/alternative_node.rb', line 28

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