expand

Expand macro.

The macro processor is the same one used in Ddoc.

string
expand
(
const(char)[] text
,
string[string] table
,
bool html = false
)

Parameters

text const(char)[]

source text to expand

table string[string]

table of name=value macro definitions

html bool

true if recognize HTML tags and comments

Return Value

Type: string

The source text after macro expansion. The return string is GC allocated.

Examples

    import std.stdio;

    string[string] table;
    string s;

    s = expand("hello", table);
    assert(s == "hello");

    table["ABC"] = "def";
    s = expand("foo$(ABC)", table);
    assert(s == "foodef");

    s = expand("foo$(DEF)", table);
    assert(s == "foo");

    table["GHI"] = "";
    s = expand("foo$(GHI)x", table);
    assert(s == "foox");

    table["JKI"] = "$(JKI)";
    s = expand("foo$(JKI)x", table);
    assert(s == "foox");

    s = expand("foo$$(JKI)x", table);
    assert(s == "foo$(JKI)x");

    s = expand("foo$(123)x", table);
    assert(s == "foo$(123)x");

    table["M3"] = "$0";
    s = expand("foo$(M3)x", table);
    assert(s == "foox");

    s = expand("foo$(M3 $(M3 1) 1)x", table);
    assert(s == "foo1 1x");

    table["M4"] = "$+";
    s = expand("foo$(M4 1,2,3)x", table);
    assert(s == "foo2,3x");

    table["M5"] = "$$1";
    s = expand("foo$(M5 1,2,3)x", table);
    assert(s == "foo$1x");

    table["M6"] = "$(M6 $0)";
    s = expand("foo$(M6 1)x", table);
//writefln("s = '%s'", s);
    assert(s == "foo$(M6 1)x");

Meta