def process_defn(exp)
type1 = exp[1].first
type2 = exp[2].first rescue nil
if type1 == :args and [:ivar, :attrset].include? type2 then
name = exp.shift
case type2
when :ivar then
exp.clear
return "attr_reader #{name.inspect}"
when :attrset then
exp.clear
return "attr_writer :#{name.to_s[0..-2]}"
else
raise "Unknown defn type: #{exp.inspect}"
end
end
case type1
when :scope, :args then
name = exp.shift
args = process(exp.shift)
args = "" if args == "()"
body = []
until exp.empty? do
body << indent(process(exp.shift))
end
body = body.join("\n")
return "def #{name}#{args}\n#{body}\nend".gsub(/\n\s*\n+/, "\n")
else
raise "Unknown defn type: #{type1} for #{exp.inspect}"
end
end