dparse.lexer

Types 19

aliasIdType = TokenIdType!(operators, dynamicTokens, keywords)

Token ID type for the D lexer.

aliasstr = tokenStringRepresentation!(IdType, operators, dynamicTokens, keywords)

Function used for converting an IdType to a string.

Examples

IdType c = tok!"case";
assert (str(c) == "case");

The token type in the D lexer

Same as Token, but doesn't contain child TriviaTokens

enumWhitespaceBehavior : ubyte

Configure whitespace handling

include = 0b0000_0000
skip = 0b0000_0001

Configure string lexing behavior

Fields
StringBehavior compilerDo not include quote characters, process escape sequences
StringBehavior includeQuoteCharsOpening quotes, closing quotes, and string suffixes are included in the string token
StringBehavior notEscapedString escape sequences are not replaced
StringBehavior sourceNot modified at all. Useful for formatters or highlighters
ubyte behavior
enumCommentBehavior : bool
intern = true
noIntern = false

Lexer configuration struct

Fields
string fileName
StringBehavior stringBehavior
WhitespaceBehavior whitespaceBehavior
CommentBehavior commentBehavior
aliasBasicTypes = AliasSeq!(tok!"int", tok!"bool", tok!"byte", tok!"cdouble", tok!"cent", tok!"cfloat", tok!"char", tok!"creal", tok!"dchar", tok!"double", tok!"float", tok!"idouble", tok!"ifloat", tok!"ireal", tok!"long", tok!"real", tok!"short", tok!"ubyte", tok!"ucent", tok!"uint", tok!"ulong", tok!"ushort", tok!"void", tok!"wchar")

Basic type token types.

aliasNumberLiterals = AliasSeq!(tok!"doubleLiteral", tok!"floatLiteral", tok!"idoubleLiteral", tok!"ifloatLiteral", tok!"intLiteral", tok!"longLiteral", tok!"realLiteral", tok!"irealLiteral", tok!"uintLiteral", tok!"ulongLiteral")

Number literal token types.

aliasIntegerLiterals = AliasSeq!(tok!"intLiteral", tok!"longLiteral", tok!"uintLiteral", tok!"ulongLiteral")

Number literal token types.

aliasOperators = AliasSeq!(tok!",", tok!".", tok!"..", tok!"...", tok!"/", tok!"/=", tok!"!", tok!"!<", tok!"!<=", tok!"!<>", tok!"!<>=", tok!"!=", tok!"!>", tok!"!>=", tok!"$", tok!"%", tok!"%=", tok!"&", tok!"&&", tok!"&=", tok!"(", tok!")", tok!"*", tok!"*=", tok!"+", tok!"++", tok!"+=", tok!"-", tok!"--", tok!"-=", tok!":", tok!";", tok!"<", tok!"<<", tok!"<<=", tok!"<=", tok!"<>", tok!"<>=", tok!"=", tok!"==", tok!"=>", tok!">", tok!">=", tok!">>", tok!">>=", tok!">>>", tok!">>>=", tok!"?", tok!"@", tok!"[", tok!"]", tok!"^", tok!"^=", tok!"^^", tok!"^^=", tok!"{", tok!"|", tok!"|=", tok!"||", tok!"}", tok!"~", tok!"~=")

Operator token types.

