class Riml::Compiler::TryNodeVisitor

Public Instance Methods

compile(node) click to toggle source

try_block, catch_nodes, finally_block

# File lib/riml/compiler.rb, line 661
def compile(node)
  try, catches, finally = node.try_block, node.catch_nodes, node.finally_block
  node.compiled_output = "try\n"
  try.accept(visitor_for_node(try, :propagate_up_tree => false))
  try.compiled_output.each_line do |line|
    node.compiled_output << node.indent + line
  end

  catches.each do |c|
    c.accept(visitor_for_node(c, :propagate_up_tree => false))
    c.compiled_output.each_line do |line|
      outdent = line =~ /\A\s*catch/
      if outdent && c.non_nested?
        node.compiled_output << node.outdent + line
      else
        node.compiled_output << node.indent + line
      end
    end
  end if catches

  if finally
    node.compiled_output << "finally\n"
    finally.accept(visitor_for_node(finally, :propagate_up_tree => false))
    finally.compiled_output.each_line do |line|
      node.compiled_output << node.indent + line
    end
  end
  node.compiled_output << "endtry\n"
end