Class: Riml::Compiler::LiteralNodeVisitor

Inherits:
Visitor
  • Object
show all
Defined in:
lib/compiler.rb

Instance Method Summary collapse

Methods inherited from Visitor

#initialize, #visit

Constructor Details

This class inherits a constructor from Riml::Compiler::Visitor

Instance Method Details

#compile(node) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/compiler.rb', line 160

def compile(node)
  value = case node.value
  when TrueClass
    1
  when FalseClass
    0
  when Numeric
    node.value
  when String
    StringNode === node ? string_surround(node) : node.value
  when Array
    node.value.each {|n| n.parent_node = node}
    '[' <<
    node.value.map do |n|
      n.accept(visitor_for_node(n))
      n.compiled_output
    end.join(', ') << ']'
  when Hash
    node.value.each {|k_n, v_n| k_n.parent_node, v_n.parent_node = node, node}
    '{' <<
    node.value.map do |k,v|
      k.accept(visitor_for_node(k))
      v.accept(visitor_for_node(v))
      k.compiled_output << ': ' << v.compiled_output
    end.join(', ') << '}'
  end.to_s

  node.compiled_output = value
end