Class: Riml::Compiler::EstablishScopeVisitor

Inherits:
DrillDownVisitor show all
Defined in:
lib/riml/compiler.rb

Instance Method Summary collapse

Methods inherited from DrillDownVisitor

#walk_node!

Constructor Details

#initialize(options) ⇒ EstablishScopeVisitor

Returns a new instance of EstablishScopeVisitor.



522
523
524
525
# File 'lib/riml/compiler.rb', line 522

def initialize(options)
  @scope = options[:scope]
  @nested_function = options[:nested_function]
end

Instance Method Details

#establish_scope(node) ⇒ Object



531
532
533
534
535
536
537
538
539
540
# File 'lib/riml/compiler.rb', line 531

def establish_scope(node)
  if node.scope && !@nested_function
    node.scope = node.scope.merge @scope
  elsif node.scope
    node.scope = @scope.merge_parent_function(node.scope)
  else
    node.scope = @scope
  end
  walk_node!(node)
end

#visit(node) ⇒ Object



527
528
529
# File 'lib/riml/compiler.rb', line 527

def visit(node)
  establish_scope(node)
end