using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using HeuristicLab.Grammars; using Attribute = HeuristicLab.Grammars.Attribute; namespace CodeGenerator { public class SourceBuilder { private readonly StringBuilder sb; private int indent; public SourceBuilder() { sb = new StringBuilder(); indent = 0; } public SourceBuilder BeginBlock() { indent += 2; return AppendLine(); } public SourceBuilder EndBlock() { indent -= 2; return AppendLine(); } public SourceBuilder Append(string str) { sb.Append(' ', indent).Append(str); return this; } public SourceBuilder AppendFormat(string fmtString, params object[] args) { sb.Append(' ', indent).AppendFormat(fmtString, args); return this; } public SourceBuilder AppendLine() { sb.Append(' ', indent).AppendLine(); return this; } public SourceBuilder AppendLine(string str) { sb.Append(' ', indent).AppendLine(str); return this; } public SourceBuilder Replace(string oldValue, string newValue) { sb.Replace(oldValue, newValue); return this; } public override string ToString() { return sb.ToString(); } } }