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.
Copyright
Types 2
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.
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();CdmDocument _docCdmNode _currentFrame[] _stackstring _pendingKeyCdmFormat.QuoteStyle _pendingKeyQuoteStyleCdmFormat.KeyValueSep _pendingSeparatorCdmFormat.SeparatorStyle _pendingElementSeparatorCdmComment[] _pendingPostKeyCommentsbool _hasPendingMemberbool _valueSetvoid 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).CdmNode _target() ref return pure @safeReturns a reference to the active node for metadata setting.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 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 setTrailingComments(CdmComment[] comments) pure @safeReplaces all trailing comments on the current node.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[] 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 addAttribute(string name, string ns = "",
CdmLocation loc = CdmLocation.init) pure @safeAdds an attribute to the current tag node.void addTrailingCommentToTop(CdmComment comment) pure @safeAdds a trailing comment directly to the top-of-stack container, bypassing target() logic.void mergeDocument(CdmDocument doc) pure @safeMerges members from an included document into the current top-of-stack container.