public string ToIndent() { Action<Node> na; Action<List<Node>> nsa = null; const string ind = " "; FList<string> inds = new FList<string>(); StringBuilder b = new StringBuilder(); na = delegate(Node n) { if (n.Leaf != null) { b .Append(inds.Deriv(Cty.ToLine)) .Append(n.Leaf) .AppendLine(); } else if (n.Branches != null) { if (n != this) inds.Add(ind); nsa(n.Branches); if (n != this) inds.RemoveAt(inds.Count - 1); } }; nsa = delegate(List<Node> ns) { if (ns.Count == 0) return; bool isPrevBranch = ns[0].Branches != null; na(ns[0]); for (int i = 1; i < ns.Count; i++) { if (isPrevBranch && ns[i].Branches != null) { b .Append(inds.Deriv(Cty.ToLine)) .Append(ind) .AppendLine(); } isPrevBranch = ns[i].Branches != null; na(ns[i]); } }; na(this); return b.ToString(); }