### Use tok template Source: https://libdparse.dlang.io/dparse/lexer/tok.html Example of using the tok template to define a token type. ```d import dparse.lexer; IdType t = tok!"floatLiteral"; ``` -------------------------------- ### Allman brace style example Source: https://libdparse.dlang.io/dparse/formatter/IndentStyle.html Demonstrates the Allman style where braces are placed on a new line. ```d if (something) { foo(); bar(); } else { bar(); baz(); } ``` -------------------------------- ### Testing Hex Character Sequences Source: https://libdparse.dlang.io/dparse/lexer/StringCache.html Example demonstrating how to validate hex character sequences using the lexer. ```d auto toks = (string s) => byToken(cast(ubyte[])s); // valid immutable hex = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','A','B','C','D','E','F']; auto source = ""; foreach (h1; hex) foreach (h2; hex) source ~= "'\\x" ~ h1 ~ h2 ~ "'"; assert (toks(source).filter!(t => t.type != tok!"characterLiteral").empty); // invalid assert (toks(`'\x'`).messages[0] == DLexer.Message(1,4,"Error: 2 hex digits expected.",true)); assert (toks(`'\x_'`).messages[0] == DLexer.Message(1,4,"Error: 2 hex digits expected.",true)); assert (toks(`'\xA'`).messages[0] == DLexer.Message(1,5,"Error: 2 hex digits expected.",true)); assert (toks(`'\xAY'`).messages[0] == DLexer.Message(1,5,"Error: 2 hex digits expected.",true)); assert (toks(`'\xXX'`).messages[0] == DLexer.Message(1,4,"Error: 2 hex digits expected.",true)); ``` -------------------------------- ### Get version specification Source: https://libdparse.dlang.io/dparse/ast/Declaration.versionSpecification.html Retrieves the version specification for a declaration. ```d const(VersionSpecification) versionSpecification() @property const; ``` -------------------------------- ### OTBS brace style example Source: https://libdparse.dlang.io/dparse/formatter/IndentStyle.html Demonstrates the One True Brace Style (OTBS) where the opening brace is on the same line. ```d if (something) { foo(); bar(); } else { bar(); baz(); } ``` -------------------------------- ### Usage of TokenId Template Source: https://libdparse.dlang.io/std/experimental/lexer/TokenId.html Example showing how to wrap TokenId in a custom template to resolve token identifiers for specific symbols. ```d template tok(string symbol) { alias tok = TokenId!(IdType, staticTokens, dynamicTokens, possibleDefaultTokens, symbol); } // num and plus are of type ubyte. IdType plus = tok!"+"; IdType num = tok!"numberLiteral"; ``` -------------------------------- ### Define Lexer Constants for a Calculator Source: https://libdparse.dlang.io/std/experimental/lexer.html Example configuration for a simple calculator lexer, defining dynamic tokens, static operators, and custom token handlers. ```d // 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" ]; ``` -------------------------------- ### Implement Calculator Lexer Source: https://libdparse.dlang.io/std/experimental/lexer/Lexer.html An example struct implementing a lexer using the Lexer mixin template. ```d 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; } } ``` -------------------------------- ### Usage Examples for isStringLiteral Source: https://libdparse.dlang.io/dparse/strings/isStringLiteral.html Demonstrates various valid and invalid string literal formats using assertion tests. ```d assert(isStringLiteral(`"hello"`)); assert(isStringLiteral(`"ñ"`)); assert(isStringLiteral(`"hello world!"`)); assert(isStringLiteral(`r"hello world!"c`)); assert(isStringLiteral(`r"hello world!"d`)); assert(isStringLiteral(`q{cool}`)); assert(isStringLiteral(`q{cool\}`)); assert(isStringLiteral(`"\\"`)); assert(!isStringLiteral(`"\\\"`)); assert(isStringLiteral(`"\\\\"`)); assert(isStringLiteral(`"a\\\\"`)); assert(!isStringLiteral(`"ñ\"`)); assert(isStringLiteral(`"ñ\\"`)); assert(isStringLiteral(`""`)); assert(isStringLiteral(`q""`)); assert(isStringLiteral(`x""`)); assert(!isStringLiteral(``)); assert(!isStringLiteral(`"`)); assert(!isStringLiteral(`w""`)); assert(!isStringLiteral(`hello"`)); assert(!isStringLiteral(`"hello`)); assert(!isStringLiteral(`"hello world`)); assert(!isStringLiteral(`hello world`)); assert(!isStringLiteral(`r"`)); assert(!isStringLiteral(`rr"ok"`)); assert(!isStringLiteral(`x"`)); assert(!isStringLiteral(`x" `)); assert(!isStringLiteral(`qqqq`)); ``` -------------------------------- ### Define StatementNoCaseNoDefault startLocation Source: https://libdparse.dlang.io/dparse/ast/StatementNoCaseNoDefault.startLocation.html The startLocation field is a ulong representing the starting offset of the statement. ```d class StatementNoCaseNoDefault {   // ...   ulong startLocation;   // ... } ``` -------------------------------- ### Get AliasAssign property Source: https://libdparse.dlang.io/dparse/ast/Declaration.aliasAssign.html Retrieves the AliasAssign node from a declaration. ```d const(AliasAssign) aliasAssign() @property const; ``` -------------------------------- ### Get MixinDeclaration Source: https://libdparse.dlang.io/dparse/ast/Declaration.mixinDeclaration.html Retrieves the MixinDeclaration node from the declaration. ```d const(MixinDeclaration) mixinDeclaration() @property const; ``` -------------------------------- ### bool startsWith(const(ubyte[]) needle) Source: https://libdparse.dlang.io/std/experimental/lexer/LexerRange.startsWith.html Checks if the LexerRange starts with the provided byte sequence. ```APIDOC ## bool startsWith(const(ubyte[]) needle) ### Description Checks if the current range starts with the given byte sequence. ### Signature `bool startsWith(const(ubyte[]) needle) pure nothrow @nogc @safe const;` ### Parameters - **needle** (const(ubyte[])) - The byte sequence to check for at the start of the range. ### Returns - **bool** - Returns true if the range starts with the given byte sequence, otherwise false. ``` -------------------------------- ### Get Postblit property Source: https://libdparse.dlang.io/dparse/ast/Declaration.postblit.html Retrieves the constant Postblit node from the declaration. ```d const(Postblit) postblit() @property const; ``` -------------------------------- ### Get Declaration DebugSpecification Source: https://libdparse.dlang.io/dparse/ast/Declaration.debugSpecification.html Retrieves the current DebugSpecification associated with the declaration. ```d const(DebugSpecification) debugSpecification() @property const; ``` -------------------------------- ### Usage of TokenIdType Source: https://libdparse.dlang.io/std/experimental/lexer/TokenIdType.html Example of aliasing IdType using the TokenIdType template. ```d // In our calculator example this means that IdType is an alias for ubyte. alias IdType = TokenIdType!(staticTokens, dynamicTokens, possibleDefaultTokens); ``` -------------------------------- ### LexerRange.this(const(ubyte)[] bytes, ulong index, ulong column, ulong line) Source: https://libdparse.dlang.io/std/experimental/lexer/LexerRange.this.html Initializes a new instance of LexerRange with the specified input bytes and optional starting coordinates. ```APIDOC ## Constructor: LexerRange.this ### Description Initializes a new LexerRange instance to process a byte array. This constructor sets the initial state of the lexer, including the input buffer and starting line/column tracking. ### Signature `ref this(const(ubyte)[] bytes, ulong index = 0LU, ulong column = 1LU, ulong line = 1LU) pure nothrow @nogc @safe;` ### Parameters - **bytes** (const(ubyte)[]) - The lexer input buffer. - **index** (ulong) - The initial offset from the beginning of bytes (default: 0). - **column** (ulong) - The initial column number (default: 1). - **line** (ulong) - The initial line number (default: 1). ``` -------------------------------- ### Get AliasDeclaration Source: https://libdparse.dlang.io/dparse/ast/Declaration.aliasDeclaration.html Retrieves the AliasDeclaration node from the declaration. ```d const(AliasDeclaration) aliasDeclaration() @property const; ``` -------------------------------- ### Get ImportDeclaration Source: https://libdparse.dlang.io/dparse/ast/Declaration.importDeclaration.html Retrieves the ImportDeclaration node as a const property. ```d const(ImportDeclaration) importDeclaration() @property const; ``` -------------------------------- ### Construct TokenStructure from Type Source: https://libdparse.dlang.io/std/experimental/lexer/TokenStructure.this.html Initializes a new TokenStructure instance using only the token type. ```d this(   IdType type ); ``` -------------------------------- ### Get AttributeDeclaration Source: https://libdparse.dlang.io/dparse/ast/Declaration.attributeDeclaration.html Retrieves the constant AttributeDeclaration node from the declaration. ```d const(AttributeDeclaration) attributeDeclaration() @property const; ``` -------------------------------- ### Get interface declaration Source: https://libdparse.dlang.io/dparse/ast/Declaration.interfaceDeclaration.html Retrieves the interface declaration as a constant property. ```d const(InterfaceDeclaration) interfaceDeclaration() @property const; ``` -------------------------------- ### Calculate optimal bucket count Source: https://libdparse.dlang.io/dparse/lexer/optimalBucketCount.html Determines the recommended initial bucket count for a StringCache based on input size. ```d ulong optimalBucketCount(   ulong size ); ``` -------------------------------- ### Get VariableDeclaration Source: https://libdparse.dlang.io/dparse/ast/Declaration.variableDeclaration.html Retrieves the variable declaration node as a constant property. ```d const(VariableDeclaration) variableDeclaration() @property const; ``` -------------------------------- ### Get TemplateDeclaration Source: https://libdparse.dlang.io/dparse/ast/Declaration.templateDeclaration.html Retrieves the template declaration associated with the current node. ```d const(TemplateDeclaration) templateDeclaration() @property const; ``` -------------------------------- ### Create token range with default configuration Source: https://libdparse.dlang.io/dparse/lexer/byToken.html Generates a token range using a default lexer configuration and a GC-managed string cache. ```d auto byToken(R)(   R range ) if (is(Unqual!(ElementEncodingType!R) : ubyte) && isDynamicArray!R); ``` -------------------------------- ### Get StaticAssertDeclaration Source: https://libdparse.dlang.io/dparse/ast/Declaration.staticAssertDeclaration.html Retrieves the static assertion declaration as a const property. ```d const(StaticAssertDeclaration) staticAssertDeclaration() @property const; ``` -------------------------------- ### Construct TokenStructure with Metadata Source: https://libdparse.dlang.io/std/experimental/lexer/TokenStructure.this.html Initializes a new TokenStructure instance with full positional information and associated text. ```d this(   IdType type,   string text,   size_t line,   size_t column,   size_t index ); ``` -------------------------------- ### Create token range with full configuration Source: https://libdparse.dlang.io/dparse/lexer/byToken.html Generates a token range using a specific lexer configuration and string cache. ```d auto byToken(R)(   R range,   const LexerConfig config,   StringCache* cache ) if (is(Unqual!(ElementEncodingType!R) : ubyte) && isDynamicArray!R); ``` -------------------------------- ### Get PragmaDeclaration Source: https://libdparse.dlang.io/dparse/ast/Declaration.pragmaDeclaration.html Retrieves the current PragmaDeclaration node as a const property. ```d const(PragmaDeclaration) pragmaDeclaration() @property const; ``` -------------------------------- ### Initialize StringCache with bucket count Source: https://libdparse.dlang.io/dparse/lexer/StringCache.this.html Creates a new StringCache instance with a specified number of buckets, which must be a power of two. ```d ref this(   ulong bucketCount ) pure nothrow @nogc @trusted; ``` -------------------------------- ### Declaration.enumDeclaration Source: https://libdparse.dlang.io/dparse/ast/Declaration.enumDeclaration.html Methods to get or set the EnumDeclaration node for a declaration. ```APIDOC ## Declaration.enumDeclaration ### Description Retrieves the EnumDeclaration node associated with the declaration. ### Signature `const(EnumDeclaration) enumDeclaration() @property const;` --- ## Declaration.enumDeclaration (Setter) ### Description Sets the EnumDeclaration node for the declaration. ### Signature `const(EnumDeclaration) enumDeclaration(EnumDeclaration node) @property;` ### Parameters - **node** (EnumDeclaration) - Required - The EnumDeclaration node to assign. ``` -------------------------------- ### Function Signature for unDecorateComment Source: https://libdparse.dlang.io/dparse/trivia/unDecorateComment.html The function signature requires an output range that accepts strings. ```d void unDecorateComment(T)( string comment, auto ref T outputRange ) if (isOutputRange!(T, string)); ``` -------------------------------- ### Formatter.this(Sink sink, bool useTabs, IndentStyle style, uint indentWidth) Source: https://libdparse.dlang.io/dparse/formatter/Formatter.this.html Initializes a new instance of the Formatter class with configuration for indentation style and output destination. ```APIDOC ## Formatter.this ### Description Initializes a new Formatter instance. This constructor sets up the output sink and defines the indentation rules for the formatted source code. ### Signature `this(Sink sink, bool useTabs = false, IndentStyle style = IndentStyle.allman, uint indentWidth = 4);` ### Parameters - **sink** (Sink) - Required - The output range where the formatted source code is placed. - **useTabs** (bool) - Optional - If true, tabs are used for indent levels instead of spaces. Defaults to false. - **style** (IndentStyle) - Optional - The brace style to be used. Defaults to IndentStyle.allman. - **indentWidth** (uint) - Optional - The number of spaces used for indentation if useTabs is false. Defaults to 4. ``` -------------------------------- ### Get ClassDeclaration node Source: https://libdparse.dlang.io/dparse/ast/Declaration.classDeclaration.html Retrieves the ClassDeclaration node as a const property. ```d const(ClassDeclaration) classDeclaration() @property const; ``` -------------------------------- ### DLexer(R range, const LexerConfig config, StringCache* cache, bool haveSSE42) Source: https://libdparse.dlang.io/dparse/lexer/DLexer.this.html Initializes a new instance of the DLexer with the provided source range, configuration, and string cache. ```APIDOC ## Constructor: DLexer ### Description Initializes a new DLexer instance to process source code bytes. ### Signature `this(R)(R range, const LexerConfig config, StringCache* cache, bool haveSSE42 = sse42())` ### Parameters - **range** (R) - The bytes that compose the source code that will be lexed. - **config** (const LexerConfig) - The lexer configuration to use. - **cache** (StringCache*) - The string interning cache for de-duplicating identifiers and other token text. - **haveSSE42** (bool) - Parse streaming SIMD Extensions 4.2 in inline assembly. ``` -------------------------------- ### Get static destructor Source: https://libdparse.dlang.io/dparse/ast/Declaration.staticDestructor.html Retrieves the static destructor node as a constant property. ```d const(StaticDestructor) staticDestructor() @property const; ``` -------------------------------- ### Verify optimalBucketCount behavior Source: https://libdparse.dlang.io/dparse/lexer/optimalBucketCount.html Validates the function output for various input sizes, including platform-specific checks. ```d assert(optimalBucketCount(1) == 2); assert(optimalBucketCount(9000 * 32) == 16384); static if (size_t.sizeof == ulong.sizeof) assert(optimalBucketCount(100_000_000_000UL) == 1 << 30); ``` -------------------------------- ### Get Declaration invariant Source: https://libdparse.dlang.io/dparse/ast/Declaration.invariant_.html Retrieves the invariant node from a declaration as a const property. ```d const(Invariant) invariant_() @property const; ``` -------------------------------- ### Unittest for unDecorateComment Source: https://libdparse.dlang.io/dparse/trivia/unDecorateComment.html Demonstrates usage of unDecorateComment with various comment styles and input strings. ```d import std.array:array, appender; import std.stdio:stderr; stderr.writeln("Running unittest for unDecorateComment..."); string[] inputs = [ "/***************\n*******************/", "/***************\n *\n ******************/", "/**\n*/", "/** */", "/***/", "/******/", "/** abcde1 */", "/// abcde2\n/// abcde2", "/**\n * stuff1\n */", "/**\n *\n * stuff2\n */", "/**\n *\n * stuff3\n *\n */", "/**\n *\n * stuff4\n *\n*/", "/**\n * abcde3\n * abcde3 \n */", "/**\n * abcde4\n *\n * abcde4\n */", "/**abcde5\n*abcde5\n*/", "/** abcde6\n * abcde6\n*/", "/**\n1\n\n\n\n*/", "/**\r\n1\r\n\r\n\r\n\r\n*/", "/**\na1\n\na2\n\n*/", "/**b1\n*b2\n*b3*/", "/**c1\n *c2\n *c3*/", "/**d1\n *d2\n *d3\n*/", "///a\fbc\n///def" ]; string[] outputs = [ "", "", "", "", "", "", "abcde1", "abcde2\nabcde2", "stuff1", "stuff2", "stuff3", "stuff4", "abcde3\n abcde3", "abcde4\n\nabcde4", "abcde5\nabcde5", "abcde6\nabcde6", "1", "1", "a1\n\na2", "b1\nb2\nb3", "c1\nc2\nc3", "d1\nd2\nd3", "a\fbc\ndef" ]; // tests where * and + are not interchangeable string[2][] np = [ ["/**\n * d1\n d2\n */", "* d1\nd2"], ["/**\n + d1\n d2\n */", "+ d1\nd2"], ["/**d1\n\n\n*d2\n*/", "d1\n\n*d2"], ]; assert(inputs.length == outputs.length); foreach (pair; zip(inputs, outputs)) { foreach (b; [true, false]) { auto app = appender!string(); unDecorateComment(b ? pair[0] : pair[0].replace("*", "+"), app); assert(pair[1] == app.data, "[[" ~ pair[0] ~ "]] => [[" ~ app.data ~ "]]"); } } foreach (pair; np) { auto app = appender!string(); unDecorateComment(pair[0], app); assert(pair[1] == app.data, "[[" ~ pair[0] ~ "]] => [[" ~ app.data ~ "]]"); } stderr.writeln("Unittest for unDecorateComment passed."); ``` -------------------------------- ### Initialize Class Definition Source: https://libdparse.dlang.io/dparse/ast/Initialize.statementNoCaseNoDefault.html Defines the Initialize class containing a StatementNoCaseNoDefault member. ```d class Initialize {   // ...   StatementNoCaseNoDefault statementNoCaseNoDefault;   // ... } ``` -------------------------------- ### Create token range with custom string cache Source: https://libdparse.dlang.io/dparse/lexer/byToken.html Generates a token range using a provided string cache. ```d auto byToken(R)(   R range,   StringCache* cache ) if (is(Unqual!(ElementEncodingType!R) : ubyte) && isDynamicArray!R); ``` -------------------------------- ### Define Parser.Bookmark Alias Source: https://libdparse.dlang.io/dparse/parser/Parser.Bookmark.html Shows the alias definition for Bookmark as a ulong type inside the Parser class. ```d class Parser {   // ...   alias Bookmark = ulong;   // ... } ``` -------------------------------- ### void format(Sink, T)(Sink sink, T node, bool useTabs, IndentStyle style, uint indentWith) Source: https://libdparse.dlang.io/dparse/formatter/format.html Formats a D language AST node and writes it to the provided sink. ```APIDOC ## void format(Sink, T)(Sink sink, T node, bool useTabs, IndentStyle style, uint indentWith) ### Description Formats a given AST node and writes the output to the provided sink. Allows customization of indentation style and width. ### Parameters - **sink** (Sink) - Required - The output sink to write the formatted code to. - **node** (T) - Required - The AST node to format. - **useTabs** (bool) - Optional - Whether to use tabs for indentation. Defaults to false. - **style** (IndentStyle) - Optional - The indentation style to use (e.g., IndentStyle.allman). Defaults to IndentStyle.allman. - **indentWith** (uint) - Optional - The number of spaces or tabs to use for indentation. Defaults to 4. ``` -------------------------------- ### Constructor class structure Source: https://libdparse.dlang.io/dparse/ast/Constructor.comment.html Defines the Constructor class with a comment string field. ```d class Constructor {   // ...   string comment;   // ... } ``` -------------------------------- ### Get Interpolated String Postfix Type Source: https://libdparse.dlang.io/dparse/ast/InterpolatedString.postfixType.html Returns the postfix character for interpolated strings, identifying the encoding type. ```d inout char postfixType() pure nothrow @nogc scope @safe; ``` -------------------------------- ### Define StringBehavior.compiler Source: https://libdparse.dlang.io/dparse/lexer/StringBehavior.compiler.html Initializes the compiler behavior with a specific ubyte cast. ```d struct StringBehavior {   // ...   immutable(StringBehavior) compiler = StringBehavior(cast(ubyte)0u);   // ... } ``` -------------------------------- ### GccAsmInstruction class structure Source: https://libdparse.dlang.io/dparse/ast/GccAsmInstruction.gotos.html Definition of the GccAsmInstruction class showing the inclusion of the gotos field. ```d class GccAsmInstruction {   // ...   DeclaratorIdentifierList gotos;   // ... } ``` -------------------------------- ### LexerRange.slice method signature Source: https://libdparse.dlang.io/std/experimental/lexer/LexerRange.slice.html Defines the method signature for slicing the input byte array starting from a specific mark. ```d const(ubyte)[] slice(   size_t m ) const; ``` -------------------------------- ### BaseClassList Methods Source: https://libdparse.dlang.io/dparse/ast/BaseClassList.html Method definitions for the BaseClassList node. ```d accept ``` -------------------------------- ### Define a basic Token structure Source: https://libdparse.dlang.io/std/experimental/lexer/TokenStructure.html Creates a token alias without additional fields using the TokenStructure template. ```d // No extra struct fields are desired in this example, so leave it blank. alias Token = TokenStructure!(IdType, ""); Token minusToken = Token(tok!"-"); ``` -------------------------------- ### Parser.attachCommentFromSemicolon(T node, size_t startIndex) Source: https://libdparse.dlang.io/dparse/parser/Parser.attachCommentFromSemicolon.html Attaches a comment to the specified node starting at the provided semicolon index. ```APIDOC ## Parser.attachCommentFromSemicolon ### Description Attaches a comment to a given node starting from the specified semicolon index. ### Signature `T attachCommentFromSemicolon(T)(T node, size_t startIndex)` ### Parameters - **node** (T) - The node to which the comment will be attached. - **startIndex** (size_t) - The index of the semicolon from which to begin attaching the comment. ``` -------------------------------- ### AliasInitializer Parsing Method Source: https://libdparse.dlang.io/dparse/parser/Parser.parseAliasInitializer.html Method signature for parsing an alias initializer. ```d AliasInitializer parseAliasInitializer(); ``` -------------------------------- ### Define TokenStructure line member Source: https://libdparse.dlang.io/std/experimental/lexer/TokenStructure.line.html The line member is a size_t field within the TokenStructure struct indicating the starting line number. ```d struct TokenStructure {   // ...   size_t line;   // ... } ``` -------------------------------- ### ExpressionStatement Methods Source: https://libdparse.dlang.io/dparse/ast/ExpressionStatement.html Lists the methods available in the ExpressionStatement class. ```d accept (visitor) ``` -------------------------------- ### InStatement class definition Source: https://libdparse.dlang.io/dparse/ast/InStatement.inTokenLocation.html Shows the structure of the InStatement class and the location of the inTokenLocation field. ```d class InStatement {   // ...   ulong inTokenLocation;   // ... } ``` -------------------------------- ### rangeMatch(bool invert, chars...)(const ubyte* bytes) Source: https://libdparse.dlang.io/dparse/lexer/rangeMatch.html Calculates the number of bytes starting at a given pointer that match or do not match specified byte ranges. ```APIDOC ## rangeMatch ### Description Calculates the number of bytes starting at the provided memory location that match (or do not match if invert is true) the specified byte ranges. ### Signature `ulong rangeMatch(bool invert, chars...)(const ubyte* bytes) pure nothrow @nogc @trusted;` ### Parameters - **invert** (bool) - If true, the function counts bytes that do not match the provided ranges. - **chars** (variadic) - The byte ranges to match against. - **bytes** (const ubyte*) - The starting memory location to begin matching. ### Returns - **ulong** - The number of bytes that satisfy the matching criteria. ``` -------------------------------- ### Parser.startsWith Source: https://libdparse.dlang.io/dparse/parser/Parser.startsWith.html Checks if the current token stream matches the specified sequence of token types. ```APIDOC ## Method: Parser.startsWith ### Description Checks if there are at least `types.length` tokens starting at the current token, and verifies if the tokens have types corresponding to the provided elements. ### Signature `final bool startsWith(scope ubyte[] types...) pure nothrow @nogc @safe const;` ### Parameters - **types** (ubyte[]) - Required - A variadic list of token types to match against the current token stream. ### Returns - **bool** - Returns `true` if the sequence of tokens matches the provided types, otherwise `false`. ``` -------------------------------- ### ASTVisitor.dynamicDispatch Method Signatures Source: https://libdparse.dlang.io/dparse/ast/ASTVisitor.dynamicDispatch.html Method signatures for dynamicDispatch handling different node types. ```d void dynamicDispatch(   const(ExpressionNode) n ); void dynamicDispatch(   const(InterpolatedStringPart) n ); ``` -------------------------------- ### WhileStatement class structure Source: https://libdparse.dlang.io/dparse/ast/WhileStatement.startIndex.html Shows the definition of the WhileStatement class and the location of the startIndex property. ```d class WhileStatement {   // ...   ulong startIndex;   // ... } ``` -------------------------------- ### void accept(ASTVisitor visitor) Source: https://libdparse.dlang.io/dparse/ast/SynchronizedStatement.accept.html Accepts an ASTVisitor to perform operations on the SynchronizedStatement node. ```APIDOC ## void accept(ASTVisitor visitor) ### Description Accepts an ASTVisitor instance to visit the current SynchronizedStatement node. This is part of the visitor pattern implementation for the AST. ### Parameters - **visitor** (ASTVisitor) - Required - The visitor instance to be accepted by the node. ``` -------------------------------- ### Define MessageDelegate alias Source: https://libdparse.dlang.io/dparse/parser/MessageDelegate.html The delegate signature accepts file name, line, column, message string, and a boolean flag for error status. ```d alias MessageDelegate = void delegate(string, ulong, ulong, string, bool); ``` -------------------------------- ### Convert IdType to string Source: https://libdparse.dlang.io/dparse/lexer/str.html Demonstrates converting an IdType token to its string representation. ```d IdType c = tok!"case"; assert (str(c) == "case"); ``` -------------------------------- ### Accessing ModuleDeclaration.startLocation Source: https://libdparse.dlang.io/dparse/ast/ModuleDeclaration.startLocation.html Defines the startLocation field within the ModuleDeclaration class structure. ```d class ModuleDeclaration {   // ...   ulong startLocation;   // ... } ``` -------------------------------- ### Accessing EnumBody.startLocation Source: https://libdparse.dlang.io/dparse/ast/EnumBody.startLocation.html Shows the location of the startLocation field within the EnumBody class structure. ```d class EnumBody {   // ...   ulong startLocation;   // ... } ``` -------------------------------- ### InStatement class structure Source: https://libdparse.dlang.io/dparse/ast/InStatement.blockStatement.html Shows the definition of the InStatement class and the inclusion of the blockStatement member. ```d class InStatement {   // ...   BlockStatement blockStatement;   // ... } ``` -------------------------------- ### Accessing Foreach.startIndex Source: https://libdparse.dlang.io/dparse/ast/Foreach.startIndex.html The startIndex member is defined as a size_t within the Foreach class structure. ```d class Foreach {   // ...   size_t startIndex;   // ... } ``` -------------------------------- ### StringCache.intern method signatures Source: https://libdparse.dlang.io/dparse/lexer/StringCache.intern.html Overloaded signatures for the intern method, supporting both ubyte arrays and standard strings. ```d string intern(   const(ubyte)[] str ) pure nothrow @nogc @safe; string intern(   string str ) pure nothrow @nogc @trusted; ``` -------------------------------- ### Setting the unittest property Source: https://libdparse.dlang.io/dparse/ast/Declaration.unittest_.html Assigns a unittest node to the declaration. ```d const(Unittest) unittest_(   Unittest node ) @property; ``` -------------------------------- ### Format Parameters Source: https://libdparse.dlang.io/dparse/formatter/Formatter.format.html Formats a Parameters object. ```d void format(   const Parameters parameters ); ``` -------------------------------- ### Lexer.getBeginningChars Source: https://libdparse.dlang.io/std/experimental/lexer/Lexer.getBeginningChars.html Retrieves the beginning characters from a provided array of immutable strings representing tokens. ```APIDOC ## Lexer.getBeginningChars ### Signature `static char[] getBeginningChars(immutable string[] allTokens)` ### Description This static method processes an array of tokens and returns the characters at the beginning of those tokens. ### Parameters - **allTokens** (immutable string[]) - Required - An array of strings representing the tokens to be processed. ``` -------------------------------- ### StringCache Definition Source: https://libdparse.dlang.io/dparse/lexer/StringCache.html The basic structure definition for StringCache. ```d struct StringCache; ``` -------------------------------- ### Accessing TemplateDeclaration.startLocation Source: https://libdparse.dlang.io/dparse/ast/TemplateDeclaration.startLocation.html The startLocation field is a ulong representing the byte offset of the opening brace. ```d class TemplateDeclaration {   // ...   ulong startLocation;   // ... } ``` -------------------------------- ### Formatter.format(const AliasInitializer) Source: https://libdparse.dlang.io/dparse/formatter/Formatter.format.html Formats an alias initializer node. ```APIDOC ## void format(const AliasInitializer aliasInitializer) ### Description Formats an AliasInitializer node. ### Parameters - **aliasInitializer** (const AliasInitializer) - Required - The node to format. ``` -------------------------------- ### Formatter.format(const StructInitializer) Source: https://libdparse.dlang.io/dparse/formatter/Formatter.format.html Formats a struct initializer. ```APIDOC ## void format(const StructInitializer structInitializer) ### Description Formats a given `StructInitializer` object. ### Parameters - **structInitializer** (const StructInitializer) - The struct initializer to format. ``` -------------------------------- ### Accessing TypeSuffix.parameters Source: https://libdparse.dlang.io/dparse/ast/TypeSuffix.parameters.html Shows the structure of the TypeSuffix class containing the parameters field. ```d class TypeSuffix {   // ...   Parameters parameters;   // ... } ``` -------------------------------- ### Compare TokenStructure instances Source: https://libdparse.dlang.io/std/experimental/lexer/TokenStructure.opEquals.html Compares two TokenStructure objects for equality. ```d bool opEquals(   const ref typeof(this) other ) const; ``` -------------------------------- ### Normalize newlines in strings Source: https://libdparse.dlang.io/dparse/strings/unescapeString.html Demonstrates the normalization of various newline character sequences to standard LF. ```d string testNoChange = "hello\nworld!"; assert(normalizeNewLines(testNoChange).ptr is testNoChange.ptr); assert(normalizeNewLines("hello\rworld") == "hello\nworld"); assert(normalizeNewLines("hello\r\nworld") == "hello\nworld"); assert(normalizeNewLines("hello\r\n\nworld") == "hello\n\nworld"); assert(normalizeNewLines("hello\u2028\nworld") == "hello\n\nworld"); assert(normalizeNewLines("hello\u2029\nworld") == "hello\n\nworld"); assert(normalizeNewLines("hello\r") == "hello\n"); ``` -------------------------------- ### Define StringLiterals AliasSeq Source: https://libdparse.dlang.io/dparse/lexer/StringLiterals.html Groups dstringLiteral, stringLiteral, and wstringLiteral tokens into a single alias. ```d alias StringLiterals = AliasSeq!(tok!"dstringLiteral",tok!"stringLiteral",tok!"wstringLiteral"); ``` -------------------------------- ### Accessing ArgumentList.startLocation Source: https://libdparse.dlang.io/dparse/ast/ArgumentList.startLocation.html The startLocation field is a member of the ArgumentList class used to track the beginning of the argument list. ```d class ArgumentList {   // ...   ulong startLocation;   // ... } ``` -------------------------------- ### ReturnStatement.startLocation definition Source: https://libdparse.dlang.io/dparse/ast/ReturnStatement.startLocation.html The startLocation field is a member of the ReturnStatement class. ```d class ReturnStatement {   // ...   ulong startLocation;   // ... } ``` -------------------------------- ### format(sink, node, useTabs, style, indentWith) Source: https://libdparse.dlang.io/dparse/formatter.html Formats a given node and writes the output to the provided sink. ```APIDOC ## format(sink, node, useTabs, style, indentWith) ### Description Formats a syntax node and writes the result to the specified output sink. ### Parameters - **sink** (Output) - The destination for the formatted output. - **node** (Node) - The syntax node to format. - **useTabs** (bool) - Whether to use tabs for indentation. - **style** (IndentStyle) - The indentation style to apply. - **indentWith** (int) - The number of spaces or tabs to use for indentation. ``` -------------------------------- ### Constructor parameters field definition Source: https://libdparse.dlang.io/dparse/ast/Constructor.parameters.html Shows the structure of the Constructor class containing the parameters field. ```d class Constructor {   // ...   Parameters parameters;   // ... } ``` -------------------------------- ### Accessing parameters in AliasInitializer Source: https://libdparse.dlang.io/dparse/ast/AliasInitializer.parameters.html Shows the structure of the AliasInitializer class containing the parameters field. ```d class AliasInitializer {   // ...   Parameters parameters;   // ... } ``` -------------------------------- ### Formatter.format(const ArrayInitializer) Source: https://libdparse.dlang.io/dparse/formatter/Formatter.format.html Formats an array initializer node. ```APIDOC ## void format(const ArrayInitializer arrayInitializer) ### Description Formats an ArrayInitializer node. ### Parameters - **arrayInitializer** (const ArrayInitializer) - Required - The node to format. ``` -------------------------------- ### Parser.parseVersionSpecification Method Signature Source: https://libdparse.dlang.io/dparse/parser/Parser.parseVersionSpecification.html The method signature for parsing a version specification. ```d VersionSpecification parseVersionSpecification(); ``` -------------------------------- ### byToken(R range, const LexerConfig config, StringCache* cache) Source: https://libdparse.dlang.io/dparse/lexer/byToken.html Creates a token range from the given source code using a custom lexer configuration and string cache. ```APIDOC ## Function: byToken(R range, const LexerConfig config, StringCache* cache) ### Description Creates a token range from the given source code using the provided lexer configuration and string cache. ### Signature `auto byToken(R)(R range, const LexerConfig config, StringCache* cache) if (is(Unqual!(ElementEncodingType!R) : ubyte) && isDynamicArray!R);` ``` -------------------------------- ### DeclarationOrStatement class structure Source: https://libdparse.dlang.io/dparse/ast/DeclarationOrStatement.startLocation.html Shows the inclusion of the startLocation field within the DeclarationOrStatement class definition. ```d class DeclarationOrStatement {   // ...   ulong startLocation;   // ... } ``` -------------------------------- ### AsmBrExp class definition Source: https://libdparse.dlang.io/dparse/ast/AsmBrExp.asmExp.html Shows the structure of the AsmBrExp class including the asmExp field. ```d class AsmBrExp {   // ...   ExpressionNode asmExp;   // ... } ``` -------------------------------- ### ulong optimalBucketCount(ulong size) Source: https://libdparse.dlang.io/dparse/lexer/optimalBucketCount.html Calculates the optimal initial bucket count for a StringCache based on the provided source file size. ```APIDOC ## Function: optimalBucketCount ### Description Helper function used to avoid excessive allocations while lexing by determining the optimal initial bucket count for a `StringCache`. ### Signature `ulong optimalBucketCount(ulong size)` ### Parameters - **size** (ulong) - The length in bytes of the source file. ### Returns - **ulong** - The optimal initial bucket count. ### Example ```d assert(optimalBucketCount(1) == 2); assert(optimalBucketCount(9000 * 32) == 16384); static if (size_t.sizeof == ulong.sizeof) assert(optimalBucketCount(100_000_000_000UL) == 1 << 30); ``` ``` -------------------------------- ### Signature of getTokensForParser Source: https://libdparse.dlang.io/dparse/lexer/getTokensForParser.html The function signature requires a source code range, a LexerConfig, and a pointer to a StringCache. ```d Token[] getTokensForParser(R)(   R sourceCode,   LexerConfig config,   StringCache* cache ) if (is(Unqual!(ElementEncodingType!R) : ubyte) && isDynamicArray!R); ``` -------------------------------- ### Formatter.format(const ArrayMemberInitialization) Source: https://libdparse.dlang.io/dparse/formatter/Formatter.format.html Formats an array member initialization node. ```APIDOC ## void format(const ArrayMemberInitialization arrayMemberInitialization) ### Description Formats an ArrayMemberInitialization node. ### Parameters - **arrayMemberInitialization** (const ArrayMemberInitialization) - Required - The node to format. ``` -------------------------------- ### Accessing BlockStatement.startLocation Source: https://libdparse.dlang.io/dparse/ast/BlockStatement.startLocation.html Shows the location of the startLocation field within the BlockStatement class definition. ```d class BlockStatement {   // ...   ulong startLocation;   // ... } ``` -------------------------------- ### StringCache(ulong bucketCount) Source: https://libdparse.dlang.io/dparse/lexer/StringCache.this.html Initializes a new StringCache instance with a specified number of buckets. ```APIDOC ## StringCache(ulong bucketCount) ### Description Initializes a new instance of the StringCache with a defined number of buckets. The bucket count must be a power of two. ### Parameters - **bucketCount** (ulong) - Required - The initial number of buckets. Must be a power of two. ``` -------------------------------- ### byToken(R range, StringCache* cache) Source: https://libdparse.dlang.io/dparse/lexer/byToken.html Creates a token range from the given source code using a provided string cache. ```APIDOC ## Function: byToken(R range, StringCache* cache) ### Description Creates a token range from the given source code using the specified string cache. ### Signature `auto byToken(R)(R range, StringCache* cache) if (is(Unqual!(ElementEncodingType!R) : ubyte) && isDynamicArray!R);` ``` -------------------------------- ### Lexer.getFront(const ubyte[] arr) Source: https://libdparse.dlang.io/std/experimental/lexer/Lexer.getFront.html Retrieves information from the front of a byte array. This method is pure, nothrow, and @trusted. ```APIDOC ## static ulong getFront(const ubyte[] arr) ### Description Returns a value representing the front of the provided byte array. This is a static utility method used by the lexer. ### Signature `static ulong getFront(const ubyte[] arr) pure nothrow @trusted;` ### Parameters - **arr** (const ubyte[]) - Required - The byte array to process. ### Returns - **ulong** - The result of the operation on the front of the array. ``` -------------------------------- ### Define ImportBind.right member Source: https://libdparse.dlang.io/dparse/ast/ImportBind.right.html The right member uses TokenStructure with TokenTriviaFields to handle trivia tokens within the import binding. ```d class ImportBind {   // ...   TokenStructure!(ubyte,"import dparse.lexer:TokenTriviaFields,TriviaToken; mixin TokenTriviaFields;") right;   // ... } ``` -------------------------------- ### Accessing StructBody.startLocation Source: https://libdparse.dlang.io/dparse/ast/StructBody.startLocation.html Shows the location of the startLocation field within the StructBody class structure. ```d class StructBody {   // ...   ulong startLocation;   // ... } ``` -------------------------------- ### void popFrontN(size_t n) Source: https://libdparse.dlang.io/std/experimental/lexer/LexerRange.popFrontN.html Advances the lexer range by n elements. This implementation is optimized for performance and does not perform newline detection or handling. ```APIDOC ## void popFrontN(size_t n) ### Description Advances the lexer range by a specified number of elements. This method is implemented for efficiency and does not detect or handle newlines. ### Signature `void popFrontN(size_t n)` ### Parameters - **n** (size_t) - The number of elements to advance the range by. ``` -------------------------------- ### Set Postblit property Source: https://libdparse.dlang.io/dparse/ast/Declaration.postblit.html Assigns a Postblit node to the declaration. ```d const(Postblit) postblit(   Postblit node ) @property; ``` -------------------------------- ### ExpressionStatement Fields Source: https://libdparse.dlang.io/dparse/ast/ExpressionStatement.html Lists the fields available in the ExpressionStatement class. ```d expression ``` ```d tokens ``` -------------------------------- ### ASTVisitor visit method overloads Source: https://libdparse.dlang.io/dparse/ast/ASTVisitor.visit.html A collection of visit method signatures for various AST node types. Each method accepts a const reference to a specific AST node type. ```d void visit(   const(AddExpression) addExpression ); void visit(   const(AliasDeclaration) aliasDeclaration ); void visit(   const(AliasAssign) aliasAssign ); void visit(   const(AliasInitializer) aliasInitializer ); void visit(   const(AliasThisDeclaration) aliasThisDeclaration ); void visit(   const(AlignAttribute) alignAttribute ); void visit(   const(AndAndExpression) andAndExpression ); void visit(   const(AndExpression) andExpression ); void visit(   const(AnonymousEnumDeclaration) anonymousEnumDeclaration ); void visit(   const(AnonymousEnumMember) anonymousEnumMember ); void visit(   const(ArgumentList) argumentList ); void visit(   const(Arguments) arguments ); void visit(   const(ArrayInitializer) arrayInitializer ); void visit(   const(ArrayLiteral) arrayLiteral ); void visit(   const(ArrayMemberInitialization) arrayMemberInitialization ); void visit(   const(AsmAddExp) asmAddExp ); void visit(   const(AsmAndExp) asmAndExp ); void visit(   const(AsmBrExp) asmBrExp ); void visit(   const(AsmEqualExp) asmEqualExp ); void visit(   const(AsmExp) asmExp ); void visit(   const(AsmInstruction) asmInstruction ); void visit(   const(AsmLogAndExp) asmLogAndExp ); void visit(   const(AsmLogOrExp) asmLogOrExp ); void visit(   const(AsmMulExp) asmMulExp ); void visit(   const(AsmOrExp) asmOrExp ); void visit(   const(AsmPrimaryExp) asmPrimaryExp ); void visit(   const(AsmRelExp) asmRelExp ); void visit(   const(AsmShiftExp) asmShiftExp ); void visit(   const(AsmStatement) asmStatement ); void visit(   const(AsmTypePrefix) asmTypePrefix ); void visit(   const(AsmUnaExp) asmUnaExp ); void visit(   const(AsmXorExp) asmXorExp ); void visit(   const(AssertArguments) assertArguments ); void visit(   const(AssertExpression) assertExpression ); void visit(   const(AssignExpression) assignExpression ); void visit(   const(AssocArrayLiteral) assocArrayLiteral ); void visit(   const(AtAttribute) atAttribute ); void visit(   const(Attribute) attribute ); void visit(   const(AttributeDeclaration) attributeDeclaration ); void visit(   const(AutoDeclaration) autoDeclaration ); void visit(   const(AutoDeclarationPart) autoDeclarationPart ); void visit(   const(BlockStatement) blockStatement ); void visit(   const(BreakStatement) breakStatement ); void visit(   const(BaseClass) baseClass ); void visit(   const(BaseClassList) baseClassList ); void visit(   const(BitfieldWidth) bitfieldWidth ); void visit(   const(CaseRangeStatement) caseRangeStatement ); void visit(   const(CaseStatement) caseStatement ); void visit(   const(CastExpression) castExpression ); void visit(   const(CastQualifier) castQualifier ); void visit(   const(Catch) catch_ ); void visit(   const(Catches) catches ); void visit(   const(ClassDeclaration) classDeclaration ); void visit(   const(CmpExpression) cmpExpression ); void visit(   const(CompileCondition) compileCondition ); void visit(   const(ConditionalDeclaration) conditionalDeclaration ); void visit(   const(ConditionalStatement) conditionalStatement ); void visit(   const(Constraint) constraint ); void visit(   const(Constructor) constructor ); void visit(   const(ContinueStatement) continueStatement ); void visit(   const(DebugCondition) debugCondition ); void visit(   const(DebugSpecification) debugSpecification ); void visit(   const(Declaration) declaration ); void visit(   const(DeclarationOrStatement) declarationsOrStatement ); void visit(   const(DeclarationsAndStatements) declarationsAndStatements ); void visit(   const(Declarator) declarator ); void visit(   const(DefaultStatement) defaultStatement ); void visit(   const(DeleteExpression) deleteExpression ); void visit(   const(DeleteStatement) deleteStatement ); void visit(   const(Deprecated) deprecated_ ); void visit(   const(Destructor) destructor ); ``` -------------------------------- ### Access staticForeachDeclaration property Source: https://libdparse.dlang.io/dparse/ast/Declaration.staticForeachDeclaration.html Retrieves the static foreach declaration node from the AST. ```d const(Foreach!(true)) staticForeachDeclaration(   Foreach!(true) node ) @property; ``` ```d const(Foreach!(true)) staticForeachDeclaration() @property const; ``` -------------------------------- ### Set version specification Source: https://libdparse.dlang.io/dparse/ast/Declaration.versionSpecification.html Sets the version specification for a declaration using the provided node. ```d const(VersionSpecification) versionSpecification(   VersionSpecification node ) @property; ``` -------------------------------- ### Formatter.format(const StructMemberInitializers) Source: https://libdparse.dlang.io/dparse/formatter/Formatter.format.html Formats a collection of struct member initializers. ```APIDOC ## void format(const StructMemberInitializers structMemberInitializers) ### Description Formats a given `StructMemberInitializers` object. ### Parameters - **structMemberInitializers** (const StructMemberInitializers) - The struct member initializers to format. ```