ddn.data.cdm.builder

CDM builder — produces a full CdmDocument with roundtrip metadata.

This module provides the CdmBuilder struct which implements the builder pattern for constructing CdmDocument trees. Parsers call builder methods to produce nodes; CdmBuilder retains all metadata (location, formatting, comments) for full roundtrip fidelity.

CdmBuilder is the default builder for all CDM parsers. It is a duck-typed struct — no interface or virtual dispatch. The same parser code can also use VarBuilder to produce lightweight var output.

Types 2

private structFrame

A stack frame for tracking nested container construction.

Each frame stores the container node being built and the pending member state that was active when the frame was pushed. When endContainer() pops the frame, the pending member state is restored so that the completed container can be used as the value of the outer pending member.

Fields
CdmNode nodeThe container node being built.
string savedKeySaved pending key (empty if no member was pending).
CdmFormat.QuoteStyle savedKeyQuoteStyleSaved pending key quote style.
CdmFormat.KeyValueSep savedSeparatorSaved pending separator.
CdmFormat.SeparatorStyle savedElementSeparatorSaved pending element separator.
CdmComment[] savedPostKeyCommentsSaved pending post-key comments.
bool savedHasPendingMemberWhether a member was pending when this frame was pushed.

Builder that produces a CdmDocument with full roundtrip metadata.

Parsers call value setters (setString, setInteger, etc.) to set the "current" node, then metadata setters (setLocation, setQuoteStyle, etc.) to attach formatting details. Container operations (startObject, startArray, startTag) push a new frame; endContainer pops it.

The builder maintains a stack so nested structures are built correctly. Call endDocument() to retrieve the completed CdmDocument.

Examples

CdmBuilder b;
b.startDocument(CdmDocument.Format.CF, "app.cf");
b.startObject();
b.startMember("host");
b.setString("localhost");
b.endMember();
b.endContainer();
auto doc = b.endDocument();
Fields
CdmNode _current
Frame[] _stack
string _pendingKey
CdmFormat.QuoteStyle _pendingKeyQuoteStyle
CdmFormat.KeyValueSep _pendingSeparator
CdmFormat.SeparatorStyle _pendingElementSeparator
CdmComment[] _pendingPostKeyComments
bool _hasPendingMember
bool _valueSet
Methods
void startDocument(CdmDocument.Format fmt, string source) pure @safeBegins a new document.
CdmDocument endDocument() pure @safeCompletes the document and returns it.
void addPrologComment(CdmComment comment) pure @safeAdds a prolog comment (before the root element).
void addEpilogComment(CdmComment comment) pure @safeAdds an epilog comment (after the root element).
void setNull() pure @safeSets current to a NULL node.
void setBool(bool value) pure @safeSets current to a BOOL node.
void setInteger(long value) pure @safeSets current to an INTEGER node.
void setFloat(double value) pure @safeSets current to a FLOAT node.
void setString(string value) pure @safeSets current to a STRING node.
void setDate(Date value) pure @safeSets current to a DATE node.
void setTime(TimeOfDay value) pure @safeSets current to a TIME node.
void setDateTime(DateTime value) pure @safeSets current to a DATETIME node.
void setDuration(Duration value) pure @safeSets current to a DURATION node.
void setBinary(immutable(ubyte)[] value) pure @safeSets current to a BINARY node.
private CdmNode _target() ref return pure @safeReturns a reference to the active node for metadata setting.
void setLocation(CdmLocation loc) pure @safeSets the source location on the current node.
void setFormat(CdmFormat fmt) pure @safeSets the format on the current node.
void setQuoteStyle(CdmFormat.QuoteStyle style) pure @safeSets the quote style on the current node's format.
void setNumberFormat(CdmFormat.NumberFormat fmt) pure @safeSets the number format on the current node's format.
void setBracketStyle(CdmFormat.BracketStyle style) pure @safeSets the bracket style on the current node's format.
void setRawText(string text) pure @safeSets the raw source text on the current node's format.
void setIndentation(string indent) pure @safeSets the indentation on the current node's format.
void setBlankLinesBefore(ubyte lines) pure @safeSets the number of blank lines before this node.
void addLeadingComment(CdmComment comment) pure @safeAdds a leading comment to the current node.
void addLeadingComment(CdmComment[] comments) pure @safeAppends multiple leading comments to the current node.
void setLeadingComments(CdmComment[] comments) pure @safeReplaces all leading comments on the current node.
void addTrailingComment(CdmComment comment) pure @safeAdds a trailing comment to the current node.
void setTrailingComments(CdmComment[] comments) pure @safeReplaces all trailing comments on the current node.
void startObject() pure @safePushes a new empty OBJECT onto the stack.
void startArray() pure @safePushes a new empty ARRAY onto the stack.
void startTag(string name, string ns = "") pure @safePushes a new TAG node onto the stack.
void endContainer() pure @safePops the stack, completing the current container.
void startMember(string key, CdmFormat.QuoteStyle quoteStyle = CdmFormat.QuoteStyle.NONE, CdmFormat.KeyValueSep separator = CdmFormat.KeyValueSep.EQUALS) pure @safeBegins a new member in the current object.
void setElementSeparator(CdmFormat.SeparatorStyle style) pure @safeSets the element separator style on the pending member.
void addPostKeyComment(CdmComment comment) pure @safeAdds a post-key comment to the pending member.
void addPostKeyComment(CdmComment[] comments) pure @safeAdds multiple post-key comments to the pending member.
void endMember() pure @safe Completes the pending member and adds it to the current object. The current node is used as the member value. The pending key, quote style, separator, and comments are attached to the member. *...
void addElement() pure @safeAppends the current node to the current array container.
void addTagValue() pure @safeAppends the current value to the current tag's children.
void addAttribute(string name, string ns = "", CdmLocation loc = CdmLocation.init) pure @safeAdds an attribute to the current tag node.
void addChildToTop() pure @safeAppends the current node as a child of the top-of-stack tag.
CdmLocation topLocation() pure @safe constReturns the location of the top-of-stack container node.
void addTrailingCommentToTop(CdmComment comment) pure @safeAdds a trailing comment directly to the top-of-stack container, bypassing target() logic.
CdmNode stealCurrent() pure @safeReturns and clears current, leaving it in init state.
void setCurrent(CdmNode node) pure @safeSets current directly.
void mergeDocument(CdmDocument doc) pure @safeMerges members from an included document into the current top-of-stack container.