Class: XDry::ScopeStack

Inherits:
Object
  • Object
show all
Defined in:
lib/xdry/parsing/scope_stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_scopes) ⇒ ScopeStack

Returns a new instance of ScopeStack.



8
9
10
11
# File 'lib/xdry/parsing/scope_stack.rb', line 8

def initialize root_scopes
  @stack = []
  root_scopes.each { |scope| push(scope) }
end

Instance Attribute Details

#verboseObject

Returns the value of attribute verbose.



6
7
8
# File 'lib/xdry/parsing/scope_stack.rb', line 6

def verbose
  @verbose
end

Instance Method Details

#current_scopeObject



33
34
35
# File 'lib/xdry/parsing/scope_stack.rb', line 33

def current_scope
  @current_scope
end

#parse_line(line, eol_comments, indent) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xdry/parsing/scope_stack.rb', line 13

def parse_line line, eol_comments, indent
  parse_line_using_parser! line, eol_comments, indent do |node|
    unless node.nil?  # to simply code we allow the parser to yield nil when it cannot parse something
      # update the scope based on this new node
      while @current_scope.ends_after? node
        yield @current_scope, node
        pop
      end
      if subscope = @current_scope.subscope_for(node)
        # a subscope is added as a child of its parent scope
        yield @current_scope, subscope
        subscope.assert_bound!
        push subscope
      end
      # add the new node to the scope we have finally decided on
      yield @current_scope, node
    end
  end
end