# File lib/sexp_processor.rb, line 138
  def rewrite(exp)
    type = exp.first

    if @debug.has_key? type then
      str = exp.inspect
      puts "// DEBUG (original ): #{str}" if str =~ @debug[type]
    end

    in_context type do
      exp.map! { |sub| Array === sub ? rewrite(sub) : sub }
    end

    begin
      meth = @rewriters[type]
      exp  = self.send(meth, exp) if meth
      break unless Sexp === exp

      if @debug.has_key? type then
        str = exp.inspect
        puts "// DEBUG (rewritten): #{str}" if str =~ @debug[type]
      end

      old_type, type = type, exp.first
    end until old_type == type

    exp
  end