Class Lexer
Lexical analyzer class
class Lexer
: std .range .interfaces .InputRange!string
;
Example
import std .array: array;
import std .range: iota;
string[] delims =
[
"(", ")", ";", " ", "{", "}", ".", "\n", "\r", "=", "++", "<"
];
auto input = "for (int i=0; i<arr.length; ++i)\r\n{doThing();}\n";
auto lexer = new Lexer(input, delims);
string[] arr;
while(true)
{
auto lexeme = lexer .getLexeme();
if(lexeme .length == 0)
break;
arr ~= lexeme;
}
auto reference =
[
"for", " ", "(", "int", " ", "i", "=", "0", ";", " ", "i", "<",
"arr", ".", "length", ";", " ", "++", "i", ")", "\n", "{", "doThing",
"(", ")", ";", "}", "\n"
];
assert(arr == reference);
lexer = new Lexer(input, delims);
arr = array(lexer);
assert(arr == reference);
input = "";
lexer = new Lexer(input, delims);
assert(lexer .getLexeme() .length == 0);