Class: WLang::Compiler::StrconcatFlattener

Inherits:
Filter
  • Object
show all
Defined in:
lib/wlang/compiler/strconcat_flattener.rb

Instance Method Summary collapse

Methods included from Filter::ClassMethods

#recurse_on

Methods included from Filter::InstanceMethods

#recurse

Instance Method Details

#on_strconcat(*children) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/wlang/compiler/strconcat_flattener.rb', line 5

def on_strconcat(*children)
  if children.size == 1
    call(children.first)
  else
    children.inject [:strconcat] do |rw,child|
      child = call(child)
      if child.first == :strconcat
        child[1..-1].each do |subchild|
          rw << subchild
        end
      else
        rw << child
      end
      rw
    end
  end
end