class Rley::PTree::NonTerminalNode
Attributes
Array of sub-nodes.
Public Class Methods
Source
# File lib/rley/ptree/non_terminal_node.rb, line 11 def initialize(aSymbol, aRange) super(aSymbol, aRange) @subnodes = [] end
Calls superclass method
Public Instance Methods
Source
# File lib/rley/ptree/non_terminal_node.rb, line 39 def accept(aVisitor) aVisitor.visit_nonterminal(self) end
Part of the ‘visitee’ role in Visitor design pattern. @param aVisitor the visitor
Source
# File lib/rley/ptree/non_terminal_node.rb, line 18 def add_subnode(aSubnode) subnodes.unshift(aSubnode) end
Pre-pend the given subnode in front of the list of subnodes @param aSubnode [ParseTreeNode-like] a child node.
Source
# File lib/rley/ptree/non_terminal_node.rb, line 25 def to_string(indentation) connector = '+- ' selfie = super(indentation) prefix = "\n" + (' ' * connector.size * indentation) + connector subnodes_repr = subnodes.reduce(+'') do |sub_result, subnode| sub_result << (prefix + subnode.to_string(indentation + 1)) end selfie + subnodes_repr end
Emit a (formatted) string representation of the node. Mainly used for diagnosis/debugging purposes. rubocop: disable Style/StringConcatenation
Calls superclass method