class Koara::TreeState
Public Class Methods
new()
click to toggle source
# File lib/koara/tree_state.rb, line 4 def initialize @nodes = [] @marks = [] @nodes_on_stack = 0 @current_mark = 0 end
Public Instance Methods
add_single_value(n, t)
click to toggle source
# File lib/koara/tree_state.rb, line 28 def add_single_value(n, t) open_scope n.value = t.image close_scope(n) end
close_scope(n)
click to toggle source
# File lib/koara/tree_state.rb, line 16 def close_scope(n) a = node_arity @current_mark = @marks.delete_at(@marks.size - 1) while a > 0 a -= 1 c = pop_node c.parent = n n.add(c, a) end push_node(n) end
node_arity()
click to toggle source
# File lib/koara/tree_state.rb, line 34 def node_arity @nodes_on_stack - @current_mark end
open_scope()
click to toggle source
# File lib/koara/tree_state.rb, line 11 def open_scope @marks.push(@current_mark) @current_mark = @nodes_on_stack end
pop_node()
click to toggle source
# File lib/koara/tree_state.rb, line 38 def pop_node @nodes_on_stack -= 1 @nodes.delete_at(@nodes.size - 1) end
push_node(n)
click to toggle source
# File lib/koara/tree_state.rb, line 43 def push_node(n) @nodes.push(n) @nodes_on_stack += 1 end