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).

Types 2

private structVarFrame

A stack frame for tracking nested var container construction.

Fields
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.
Nested Templates
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");
Fields
var _current
VarFrame[] _stack
string _pendingKey
bool _hasPendingMember
string _lastTagName
Methods
void startDocument(CdmDocument.Format fmt, string source) @safe @nogc nothrowBegins a new document (no-op for VarBuilder).
var endDocument() @safeCompletes the document and returns the root var.
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 setNull() @safeSets current to a null var.
void setBool(bool value) @safeSets current to a boolean var.
void setInteger(long value) @safeSets current to an integer var.
void setFloat(double value) @safeSets current to a float var.
void setString(string value) @safeSets current to a string var.
void setDate(Date value) @safeSets current to a date var.
void setTime(TimeOfDay value) @safeSets current to a time var.
void setDateTime(DateTime value) @safeSets current to a datetime var.
void setDuration(Duration value) @safeSets current to a duration value.
void setBinary(immutable(ubyte)[] value) @trustedSets current to a binary var.
void setLocation(CdmLocation loc) @safe @nogc nothrowNo-op — VarBuilder does not preserve location.
void setFormat(CdmFormat fmt) @safe @nogc nothrowNo-op — VarBuilder does not preserve format.
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 setRawText(string text) @safe @nogc nothrowNo-op — VarBuilder does not preserve raw text.
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 startObject() @safePushes a new empty object onto the stack.
void startArray() @safePushes a new empty array onto the stack.
void startTag(string name, string ns = "") @safePushes a new tag frame onto the stack.
void endContainer() @safePops the stack, completing the current container.
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 endMember() @safeCompletes the pending member and adds it to the current object.
void addElement() @safeAppends the current value to the current array.
void addTagValue() @safeAppends the current value to the pending tag values list.
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 addChildToTop() @safeAdds current as a child of the top-of-stack container.
CdmLocation topLocation() @safe @nogc nothrow constNo-op — VarBuilder does not preserve locations.
void addTrailingCommentToTop(CdmComment comment) @safe @nogc nothrowNo-op — VarBuilder does not preserve trailing comments.
private var flattenTag(VarFrame frame) @safeFlattens a tag frame into a var according to SDL tag rules.