Sha256: 7cabba14d7acf3f63f4a0577e34ce6a06732a92fcd2b0c1ab83ead07e06e51bc

Contents?: true

Size: 1.22 KB

Versions: 8

Compression:

Stored size: 1.22 KB

Contents

require_relative 'parse_tree_node'  # Load superclass

module Rley # This module is used as a namespace
  module PTree # This module is used as a namespace
    class NonTerminalNode < ParseTreeNode
      # Link to the input token
      attr_reader(:children)

      def initialize(aSymbol, aRange)
        super(aSymbol, aRange)
        @children = []
      end

      # @param aChildNode [ParseTreeNode-like] a child node.
      def add_child(aChildNode)
        children << aChildNode
      end
      
      # Emit a (formatted) string representation of the node.
      # Mainly used for diagnosis/debugging purposes.
      def to_string(indentation)
        connector = '+- '
        selfie = super(indentation)
        prefix = "\n" + (' ' * connector.size * indentation) + connector
        children_repr = children.reduce('') do |sub_result, child|
          sub_result << prefix + child.to_string(indentation + 1) 
        end
        
        return selfie + children_repr
      end
      
      # Part of the 'visitee' role in Visitor design pattern.
      # @param aVisitor[ParseTreeVisitor] the visitor
      def accept(aVisitor)
        aVisitor.visit_nonterminal(self)
      end
    end # class
  end # module
end # module
# End of file

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rley-0.3.04 lib/rley/ptree/non_terminal_node.rb
rley-0.3.01 lib/rley/ptree/non_terminal_node.rb
rley-0.3.00 lib/rley/ptree/non_terminal_node.rb
rley-0.2.15 lib/rley/ptree/non_terminal_node.rb
rley-0.2.14 lib/rley/ptree/non_terminal_node.rb
rley-0.2.12 lib/rley/ptree/non_terminal_node.rb
rley-0.2.11 lib/rley/ptree/non_terminal_node.rb
rley-0.2.10 lib/rley/ptree/non_terminal_node.rb