IdType c = tok!"case";
assert (str(c) == "case");dparse.lexer
Types 19
Token ID type for the D lexer.
Function used for converting an IdType to a string.
Examples
The token type in the D lexer
Same as Token, but doesn't contain child TriviaTokens
Configure whitespace handling
Configure string lexing behavior
StringBehavior compilerDo not include quote characters, process escape sequencesStringBehavior includeQuoteCharsOpening quotes, closing quotes, and string suffixes are included in the string tokenStringBehavior notEscapedString escape sequences are not replacedStringBehavior sourceNot modified at all. Useful for formatters or highlightersubyte behaviorLexer configuration struct
string fileNameStringBehavior stringBehaviorWhitespaceBehavior whitespaceBehaviorCommentBehavior commentBehaviorBasic type token types.
Number literal token types.
Number literal token types.
Operator token types.
Keyword token types.
String literal token types
Protection token types.
The D lexer struct.
const(Message[]) messages() const @propertyReturns: An array of all of the warnings and errors generated so far during lexing. It may make sense to only check this when `empty` returns `true`.this()this(R range, const LexerConfig config, StringCache * cache,
bool haveSSE42 = sse42())Params: range = the bytes that compose the source code that will be lexed. config = the lexer configuration to use. cache = the string interning cache for de-duplicating identifiers and other token...MessageLexer error/warning message.IstringStateThe string cache is used for string interning.
It will only store a single copy of any string that it is asked to hold. Interned strings can be compared for equality by comparing their .ptr field.
Default and postbilt constructors are disabled. When a StringCache goes out of scope, the memory held by it is freed.
defaultBucketCountThe default bucket count for the string cache.this()this(size_t bucketCount)Params: bucketCount = the initial number of buckets. Must be a power of twoNodeBlockFunctions 14
bool isBasicType(IdType type) nothrow pure @safe @nogcReturns: true if the given ID is for a basic type.bool isNumberLiteral(IdType type) nothrow pure @safe @nogcReturns: true if the given ID type is for a number literal.bool isIntegerLiteral(IdType type) nothrow pure @safe @nogcReturns: true if the given ID type is for a integer literal.bool isOperator(IdType type) nothrow pure @safe @nogcReturns: true if the given ID type is for an operator.bool isKeyword(IdType type) pure nothrow @safe @nogcReturns: true if the given ID type is for a keyword.bool isStringLiteral(IdType type) pure nothrow @safe @nogcReturns: true if the given ID type is for a string literal.bool isProtection(IdType type) pure nothrow @safe @nogcReturns: true if the given ID type is for a protection attribute.Token[] getTokensForParser(R)(R sourceCode, LexerConfig config, StringCache * cache) if (is(Unqual!(ElementEncodingType!R) : ubyte) && isDynamicArray!R)Returns: an array of tokens lexed from the given source code to the output range. All whitespace, comment and specialTokenSequence tokens (trivia) are attached to the token nearest to them.auto byToken(R)(R range) if (is(Unqual!(ElementEncodingType!R) : ubyte) && isDynamicArray!R)Creates a token range from the given source code. Creates a default lexer configuration and a GC-managed string cache.auto byToken(R)(R range, StringCache * cache) if (is(Unqual!(ElementEncodingType!R) : ubyte) && isDynamicArray!R)Creates a token range from the given source code. Uses the given string cache.auto byToken(R)(R range, const LexerConfig config, StringCache * cache) if (is(Unqual!(ElementEncodingType!R) : ubyte) && isDynamicArray!R)Creates a token range from the given source code. Uses the provided lexer configuration and string cache.size_t optimalBucketCount(size_t size)Helper function used to avoid too much allocations while lexing.Templates 1
Template used to refer to D token types.
See the operators, keywords, and dynamicTokens enums for values that can be passed to this template. Example:
import dparse.lexer;
IdType t = tok!"floatLiteral";