public template Lexer(Token, alias defaultTokenFunction, alias tokenSeparatingFunction, alias staticTokens, alias dynamicTokens, alias possibleDefaultTokens, alias tokenHandlers)
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:

Parameters

TokenTokenStructure
defaultTokenFunctiondefaultTokenFunction
tokenSeparatingFunctiontokenSeparatingFunction
staticTokensstaticTokens
dynamicTokensdynamicTokens
possibleDefaultTokenspossibleDefaultTokens
tokenHandlerstokenHandlers

Examples

struct CalculatorLexer
{
   mixin Lexer!(IdType, Token, defaultTokenFunction, isSeparating,
       staticTokens, dynamicTokens, possibleDefaultTokens, tokenHandlers);

   this (ubyte[] bytes)
   {
       this.range = LexerRange(bytes);
       popFront();
   }

   void popFront() pure
   {
       _popFront();
   }

   Token lexNumber() pure nothrow @safe
   {
       // implementation goes here
   }

   Token lexWhitespace() pure nothrow @safe
   {
       // implementation goes here
   }

   Token defaultTokenFunction() pure nothrow @safe
   {
       // There is no default token in the example calculator language, so
       // this is always an error.
       range.popFront();
       return Token(tok!"");
   }

   bool isSeparating(size_t offset) pure nothrow @safe
   {
       // For this example language, always return true.
       return true;
   }
}

Variables

range
LexerRange
The lexer input.
_front
Token
The token that is currently at the front of the range.

Functions

frontImplements the range primitive _front.
_popFrontAdvances the lexer to the next token and stores the new current token in the _front variable.
emptyImplements the range primitive _empty.