Class: Riml::Compiler::DefNodeVisitor
Instance Method Summary
collapse
Methods inherited from Visitor
#initialize
Instance Method Details
#compile(node) ⇒ Object
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
# File 'lib/riml/compiler.rb', line 468
def compile(node)
set_modifier(node)
bang = node.bang
params = process_parameters!(node)
declaration = "function#{bang} #{node.sid}#{node.scope_modifier}"
declaration <<
if node.name.respond_to?(:variable)
node.name.accept(visitor_for_node(node.name))
node.name.compiled_output
else
node.name
end << "(#{params.join(', ')})"
declaration << (node.keywords.empty? ? "\n" : " #{node.keywords.join(' ')}\n")
node.expressions.parent_node = node
node.expressions.accept NodesVisitor.new(:propagate_up_tree => false)
body = ""
unless node.expressions.compiled_output.empty?
node.expressions.compiled_output.each_line do |line|
body << node.indent + line
end
end
node.compiled_output = declaration << body << "endfunction\n"
if current_compiler(node).readable
node.compiled_output << "\n"
else
node.compiled_output
end
end
|
#visit(node) ⇒ Object
459
460
461
462
463
464
465
466
|
# File 'lib/riml/compiler.rb', line 459
def visit(node)
options = {}
if node.nested_function?
options[:nested_function] = true
end
setup_local_scope_for_descendants(node, options)
super
end
|