Class Amrita::NodeArray
In: lib/amrita/compiler.rb
lib/amrita/node.rb
lib/amrita/format.rb
lib/amrita/node_expand.rb
Parent: Object

represents an Array of Node. It is a Node also.

Methods

+   <<   ==   []   apply_to_children   children   clone   compile   format   new   no_child?   pre_format1   size   to_ruby  

Included Modules

Node

Attributes

array  [R] 

Public Class methods

[Source]

# File lib/amrita/node.rb, line 585
    def initialize(*elements)
      if elements.size() == 1 and elements[0].kind_of?(NodeArray)
        a = elements[0]
        @array = a.array.collect { |n| n.clone }
      else
        @array = elements.collect do |a|
          #raise "can't be a parent of me!" if a.id == self.id # no recusive check because it costs too much
          to_node(a)
        end
      end
    end

Public Instance methods

[Source]

# File lib/amrita/node.rb, line 631
    def +(node)
      ret = clone
      ret << node
      ret
    end

[Source]

# File lib/amrita/node.rb, line 637
    def <<(node)
      raise "can't be a parent of me!" if node == self
      @array << to_node(node)
      self
    end

[Source]

# File lib/amrita/node.rb, line 597
    def ==(x)
      return false unless x.kind_of?(NodeArray)
      case x
      when NodeArray, Array
        return false unless x.size() == @array.size()
        @array.each_with_index do |n, i|
          return false unless n == x[i]
        end
        true
      else
        false
      end
    end

[Source]

# File lib/amrita/node.rb, line 615
    def [](index)
      @array[index]
    end

[Source]

# File lib/amrita/node_expand.rb, line 342
    def apply_to_children(&block)
      ret =@array.collect do |n|
        yield(n)
      end
      Node::to_node(ret)
    end

[Source]

# File lib/amrita/node.rb, line 627
    def children
      @array
    end

[Source]

# File lib/amrita/node.rb, line 623
    def clone
      NodeArray.new(self)
    end

[Source]

# File lib/amrita/compiler.rb, line 105
    def compile(compiler)
      children.each { |node| node.compile(compiler) }
    end

[Source]

# File lib/amrita/format.rb, line 577
    def format(f)
      @array.each { |n| n.format(f) }
    end

[Source]

# File lib/amrita/node.rb, line 619
    def no_child?
      @array.empty?
    end

[Source]

# File lib/amrita/format.rb, line 581
    def pre_format1(prf)
      @array.each do |n|
        n.pre_format1(prf)
      end
    end

[Source]

# File lib/amrita/node.rb, line 611
    def size()
      @array.size()
    end

[Source]

# File lib/amrita/node.rb, line 643
    def to_ruby
      "[ " + @array.collect {|e| e.to_ruby}.join(", ") + " ]"
    end

[Validate]