Class: NScript::ArrayNode

Inherits:
Node
  • Object
show all
Defined in:
lib/nscript/parser/nodes.rb

Constant Summary

Constants inherited from Node

Node::TAB

Instance Method Summary collapse

Methods inherited from Node

#children, children, #compile, #compile_closure, #contains?, #idt, statement, #statement?, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #unwrap, #write

Constructor Details

#initialize(objects = []) ⇒ ArrayNode

Returns a new instance of ArrayNode.



655
656
657
# File 'lib/nscript/parser/nodes.rb', line 655

def initialize(objects=[])
  @objects = objects
end

Instance Method Details

#compile_node(o) ⇒ Object



659
660
661
662
663
664
665
666
667
668
# File 'lib/nscript/parser/nodes.rb', line 659

def compile_node(o)
  o[:indent] = idt(1)
  objects = @objects.map { |obj|
    code = obj.compile(o)
    obj.is_a?(CommentNode) ? "\n#{code}\n#{o[:indent]}" :
    obj == @objects.last   ? code : "#{code}, "
  }.join('')
  ending = objects.include?("\n") ? "\n#{idt}]" : ']'
  write("[#{objects}#{ending}")
end