lib/ravensat/ast/node.rb in ravensat-1.0.0 vs lib/ravensat/ast/node.rb in ravensat-1.0.1

- old
+ new

@@ -5,44 +5,17 @@ attr_reader :children def initialize @children = [] end - # def each - # yield(self) - # @children.each do |child| - # child.each {|c| yield(c)} - # end - # end - - # def each - # case self - # when AndNode, OrNode - # @children.first.each{|c| yield(c)} - # yield(self) - # @children.last.each{|c| yield(c)} - # when NotNode - # yield(self) - # @children.first.each{|c| yield(c)} - # when VarNode - # yield(self) - # end - # end - - def each_DP + def each_by_descriptive node_stack = [[self, self.children.clone]] #[[parent, children], ...] until node_stack.empty? current_parent, current_children = node_stack.pop current_node = current_children.shift -# puts 'loop' -# puts "node_stack.size:#{node_stack.size}" -# puts "current_parent:#{current_parent.class}" -# puts "current_children.size:#{current_children.size}" -# puts "current_node:#{current_node.class}" - case current_node when AndNode node_stack.push [current_parent, current_children.clone] node_stack.push [current_node, current_node.children.clone] when OrNode @@ -66,11 +39,10 @@ else yield(current_parent) node_stack.push [current_parent, current_children.clone] end end - end end def each return to_enum unless block_given? @@ -84,16 +56,9 @@ node_stack = node_stack.concat(current_node.children) end self if block_given? - end - - def each_naive - yield(self) - @children.each do |child| - child.each {|c| yield(c)} - end end def &(object) AndNode.new(self, object) end