class TreeStack
Attributes
current_node[R]
last_leaf[R]
node_end[R]
Public Class Methods
new(root_node=Node.new)
click to toggle source
# File lib/pseudohiki/treestack.rb, line 64 def initialize(root_node=Node.new) @stack = [root_node] @current_node = root_node # @stack[-1] @node_end = NodeEnd.new root_node.depth = 0 end
Public Instance Methods
accept(visitor, memo=nil)
click to toggle source
# File lib/pseudohiki/treestack.rb, line 110 def accept(visitor, memo=nil) visitor.visit(tree, memo) end
pop()
click to toggle source
# File lib/pseudohiki/treestack.rb, line 80 def pop return unless @stack.length > 1 @current_node = @stack[-2] @stack.pop end
Also aliased as: return_to_previous_node
push(node=Node.new)
click to toggle source
# File lib/pseudohiki/treestack.rb, line 75 def push(node=Node.new) @last_leaf = node.push_self(self) node end
push_as_child_node(node)
click to toggle source
# File lib/pseudohiki/treestack.rb, line 87 def push_as_child_node(node) @current_node.push node @current_node = node @stack.push node end
push_as_leaf(node)
click to toggle source
# File lib/pseudohiki/treestack.rb, line 93 def push_as_leaf(node) @current_node.push node end
push_as_sibling(sibling_node=nil)
click to toggle source
# File lib/pseudohiki/treestack.rb, line 97 def push_as_sibling(sibling_node=nil) sibling_node ||= @current_node.class.new pop if sibling_node.kind_of? NodeType push(sibling_node) sibling_node end
remove_current_node()
click to toggle source
# File lib/pseudohiki/treestack.rb, line 104 def remove_current_node removed_node = pop @current_node.pop removed_node end
tree()
click to toggle source
# File lib/pseudohiki/treestack.rb, line 71 def tree @stack[0] end