Returns the buffer, applying an code remaining on the stack.
Places the top stack item into the buffer.
Places str onto a stack that can latter be popped into the current buffer.
Places str into the buffer.
Places str onto a stack that can latter be popped into the current buffer.
Places str into the buffer.
Example usage
auto indentCount = 0; auto code = CodeBuilder(indentCount); code.put("void main() {\n", Indent.open); code.push("}\n"); code.put("int a = 5;\n"); code.put("multiply(a);\n"); code.pop(); code.put("\nvoid multiply(int v) {\n", Indent.open); code.push("}\n"); code.put("try {\n", Indent.open); auto catchblock = CodeBuilder(1); catchblock.put("} catch(Exception e) {\n", Indent.close | Indent.open); catchblock.put("import std.stdio;\n"); catchblock.put("writeln(`Exception is bad but I don't care.`);\n"); catchblock.put("}\n", Indent.close); code.push(catchblock); code.put("return v * "); code.rawPut(76.to!string ~ ";\n");
An output range that provides extended functionality for constructing a well formatted string of code.
CodeBuilder has three main operations.
put
The main operation for placing code into the buffer. This will sequentially place code into the buffer. Similar operations are provided for the other operations.
rawPut will place the string without indentation added.
One can place the current indentation level without code by calling put("");
push
This places code onto a stack. pop can be used to put the code into the buffer.
build
Building code in a sequence can be pushed onto the stack, or saved to be put into the buffer later.