Class: Atomy::Grammar::AST::Block

Inherits:
Node show all
Defined in:
lib/atomy/grammar.rb,
lib/atomy/node/meta.rb,
lib/atomy/node/pretty.rb,
lib/atomy/node/equality.rb,
lib/atomy/node/constructable.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#accept, #attributes, basename, #children, #each_attribute

Constructor Details

#initialize(nodes) ⇒ Block

Returns a new instance of Block.



67
68
69
# File 'lib/atomy/grammar.rb', line 67

def initialize(nodes)
  @nodes = nodes
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



70
71
72
# File 'lib/atomy/grammar.rb', line 70

def nodes
  @nodes
end

Instance Method Details

#==(other) ⇒ Object



81
82
83
# File 'lib/atomy/node/equality.rb', line 81

def ==(other)
  super || other.is_a?(self.class) && @nodes == other.nodes
end

#construct(gen) ⇒ Object



120
121
122
123
124
125
126
127
# File 'lib/atomy/node/constructable.rb', line 120

def construct(gen)
  push_node(gen, :Block)
  @nodes.each do |node|
    node.construct(gen)
  end
  gen.make_array(@nodes.size)
  gen.send(:new, 1)
end

#each_child {|:nodes, @nodes| ... } ⇒ Object

Yields:



160
161
162
# File 'lib/atomy/node/meta.rb', line 160

def each_child
  yield :nodes, @nodes
end

#throughObject



164
165
166
# File 'lib/atomy/node/meta.rb', line 164

def through
  self.class.new(@nodes.collect { |n| yield n })
end

#to_sObject



76
77
78
79
80
81
82
# File 'lib/atomy/node/pretty.rb', line 76

def to_s
  if @nodes.empty?
    "{}"
  else
    "{ #{@nodes.join(", ")} }"
  end
end