class Haml::DynamicMerger

def on_multi(*exps)

def on_multi(*exps)
  exps = exps.dup
  result = [:multi]
  buffer = []
  until exps.empty?
    type, arg = exps.first
    if type == :dynamic && arg.count("\n") == 0
      buffer << exps.shift
    elsif type == :static && exps.size > (count = arg.count("\n")) &&
          exps[1, count].all? { |e| e == [:newline] }
      (1 + count).times { buffer << exps.shift }
    elsif type == :newline && exps.size > (count = count_newline(exps)) &&
          exps[count].first == :static && count == exps[count].last.count("\n")
      (count + 1).times { buffer << exps.shift }
    else
      result.concat(merge_dynamic(buffer))
      buffer = []
      result << compile(exps.shift)
    end
  end
  result.concat(merge_dynamic(buffer))
  result.size == 2 ? result[1] : result
end