lex

Parses source, caches its symbols and compares the the cache content with the results.

  1. const(Token)[] lex(string source)
  2. const(Token)[] lex(string source, string filename)
    version(unittest)
    const(Token)[]
    lex
    (
    string source
    ,
    string filename
    )

Parameters

source string

The source code to test.

Examples

Parses source, caches its symbols and compares the the cache content with the results.

Params: source = The source code to test. results = An array of string array. Each slot represents the variable name followed by the type strings.

auto tokens = lex(q{int a = 9;});
foreach(i, t;
	cast(IdType[]) [tok!"int", tok!"identifier", tok!"=", tok!"intLiteral", tok!";"])
{
	assert(tokens[i] == t);
}
assert(tokens[1].text == "a", tokens[1].text);
assert(tokens[3].text == "9", tokens[3].text);

Meta