Looks up the string representation of the given token type.
The implementation of the _lexer is contained within this mixin template.
Range structure that wraps the _lexer's input.
The token that is returned by the lexer.
Generates the token type identifier for the given symbol.
Template for determining the type used for a token type.
Here are some example constants for a simple calculator lexer:
// There are a near infinite number of valid number literals, so numbers are // dynamic tokens. enum string[] dynamicTokens = ["numberLiteral", "whitespace"]; // The operators are always the same, and cannot start a numberLiteral, so // they are staticTokens enum string[] staticTokens = ["-", "+", "*", "/"]; // In this simple example there are no keywords or other tokens that could // look like dynamic tokens, so this is blank. enum string[] possibleDefaultTokens = []; // If any whitespace character or digit is encountered, pass lexing over to // our custom handler functions. These will be demonstrated in an example // later on. enum string[] tokenHandlers = [ "0", "lexNumber", "1", "lexNumber", "2", "lexNumber", "3", "lexNumber", "4", "lexNumber", "5", "lexNumber", "6", "lexNumber", "7", "lexNumber", "8", "lexNumber", "9", "lexNumber", " ", "lexWhitespace", "\n", "lexWhitespace", "\t", "lexWhitespace", "\r", "lexWhitespace" ];
Brian Schott 2013
Summary
This module contains a range-based compile-time lexer generator.
Overview
The lexer generator consists of a template mixin, Lexer, along with several helper templates for generating such things as token identifiers.
To write a lexer using this API: