Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Fix wrong flatten in AST::Visitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Apr 11, 2012
1 parent b1cd6ac commit cc3b779
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/furnace/ast/visitor.rb
@@ -1,19 +1,31 @@
module Furnace::AST module Furnace::AST
module Visitor module Visitor
def visit(node) def visit(node)
node.children.map! do |child| replacements = {}

node.children.each_with_index do |child, index|
if child.is_a? Node if child.is_a? Node
visit child visit child


if child.type == :expand if child.type == :expand
child = child.children replacements[index] = child.children
end end
end end

child
end end


node.children.flatten! if replacements.any?
new_children = []

node.children.each_with_index do |child, index|
if replacements[index]
new_children.concat replacements[index]
else
new_children.push child
end
end

node.children.replace new_children
end


node.children.delete_if do |child| node.children.delete_if do |child|
if child.is_a? Node if child.is_a? Node
Expand Down

0 comments on commit cc3b779

Please sign in to comment.