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
1 auto indentCount = 0; 2 auto code = CodeBuilder(indentCount); 3 code.put("void main() {\n", Indent.open); 4 code.push("}\n"); 5 code.put("int a = 5;\n"); 6 code.put("multiply(a);\n"); 7 code.pop(); 8 9 code.put("\nvoid multiply(int v) {\n", Indent.open); 10 code.push("}\n"); 11 code.put("try {\n", Indent.open); 12 auto catchblock = CodeBuilder(1); 13 catchblock.put("} catch(Exception e) {\n", Indent.close | Indent.open); 14 catchblock.put("import std.stdio;\n"); 15 catchblock.put("writeln(`Exception is bad but I don't care.`);\n"); 16 catchblock.put("}\n", Indent.close); 17 code.push(catchblock); 18 19 code.put("return v * "); 20 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.