The OpenD Programming Language

InversionList.toSourceCode

Generates string with D source code of unary function with name of funcName taking a single dchar argument. If funcName is empty the code is adjusted to be a lambda function.

The function generated tests if the $(CODEPOINT) passed belongs to this set or not. The result is to be used with string mixin. The intended usage area is aggressive optimization via meta programming in parser generators and the like.

Note: Use with care for relatively small or regular sets. It could end up being slower then just using multi-staged tables.

struct InversionList(SP = GcPolicy)
string
toSourceCode
(
string funcName = ""
)

Examples

import std.stdio;

// construct set directly from [a, b$RPAREN intervals
auto set = CodepointSet(10, 12, 45, 65, 100, 200);
writeln(set);
writeln(set.toSourceCode("func"));

The above outputs something along the lines of:

bool func(dchar ch)  @safe pure nothrow @nogc
{
    if (ch < 45)
    {
        if (ch == 10 || ch == 11) return true;
        return false;
    }
    else if (ch < 65) return true;
    else
    {
        if (ch < 100) return false;
        if (ch < 200) return true;
        return false;
    }
}

Meta