Class: Rley::SPPF::NonTerminalNode

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

Overview

A node in a parse forest that matches exactly one non-terminal symbol.

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, #inspect, #key, #signature_exist?

Methods inherited from SPPFNode

#origin

Constructor Details

#initialize(aNonTerminal, aRange) ⇒ NonTerminalNode

Constructor

Parameters:



20
21
22
23
24
# File 'lib/rley/sppf/non_terminal_node.rb', line 20

def initialize(aNonTerminal, aRange)
  super(aRange)
  @symbol = aNonTerminal
  @refinement = :and
end

Instance Attribute Details

#refinementObject

Indication on how the sub-nodes contribute to the 'success' of parent node. Possible values: :and, :or



15
16
17
# File 'lib/rley/sppf/non_terminal_node.rb', line 15

def refinement
  @refinement
end

#symbolSyntax::NonTerminal (readonly)

Returns Link to the non-terminal symbol.

Returns:



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

def symbol
  @symbol
end

Instance Method Details

#accept(aVisitor) ⇒ Object

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

Parameters:



45
46
47
# File 'lib/rley/sppf/non_terminal_node.rb', line 45

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

#add_subnode(aSubnode) ⇒ Object

Add a sub-node (child) to this one.

Parameters:



28
29
30
31
32
33
34
# File 'lib/rley/sppf/non_terminal_node.rb', line 28

def add_subnode(aSubnode)
  if refinement == :or
    subnodes << aSubnode
  else
    super(aSubnode)
  end
end

#to_string(indentation) ⇒ String

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

Returns:

  • (String)

    a text representation of the node.



39
40
41
# File 'lib/rley/sppf/non_terminal_node.rb', line 39

def to_string(indentation)
  return "#{symbol.name}#{range.to_string(indentation)}"
end