ddn.data.cdm.varbuilder
Var builder — produces a lightweight var without metadata.
This module provides the VarBuilder struct which implements the builder pattern for producing var values. It has the same duck-typed API as CdmBuilder but discards all metadata (location, formatting, comments) for minimal memory usage.
VarBuilder also implements SDL tag flattening: SDL tags are converted to simple var objects using conventions like #value, #values, and @attr keys (see BUILDERS.md §2.3 for the full flattening rules).
Copyright
Types 2
A stack frame for tracking nested var container construction.
Kind kindWhich kind of container.var containerThe container var being built.string tagNameTag name (only for TAG kind).string tagNsTag namespace (only for TAG kind).var[] tagValuesPending tag values collected during tag parsing.string savedKeySaved pending key from outer member.bool savedHasPendingMemberWhether an outer member was pending when this frame was pushed.KindThe kind of container being built.Builder that produces a lightweight var value.
VarBuilder has the same API as CdmBuilder but all metadata setters are no-ops. Value setters create var instances directly. Container operations push/pop frames on a stack.
SDL tags are flattened at endContainer() time according to the following rules:
- Single value, no attrs, no children → flattened to value
- Multiple values, no attrs, no children → array
- Single value + children → value becomes nested key
- Attributes only → object with @-prefixed keys
- Value + attributes → #value + @-prefixed keys
- Multiple values + attrs/children → #values array + other keys
Tag namespace, if present, is stored under a "#ns" key.
Examples
VarBuilder b;
b.startDocument(CdmDocument.Format.CF, "app.cf");
b.startObject();
b.startMember("host");
b.setString("localhost");
b.endMember();
b.endContainer();
auto v = b.endDocument();
assert(v["host"].as!string == "localhost");void startDocument(CdmDocument.Format fmt, string source) @safe @nogc nothrowBegins a new document (no-op for VarBuilder).void addPrologComment(CdmComment comment) @safe @nogc nothrowNo-op — VarBuilder does not preserve comments.void addEpilogComment(CdmComment comment) @safe @nogc nothrowNo-op — VarBuilder does not preserve comments.void setQuoteStyle(CdmFormat.QuoteStyle style) @safe @nogc nothrowNo-op — VarBuilder does not preserve quote style.void setNumberFormat(CdmFormat.NumberFormat fmt) @safe @nogc nothrowNo-op — VarBuilder does not preserve number format.void setBracketStyle(CdmFormat.BracketStyle style) @safe @nogc nothrowNo-op — VarBuilder does not preserve bracket style.void setIndentation(string indent) @safe @nogc nothrowNo-op — VarBuilder does not preserve indentation.void setBlankLinesBefore(ubyte lines) @safe @nogc nothrowNo-op — VarBuilder does not preserve blank lines.void addLeadingComment(CdmComment comment) @safe @nogc nothrowNo-op — VarBuilder does not preserve comments.void addLeadingComment(CdmComment[] comments) @safe @nogc nothrowNo-op — VarBuilder does not preserve comments.void setLeadingComments(CdmComment[] comments) @safe @nogc nothrowNo-op — VarBuilder does not preserve comments.void addTrailingComment(CdmComment comment) @safe @nogc nothrowNo-op — VarBuilder does not preserve comments.void setTrailingComments(CdmComment[] comments) @safe @nogc nothrowNo-op — VarBuilder does not preserve comments.void startMember(string key,
CdmFormat.QuoteStyle quoteStyle = CdmFormat.QuoteStyle.NONE,
CdmFormat.KeyValueSep separator = CdmFormat.KeyValueSep.EQUALS) @safe @nogc nothrowBegins a new member in the current object.void setElementSeparator(CdmFormat.SeparatorStyle style) @safe @nogc nothrowNo-op — VarBuilder does not preserve element separators.void addPostKeyComment(CdmComment comment) @safe @nogc nothrowNo-op — VarBuilder does not preserve post-key comments.void addPostKeyComment(CdmComment[] comments) @safe @nogc nothrowNo-op — VarBuilder does not preserve post-key comments.void addAttribute(string name, string ns = "",
CdmLocation loc = CdmLocation.init) @safeAdds an attribute to the current tag as an @-prefixed key.void mergeDocument(var v) @safeMerges members from an included var into the current top-of-stack container.void addTrailingCommentToTop(CdmComment comment) @safe @nogc nothrowNo-op — VarBuilder does not preserve trailing comments.var flattenTag(VarFrame frame) @safeFlattens a tag frame into a var according to SDL tag rules.