Class: Riml::Compiler::TryNodeVisitor

Inherits:
Visitor
  • Object
show all
Defined in:
lib/riml/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

try_block, catch_nodes, finally_block



661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
# 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