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 1
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();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 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 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.