Class: Riml::Compiler::ForNodeVisitor

Inherits:
ScopedVisitor 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



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
# File 'lib/riml/compiler.rb', line 627

def compile(node)
  scope_visitor = EstablishScopeVisitor.new(:scope => node.to_scope)
  if node.variables
    node.variables.parent_node = node
    node.variables.accept(scope_visitor)
    node.variables.accept(
      visitor_for_node(
        node.variables,
        :propagate_up_tree => false
      )
    )
    node.compiled_output = "for #{node.variables.compiled_output} in "
  else
    node.variable.parent_node = node
    node.variable.accept(scope_visitor)
    set_modifier(node.variable)
    node.compiled_output = "for #{node.variable.full_name} in "
  end
  node.in_expression.parent_node = node
  node.in_expression.force_newline = true
  node.in_expression.accept(visitor_for_node(node.in_expression))
  node.expressions.parent_node = node
  node.expressions.accept(scope_visitor)
  node.expressions.accept(NodesVisitor.new :propagate_up_tree => false)
  body = node.expressions.compiled_output
  body.each_line do |line|
    node.compiled_output << node.indent + line
  end
  node.compiled_output << "endfor\n"
end