lib/sexp_processor.rb in ParseTree-1.7.1 vs lib/sexp_processor.rb in ParseTree-2.0.0

- old
+ new

@@ -162,29 +162,20 @@ raise NotEmptyError, msg end end def rewrite(exp) - meth = @rewriters[exp.first] - if meth then - r = self.send(meth, exp) - self.assert_empty(meth, exp, nil) if @require_empty - r - else - result = exp.class.new - until exp.empty? do - sub_exp = exp.shift - sub_result = nil + exp.map! { |sub| Array === sub ? rewrite(sub) : sub } - if Array === sub_exp then - result << rewrite(sub_exp) - else - result << sub_exp - end - end - result - end + type = exp.first + begin + meth = @rewriters[type] + exp = self.send(meth, exp) if meth + old_type, type = type, exp.first + end until old_type == type + + exp end ## # Default Sexp processor. Invokes process_<type> methods matching # the Sexp type given. Performs additional checks as specified by @@ -218,9 +209,14 @@ @debug.has_key? type or @exceptions.has_key?(type) raise UnsupportedNodeError, "'#{type}' is not a supported node type" if @unsupported.include? type exp = self.rewrite(exp) if @process_level == 1 + + if @debug.has_key? type then + str = exp.inspect + puts "// DEBUG (rewritten): #{str}" if str =~ @debug[type] + end # now do a pass with the real processor (or generic) meth = @processors[type] || @default_method if meth then