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

#subnodes

Attributes inherited from SPPFNode

#range

Instance Method Summary collapse

Methods inherited from CompositeNode

#key

Methods inherited from SPPFNode

#origin

Constructor Details

#initialize(aNonTerminal, aRange) ⇒ NonTerminalNode

Returns a new instance of NonTerminalNode.



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

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



13
14
15
# File 'lib/rley/sppf/non_terminal_node.rb', line 13

def refinement
  @refinement
end

#symbolObject (readonly)

Link to the non-terminal symbol



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

def symbol
  @symbol
end

Instance Method Details

#add_subnode(aSubnode) ⇒ Object



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

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

#to_string(indentation) ⇒ Object

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



31
32
33
# File 'lib/rley/sppf/non_terminal_node.rb', line 31

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