Class: Yoda::Parsing::Scopes::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/parsing/scopes/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Builder

Returns a new instance of Builder.

Parameters:



9
10
11
12
# File 'lib/yoda/parsing/scopes/builder.rb', line 9

def initialize(node)
  @node = node
  @root_scope = Root.new(node)
end

Instance Attribute Details

#nodeAST::Node (readonly)

Returns:



6
7
8
# File 'lib/yoda/parsing/scopes/builder.rb', line 6

def node
  @node
end

Instance Method Details

#build(node, scope) ⇒ void

This method returns an undefined value.

Parameters:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/yoda/parsing/scopes/builder.rb', line 26

def build(node, scope)
  return if !node || !node.is_a?(AST::Vnode)
  case node.type
  when :def
    mscope = MethodDefinition.new(node, scope)
    scope.method_definitions << mscope
    mscope.body_nodes.each { |node| build(node, mscope)}
  when :defs
    mscope = SingletonMethodDefinition.new(node, scope)
    scope.method_definitions << mscope
    mscope.body_nodes.each { |node| build(node, mscope)}
  when :class
    cscope = ClassDefinition.new(node, scope)
    scope.child_scopes << cscope
    cscope.body_nodes.each { |node| build(node, cscope)}
  when :sclass
    cscope = SingletonClassDefinition.new(node, scope)
    scope.child_scopes << cscope
    cscope.body_nodes.each { |node| build(node, cscope)}
  when :module
    mscope = ModuleDefinition.new(node, scope)
    scope.child_scopes << mscope
    mscope.body_nodes.each { |node| build(node, mscope)}
  when :begin, :kwbegin, :block
    node.children.each { |node| build(node, scope) }
  else
    if node.respond_to?(:children)
      node.children.map { |node| build(node, scope) }
    end
  end
end

#root_scopeScope

Returns:

  • (Scope)


15
16
17
18
19
20
21
# File 'lib/yoda/parsing/scopes/builder.rb', line 15

def root_scope
  unless @did_build
    @did_build = true
    build(node, @root_scope)
  end
  @root_scope
end