addImport

Creates an import statement.

Notes: If selection is null, then the entire module is imported. Otherwise, only the specified symbols are imported.

addImport
(,
dstring moduleName
,
dstring[] selection = null
)

Parameters

builder CodeBuilder

The CodeBuilder to use.

moduleName dstring

The name of the module to import.

selection dstring[]

An array of which symbols to import from the module.

Return Value

builder

Examples

auto builder = new CodeBuilder();

// Import entire module
builder.addImport("std.stdio");
builder.data.should.equal("import std.stdio;\n");

builder = new CodeBuilder(); // Just to keep the asserts clean to read.


// Selective imports
builder.addImport("std.stdio", ["readln"d, "writeln"d]);
builder.data.should.equal("import std.stdio : readln, writeln;\n");

Meta