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:
1 // There are a near infinite number of valid number literals, so numbers are 2 // dynamic tokens. 3 enum string[] dynamicTokens = ["numberLiteral", "whitespace"]; 4 5 // The operators are always the same, and cannot start a numberLiteral, so 6 // they are staticTokens 7 enum string[] staticTokens = ["-", "+", "*", "/"]; 8 9 // In this simple example there are no keywords or other tokens that could 10 // look like dynamic tokens, so this is blank. 11 enum string[] possibleDefaultTokens = []; 12 13 // If any whitespace character or digit is encountered, pass lexing over to 14 // our custom handler functions. These will be demonstrated in an example 15 // later on. 16 enum string[] tokenHandlers = [ 17 "0", "lexNumber", 18 "1", "lexNumber", 19 "2", "lexNumber", 20 "3", "lexNumber", 21 "4", "lexNumber", 22 "5", "lexNumber", 23 "6", "lexNumber", 24 "7", "lexNumber", 25 "8", "lexNumber", 26 "9", "lexNumber", 27 " ", "lexWhitespace", 28 "\n", "lexWhitespace", 29 "\t", "lexWhitespace", 30 "\r", "lexWhitespace" 31 ];
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: