dex.cf.document

CF Document Model

This module defines the concrete syntax tree (CST) types for CF documents. The document model preserves all metadata needed for roundtrip fidelity, including comments, source locations, original formatting, and quote styles.

The primary types are:

  • CfDocument — The root container for a CF file
  • CfNode — A value node in the document tree
  • CfMember — A key-value pair in an object
  • CfComment — A comment (line or block)

Types 7

Comment style enumeration.

Indicates which comment syntax was used in the original source.

HASHHash comment: # ...
DOUBLE_SLASHDouble-slash comment: // ...
BLOCKBlock comment: slash-star ... star-slash
structCfComment

A comment in a CF document.

Preserves both the decoded content and the original raw text for roundtrip fidelity.

Fields
string textComment content without delimiters
CommentStyle styleWhich comment syntax was used
Location locSource location of the comment
string rawTextOriginal text including delimiters (for exact reproduction)
Methods
string toString() const @safe pureCreates a human-readable string representation.

Node type enumeration for CF values.

Represents the semantic type of a CfNode.

OBJECTObject container { ... }
ARRAYArray container [ ... ]
STRINGString literal
INTEGERInteger number
FLOATFloating-point number
BOOLEANBoolean value (true or false)
NULL_VALUENull value
DATEDate literal (YYYY-MM-DD)
TIMETime literal (HH:MM:SS)
DATETIMEDateTime literal (ISO 8601)
structCfMember

A member (key-value pair) in a CF object.

Preserves all metadata needed for roundtrip fidelity.

Fields
string keyDecoded key text
string rawKeyOriginal key text (quoted or unquoted)
Location keyLocSource location of the key
bool hasEqualsWhether `=` was used (vs `:`)
SeparatorStyle separatorThe separator after this member
CfNode * valueThe value node
CfComment[] leadingCommentsComments before this member
CfComment[] trailingCommentsInline comment after this member
structCfNodeRef

A lightweight reference wrapper for CfNode that enables natural chaining.

This wrapper allows idiomatic D syntax like doc["server"]["port"].as!long by providing opIndex that returns another CfNodeRef.

Example:

auto doc = parseCFDocument(`server { host = "localhost", port = 8080 }`);
auto port = doc["server"]["port"].as!long;  // 8080
auto missing = doc["nonexistent"]["key"].as!string;  // "" (safe, no crash)

Fields
private CfNode * ptr
Methods
bool isValid() @property const @safe pure nothrowCheck if this reference points to a valid node
inout(CfNode) * node() @property inout @safe pure nothrowGet the underlying pointer (may be null)
CfNodeRef opIndex(string key) @safe pure nothrowIndex into object by key.
CfNodeRef opIndex(size_t index) @safe pure nothrowIndex into array by index.
T as(T)() const @safe pure nothrowType-safe value extraction.
bool isNull() @property const @safe pure nothrowReturns true if this is a null value node or an invalid reference.
bool isObject() @property const @safe pure nothrowReturns true if this is an object node.
bool isArray() @property const @safe pure nothrowReturns true if this is an array node.
bool isString() @property const @safe pure nothrowReturns true if this is a string node.
bool isInteger() @property const @safe pure nothrowReturns true if this is an integer node.
bool isFloat() @property const @safe pure nothrowReturns true if this is a float node.
bool isBoolean() @property const @safe pure nothrowReturns true if this is a boolean node.
bool isScalar() @property const @safe pure nothrowReturns true if this is a scalar (non-container) value.
size_t length() @property const @safe pure nothrowReturns the number of elements (for arrays) or members (for objects).
string[] keys() @property const @safe pureReturns the keys of an object node.
bool hasKey(string key) const @safe pure nothrowChecks if an object contains a specific key.
T getOr(T)(string key, T defaultValue = T.init) const @safe pure nothrowGets a value by key with a default fallback.
int opApply(scope int delegate(CfNodeRef) @safe dg) @safeEnables foreach iteration over array elements.
int opApply(scope int delegate(string, CfNodeRef) @safe dg) @safeEnables foreach iteration over object members as key-value pairs.
Constructors
this(CfNode * p)Construct from a pointer (may be null)
structCfNode

A node in the CF document tree.

Represents a value in the document, preserving all metadata for roundtrip fidelity. The type field indicates which value field is active.

Fields
CfNodeType typeThe semantic type of this node
Location locSource position of the node's first token
CfComment[] leadingCommentsComments that appear before this node
CfComment[] trailingCommentsInline comment after this node on the same line
string stringValueFor STRING, DATE, TIME, DATETIME: the decoded string content
long longValueFor INTEGER: signed value
ulong ulongValueFor INTEGER: unsigned value (when value exceeds long range)
double doubleValueFor FLOAT: the numeric value
bool boolValueFor BOOLEAN: the boolean value
QuoteStyle quoteStyleFor strings: which quote form was used
string rawValueOriginal text representation (e.g., 0xFF, 1_000, "hello")
CfMember[] membersOrdered key-value pairs (for OBJECT)
bool hasExplicitBracesFalse for the implicit top-level object
CfNode *[] elementsOrdered elements (for ARRAY)
Methods
CfNode makeNull(Location loc = Location.init) @safe pureCreates a null node.
CfNode makeBool(bool value, Location loc = Location.init) @safe pureCreates a boolean node.
CfNode makeInteger(long value, string raw = "", Location loc = Location.init) @safe pureCreates an integer node.
CfNode makeFloat(double value, string raw = "", Location loc = Location.init) @safe pureCreates a float node.
CfNode makeString(string value, string raw = "", QuoteStyle style = QuoteStyle.DOUBLE, Location loc = Location.init) @safe pureCreates a string node.
CfNode makeDate(string value, Location loc = Location.init) @safe pureCreates a date node.
CfNode makeTime(string value, Location loc = Location.init) @safe pureCreates a time node.
CfNode makeDateTime(string value, Location loc = Location.init) @safe pureCreates a datetime node.
CfNode makeObject(bool explicitBraces = true, Location loc = Location.init) @safe pureCreates an empty object node.
CfNode makeArray(Location loc = Location.init) @safe pureCreates an empty array node.
CfNodeRef opIndex(string key) @safe pure nothrowIndex operator for object member access.
CfNodeRef opIndex(size_t index) @safe pure nothrowIndex operator for array element access.

A CF document.

The root container for a parsed CF file. The root node is always an OBJECT with hasExplicitBraces = false for the implicit top-level object.

Fields
CfNode rootThe root node (always an OBJECT)
string sourceSource filename
CfComment[] trailingCommentsComments after the last member
Methods
CfDocument create(string filename = "") @safe pureCreates an empty document.
CfNodeRef opIndex(string key) @safe pure nothrowIndex operator forwarded to root.
CfNodeRef opIndex(size_t index) @safe pure nothrowIndex operator for integer index (for when root is array-like).
size_t length() @property const @safe pure nothrowNumber of members in the root object.
string[] keys() @property const @safe pureKeys of the root object.
bool hasKey(string key) const @safe pure nothrowCheck if root contains a key.
T getOr(T)(string key, T defaultValue = T.init) const @safe pure nothrowGet value with default, forwarded to root.
int opApply(scope int delegate(string, CfNode *) @safe dg) @safeEnables foreach iteration over root members.
auto byMember() @safe pure nothrowRange over root members.

Functions 36

fnbool isNull(const(CfNode) * self) @property @safe pure nothrowReturns true if this is a null value node (or pointer is null).
fnbool isNull(ref const CfNode self) @property @safe pure nothrowditto
fnbool isObject(const(CfNode) * self) @property @safe pure nothrowReturns true if this is an object node.
fnbool isObject(ref const CfNode self) @property @safe pure nothrowditto
fnbool isArray(const(CfNode) * self) @property @safe pure nothrowReturns true if this is an array node.
fnbool isArray(ref const CfNode self) @property @safe pure nothrowditto
fnbool isString(const(CfNode) * self) @property @safe pure nothrowReturns true if this is a string node.
fnbool isString(ref const CfNode self) @property @safe pure nothrowditto
fnbool isInteger(const(CfNode) * self) @property @safe pure nothrowReturns true if this is an integer node.
fnbool isInteger(ref const CfNode self) @property @safe pure nothrowditto
fnbool isFloat(const(CfNode) * self) @property @safe pure nothrowReturns true if this is a float node.
fnbool isFloat(ref const CfNode self) @property @safe pure nothrowditto
fnbool isBoolean(const(CfNode) * self) @property @safe pure nothrowReturns true if this is a boolean node.
fnbool isBoolean(ref const CfNode self) @property @safe pure nothrowditto
fnbool isDate(const(CfNode) * self) @property @safe pure nothrowReturns true if this is a date node.
fnbool isDate(ref const CfNode self) @property @safe pure nothrowditto
fnbool isTime(const(CfNode) * self) @property @safe pure nothrowReturns true if this is a time node.
fnbool isTime(ref const CfNode self) @property @safe pure nothrowditto
fnbool isDateTime(const(CfNode) * self) @property @safe pure nothrowReturns true if this is a datetime node.
fnbool isDateTime(ref const CfNode self) @property @safe pure nothrowditto
fnbool isTemporal(const(CfNode) * self) @property @safe pure nothrowReturns true if this is any temporal type (date, time, or datetime).
fnbool isTemporal(ref const CfNode self) @property @safe pure nothrowditto
fnbool isScalar(const(CfNode) * self) @property @safe pure nothrowReturns true if this is a scalar (non-container) value.
fnbool isScalar(ref const CfNode self) @property @safe pure nothrowditto
fnsize_t length(const(CfNode) * self) @property @safe pure nothrowReturns the number of elements (for arrays) or members (for objects).
fnsize_t length(ref const CfNode self) @property @safe pure nothrowditto
fnstring[] keys(const(CfNode) * self) @property @safe pureReturns the keys of an object node.
fnstring[] keys(ref const CfNode self) @property @safe pureditto
fnbool hasKey(const(CfNode) * self, string key) @property @safe pure nothrowChecks if an object contains the given key.
fnbool hasKey(ref const CfNode self, string key) @property @safe pure nothrowditto
fnT getOr(T)(const(CfNode) * self, string key, T defaultValue = T.init) @safe pure nothrowGets a member's value with a default fallback.
fnT getOr(T)(ref const CfNode self, string key, T defaultValue = T.init) @safe pure nothrowditto
fnT as(T)(CfNode * self) @safe pure nothrowType-safe value extraction for CfNode pointers (UFCS).
fnT as(T)(const(CfNode) * self) @safe pure nothrowType-safe value extraction for const CfNode pointers (UFCS).
fnT as(T)(ref const CfNode self) @safe pure nothrowType-safe value extraction for CfNode references (UFCS).
private fnT asImpl(T)(ref const CfNode node) @safe pure nothrowInternal implementation of type conversion.