# Copyright 2005-2007 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ pragma.syntax("0.9") def makeVisitor(writer, depth) :any { return def condensedDumpVisitor { match [`visit@name`, [_] + elements] { def single := elements.size() <=> 1 def step := if (single) { "" } else { " " } writer.print(name.replaceAll("Expr", "E.").replaceAll("Pattern", "P.")) def nextWriter := writer.indent(step) for element in elements { if (single) { nextWriter.write(" ") } else { nextWriter.println() } if (element.__respondsTo("welcome", 1)) { element.welcome(makeVisitor(nextWriter, depth + 1)) } else if (element =~ l :List ? (l !~ s :String)) { E.call(makeVisitor(nextWriter, depth + 1), "visit[]", [null] + l) } else { nextWriter.print(element) } } } } } def dumpENodes implements ExitViaHere { to run(node, out) { node.welcome(makeVisitor(out, 0)) } }