aliasKeywords = AliasSeq!(tok!"abstract", tok!"alias", tok!"align", tok!"asm", tok!"assert", tok!"auto", tok!"break", tok!"case", tok!"cast", tok!"catch", tok!"class", tok!"const", tok!"continue", tok!"debug", tok!"default", tok!"delegate", tok!"delete", tok!"deprecated", tok!"do", tok!"else", tok!"enum", tok!"export", tok!"extern", tok!"false", tok!"final", tok!"finally", tok!"for", tok!"foreach", tok!"foreach_reverse", tok!"function", tok!"goto", tok!"if", tok!"immutable", tok!"import", tok!"in", tok!"inout", tok!"interface", tok!"invariant", tok!"is", tok!"lazy", tok!"macro", tok!"mixin", tok!"module", tok!"new", tok!"nothrow", tok!"null", tok!"out", tok!"override", tok!"package", tok!"pragma", tok!"private", tok!"protected", tok!"public", tok!"pure", tok!"ref", tok!"return", tok!"scope", tok!"shared", tok!"static", tok!"struct", tok!"super", tok!"switch", tok!"synchronized", tok!"template", tok!"this", tok!"throw", tok!"true", tok!"try", tok!"typedef", tok!"typeid", tok!"typeof", tok!"union", tok!"unittest", tok!"version", tok!"while", tok!"with", tok!"__DATE__", tok!"__EOF__", tok!"__FILE__", tok!"__FILE_FULL_PATH__", tok!"__FUNCTION__", tok!"__gshared", tok!"__LINE__", tok!"__MODULE__", tok!"__parameters", tok!"__PRETTY_FUNCTION__", tok!"__TIME__", tok!"__TIMESTAMP__", tok!"__traits", tok!"__vector", tok!"__VENDOR__", tok!"__VERSION__")

Keyword token types.

aliasStringLiterals = AliasSeq!(tok!"dstringLiteral", tok!"stringLiteral", tok!"wstringLiteral")

String literal token types

aliasProtections = AliasSeq!(tok!"export", tok!"package", tok!"private", tok!"public", tok!"protected")

Protection token types.

aliasSpecialTokens = AliasSeq!(tok!"__DATE__", tok!"__TIME__", tok!"__TIMESTAMP__", tok!"__VENDOR__", tok!"__VERSION__", tok!"__FILE__", tok!"__FILE_FULL_PATH__", tok!"__LINE__", tok!"__MODULE__", tok!"__FUNCTION__", tok!"__PRETTY_FUNCTION__")
aliasLiterals = AliasSeq!(StringLiterals, NumberLiterals, tok!"characterLiteral", SpecialTokens, tok!"true", tok!"false", tok!"null", tok!"$")
structDLexer

The D lexer struct.

Methods
void popFront()() pure nothrow @safe
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`.
Constructors
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...
Nested Templates
MessageLexer error/warning message.
IstringState

The 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.

See_also: http://en.wikipedia.org/wiki/String_interning

Fields
defaultBucketCountThe default bucket count for the string cache.
Methods
string intern(const(ubyte)[] str) pure nothrow @nogc @safeCaches a string.
string intern(string str) pure nothrow @nogc @trustedditto
Constructors
this(size_t bucketCount)Params: bucketCount = the initial number of buckets. Must be a power of two
Destructors
Nested Templates
Node
Block

Functions 14

fnbool isBasicType(IdType type) nothrow pure @safe @nogcReturns: true if the given ID is for a basic type.
fnbool isNumberLiteral(IdType type) nothrow pure @safe @nogcReturns: true if the given ID type is for a number literal.
fnbool isIntegerLiteral(IdType type) nothrow pure @safe @nogcReturns: true if the given ID type is for a integer literal.
fnbool isOperator(IdType type) nothrow pure @safe @nogcReturns: true if the given ID type is for an operator.
fnbool isKeyword(IdType type) pure nothrow @safe @nogcReturns: true if the given ID type is for a keyword.
fnbool isStringLiteral(IdType type) pure nothrow @safe @nogcReturns: true if the given ID type is for a string literal.
fnbool isProtection(IdType type) pure nothrow @safe @nogcReturns: true if the given ID type is for a protection attribute.
fnbool isSpecialToken(IdType type) pure nothrow @safe @nogc
fnbool isLiteral(IdType type) pure nothrow @safe @nogc
fnToken[] 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.
fnauto 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.
fnauto 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.
fnauto 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.
fnsize_t optimalBucketCount(size_t size)Helper function used to avoid too much allocations while lexing.

Templates 1

tmpltok(string token)

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";