ddn.data.xml.internal.tokens

Internal: shared token-processing state and helpers.

This module provides reusable logic extracted from XmlReader.advance() and parseSax(). It is designed to support both the existing pull reader and the planned incremental reader without duplicating namespace resolution, element stack management, or event construction code.

This module is not part of the public API and may change at any time.

Types 1

Shared mutable state for token-to-event processing.

Holds the element stack, namespace stack, and pending end-element state used by both the existing XmlReader and the planned incremental reader to track document structure across tokens.

The struct is intended to be used by value or by reference. Stack operations mutate the struct in place.

Fields
string[] elementStackElement name stack. Pushed on non-empty start tags, popped on end tags. The stack length equals the current nesting depth.
string[string][] nsStackNamespace scope stack. Each entry maps prefixes to namespace URIs declared in that scope. Scopes are pushed on start tags and popped on matching end tags (or immediately for empty elements).
string pendingEndNamePending end-element name for empty-element tags (`<a/>`).
XmlLocation pendingEndLocationLocation of the pending end-element event.
string pendingEndPrefixPrefix part of the pending end-element name.
string pendingEndLocalLocal part of the pending end-element name.
string pendingEndNamespaceUriNamespace URI of the pending end-element.
size_t pendingEndDepthDepth at which the pending end-element was opened.
Methods
bool hasPendingEnd() const @safe pure nothrowReturns `true` when a synthetic `END_ELEMENT` is pending.
void clearPendingEnd() @safe pure nothrowClears the pending end-element state.
size_t currentDepth() const @safe pure nothrowReturns the current element nesting depth.
void pushElement(string name) @safe nothrowPushes an element name onto the stack.
void popElement() @safe nothrowPops the top element from the stack.
void pushNamespaceScope(string[string] declared) @safe nothrowPushes a new namespace scope.
void popNamespaceScope() @safe nothrowPops the top namespace scope.
string lookupNamespaceUri(string prefix) const @safe nothrowLooks up a namespace URI for the given prefix.

Functions 12

fnvoid splitQName(string qname, out string prefix, out string local) @safe pure nothrowSplits a QName into its prefix and local parts.
fnstring[string] extractNamespaceDeclarations( const XmlTokenAttribute[] attributes, bool decodeEntities, bool normalizeValues, const ref XmlParserLimits limits) @safeExtracts namespace declarations from a set of token attributes.
fnstring resolveAttributeUri( string attrName, string attrPrefix, const string[string][] nsStack) @safe nothrowResolves the namespace URI for an attribute name.
fnXmlEvent buildStartTagEvent( ref TokenProcessingState state, const XmlToken tok, bool decodeEntities, bool normalizeValues, const ref XmlParserLimits limits) @safeProcesses a `START_TAG` token and returns the corresponding `XmlEvent`.
fnXmlEvent buildEndTagEvent( ref TokenProcessingState state, const XmlToken tok) @safe nothrowProcesses an `END_TAG` token and returns the corresponding `XmlEvent`.
fnXmlEvent buildPendingEndEvent(ref TokenProcessingState state) @safe pure nothrowReturns the pending `END_ELEMENT` event and clears the pending state.
fnXmlEvent buildTextEvent( ref TokenProcessingState state, const XmlToken tok, bool decodeEntities, const ref XmlParserLimits limits) @safeBuilds a `TEXT` event from a token.
fnXmlEvent buildCommentEvent( const ref TokenProcessingState state, const XmlToken tok) @safe pure nothrowBuilds a `COMMENT` event from a token.
fnXmlEvent buildCDataEvent( const ref TokenProcessingState state, const XmlToken tok) @safe pure nothrowBuilds a `CDATA` event from a token.
fnXmlEvent buildPIEvent( const ref TokenProcessingState state, const XmlToken tok) @safe nothrowBuilds a `PROCESSING_INSTRUCTION` event from a token.
fnXmlEvent buildDoctypeEvent( const ref TokenProcessingState state, const XmlToken tok) @safe pure nothrowBuilds a `DOCTYPE` event from a token.
fnXmlEvent buildEofEvent(const XmlToken tok) @safe pure nothrowBuilds an `EOF` event from a token.