private static void walk(Writer writer, CommonTree tree, String dent,
			TokenTypes types) throws IOException {

		final int type = tree.getType();

		if (types.isLiteral(type) || types.isToken(type)) {
			// TODO Should escape stuff where necessary.
		//	Tuple4<Integer, Integer, Integer, Integer> token = getTokenPosition(tree);
			// Get the token data
			Token koopaToken = ((CommonKoopaToken)tree.token).getKoopaToken();

			writer.append(dent + "<TOKEN startline=\"" + getLineNum(koopaToken.getStart().getLinenumber()) +
					"\" startpos=\"" + koopaToken.getStart().getOffsetPositionInLine() +
					"\" endline=\"" + getLineNum(koopaToken.getEnd().getLinenumber()) +
					"\" endpos=\"" + (koopaToken.getEnd().getOffsetPositionInLine() + 1) + "\">" +
						tree.getText() + "</TOKEN>" + enterkey);
			return;
		}

		if (tree.getChildCount() == 0) {
			writer.append(dent + "<" + tree.getText());
			writePositions(writer, tree);
			writer.append(" />" + enterkey);

		} else {
			writer.append(dent + "<" + tree.getText());
			writePositions(writer, tree);
			writer.append(">" + enterkey);

			for (Object child : tree.getChildren()) {
				walk(writer, (CommonTree) child, dent + "  ", types);
			}

			writer.append(dent + "</" + tree.getText() + ">" + enterkey);
		}
	}