Advances the lexer to the next token and stores the new current token in the _front variable.
Implements the range primitive empty.
Implements the range primitive front.
The token that is currently at the front of the range.
The lexer input.
1 struct CalculatorLexer 2 { 3 mixin Lexer!(IdType, Token, defaultTokenFunction, isSeparating, 4 staticTokens, dynamicTokens, possibleDefaultTokens, tokenHandlers); 5 6 this (ubyte[] bytes) 7 { 8 this.range = LexerRange(bytes); 9 popFront(); 10 } 11 12 void popFront() pure 13 { 14 _popFront(); 15 } 16 17 Token lexNumber() pure nothrow @safe 18 { 19 // implementation goes here 20 } 21 22 Token lexWhitespace() pure nothrow @safe 23 { 24 // implementation goes here 25 } 26 27 Token defaultTokenFunction() pure nothrow @safe 28 { 29 // There is no default token in the example calculator language, so 30 // this is always an error. 31 range.popFront(); 32 return Token(tok!""); 33 } 34 35 bool isSeparating(size_t offset) pure nothrow @safe 36 { 37 // For this example language, always return true. 38 return true; 39 } 40 }
The implementation of the _lexer is contained within this mixin template.
To use it, this template should be mixed in to a struct that represents the _lexer for your language. This struct should implement the following methods: