ddn.data.sdl

SDL (Simple Declarative Language) Parser and Writer

This module provides complete SDL support including:

  • Parsing SDL documents into CDM structures
  • Preserving comments, formatting, and source locations
  • Serializing CDM documents back to SDL
  • Support for all 13 SDL literal types
  • Namespace support for tags and attributes
  • Anonymous tags and line continuation
  • Four comment styles (hash, double-slash, block, double-dash)

SDL is a tag-based configuration language with rich literal types including dates, timespans, and binary data.

Types 7

structSdlError

Error information for SDL parsing failures.

Fields
size_t line
size_t column
string message
string source
Methods
string toString() const @safeFormat error as human-readable string.
structSdlPolicy

Policy options for SDL parsing.

Fields
size_t maxDepth
bool strictNamespaces

Options for SDL serialization.

Fields
bool prettyPrint
uint indentWidth
bool preserveRawText
CdmComment.Style commentStyle
enumSdlTokenKind : ubyte

SDL token kinds produced by the lexer.

UNKNOWNInvalid/unrecognised input
EOFEnd of input
LBRACE{
RBRACE}
SEMICOLON;
EQUALS=
COLON: (namespace or in datetime literal)
BACKSLASH_NL\ at end of line (line continuation)
LINE_COMMENT_HASH# ...
LINE_COMMENT_DSLASH// ...
LINE_COMMENT_DASH-- ...
BLOCK_COMMENT/ ... /
STRING"..." double-quoted string
BACKTICK`...` backtick/raw string
CHARACTER'x' single character
INTEGER123, 123L
FLOAT3.14, 3.14F, 3.14d, 123.44BD
BOOLEANtrue, false, on, off
DATE2005/12/05
DATETIME2005/12/05 14:12:23.345-ZONE
TIMESPAN12:14:42, 12:14:42.532
BINARY[base64...]
NULL_LITnull
IDENTIFIERmyName, my-name, com.example.foo
structSdlToken

A single SDL token produced by the lexer.

Fields
string value
string rawText
size_t line
size_t column
size_t offset
private structSdlLexer

SDL lexer that tokenises input on demand.

Supports all SDL lexical constructs including:

  • Four comment styles (hash, double-slash, block, double-dash)
  • String literals (double-quoted and backtick)
  • Character literals
  • Numeric literals (integer, float, double, decimal)
  • Boolean literals (true, false, on, off)
  • Date, datetime, and timespan literals
  • Binary literals (base64 in [ ])
  • Null literal
  • Identifiers with namespace prefix
  • Line continuation (backslash-newline)
  • Semicolon tag separator
Fields
const(char)[] input
size_t pos
size_t line
size_t column
Methods
SdlToken nextToken() @safeAdvance to the next token.
void advance() pure nothrow @nogc @safe
void skipWhitespace() @safe
SdlToken readDateOrDateTime(size_t startPos, size_t startLine, size_t startCol, size_t startOffset) @safe
SdlToken readTimeSpan(size_t startPos, size_t startLine, size_t startCol, size_t startOffset) @safe
bool isDigit(char c) const pure nothrow @nogc @safe
bool isIdentStart(char c) const pure nothrow @nogc @safe
bool isIdentContinue(char c) const pure nothrow @nogc @safe
Constructors
this(const(char)[] input)

Internal SDL CDM parser.

Consumes tokens from an SdlLexer and produces CdmNode trees. Handles all SDL grammar constructs including tags, values, attributes, namespaces, anonymous tags, and comments.

Fields
SdlLexer lexer
SdlPolicy policy
SdlError * err
string source
SdlToken current
CdmComment[] pendingComments
Builder builder
Methods
void advance() @safe
bool isCommentToken(SdlTokenKind kind) pure nothrow @nogc @safe
bool fail(string msg) @safe
Constructors
this(const(char)[] input, SdlPolicy policy, SdlError * err, string source)

Functions 36

private fnbool parseDocument(Builder)(ref SdlCdmParser!Builder p) @safeParse a complete SDL document via the builder.
private fnbool parseDocumentCdm(ref SdlCdmParser!CdmBuilder p) @safeCdmBuilder document parsing: uses anonymous tag wrapper for multiple tags.
private fnbool parseDocumentVar(ref SdlCdmParser!VarBuilder p) @safeVarBuilder document parsing: top-level tags become object members.
private fnbool parseTag(Builder)(ref SdlCdmParser!Builder p, CdmComment[] leadingComments) @safeParse a single SDL tag via the builder.
private fnbool parseNamedTag(Builder)(ref SdlCdmParser!Builder p, CdmComment[] leadingComments, CdmLocation loc) @safeParse a named tag with optional namespace via the builder.
private fnbool parseAnonymousTag(Builder)(ref SdlCdmParser!Builder p, CdmComment[] leadingComments, CdmLocation loc) @safeParse an anonymous tag (no name, must have at least one value).
private fnbool parseValuesAndAttributes(Builder)(ref SdlCdmParser!Builder p) @safeParse values and attributes for a named tag via the builder.
private fnbool parseAttribute(Builder)(ref SdlCdmParser!Builder p) @safeParse an attribute via the builder: [namespace ':'] name '=' value
private fnbool parseChildrenBlock(Builder)(ref SdlCdmParser!Builder p) @safeParse a children block: '{' (comment | tag)* '}' via the builder.
private fnbool isAttributeStart(Builder)(ref SdlCdmParser!Builder p) @safeCheck if the current position starts an attribute.
private fnbool parseLiteral(Builder)(ref SdlCdmParser!Builder p) @safeParse any SDL literal via the builder.
private fnvoid collectTrailingComment(Builder)(ref SdlCdmParser!Builder p) @safeCollect trailing comment on the same line as the current token.
private fnlong parseLong(const(char)[] raw) pure @safeParse an SDL integer literal to long.
private fndouble parseDouble(const(char)[] raw) pure @safeParse an SDL float/double/decimal literal to double.
private fnbool parseBool(const(char)[] raw) pure nothrow @nogc @safeParse an SDL boolean literal.
private fnDate parseDate(const(char)[] raw) pure @safeParse an SDL date literal (yyyy/mm/dd) to std.datetime.date.Date.
private fnDateTime parseDateTime(const(char)[] raw) pure @safeParse an SDL datetime literal to std.datetime.date.DateTime.
private fnDuration parseTimeSpan(const(char)[] raw) pure @safeParse an SDL timespan literal to core.time.Duration.
private fnimmutable(ubyte)[] decodeBase64(const(char)[] base64) @safeDecode a base64 string to immutable ubyte[]. Decode a base64 string to immutable ubyte[].
fnauto parseSdlCdm(Builder = CdmBuilder)(const(char)[] input, string source = "") @safeParse SDL text into a CDM document.
fnauto parseSdlCdm(Builder = CdmBuilder)(File file) @safeParse SDL file.
fnbool parseSdlCdm(out CdmDocument doc, const(char)[] input, out SdlError err, string source = "", SdlPolicy policy = SdlPolicy.init) @trustedNon-throwing parse variant.
private fnbool parseSdlCdmWithBuilder(Builder)(ref Builder.Result result, const(char)[] input, ref SdlError err, string source = "", SdlPolicy policy = SdlPolicy.init) @trustedInternal templated parse function.
fnstring toSdl(const ref CdmDocument doc, SdlWriteOptions opts = SdlWriteOptions.init) @safeSerialize a CDM document to SDL text.
fnvoid toSdl(Out)(const ref CdmDocument doc, ref Out output, SdlWriteOptions opts = SdlWriteOptions.init) @safeOutput range variant of toSdl().
private fnvoid writeTag(Out)(ref Out buf, const ref CdmNode node, uint depth, const ref SdlWriteOptions opts) @safeWrite a tag node as SDL text.
private fnvoid writeLiteral(Out)(ref Out buf, const ref CdmNode node, const ref SdlWriteOptions opts) @safeWrite a literal value node as SDL text.
private fnvoid writeStringLiteral(Out)(ref Out buf, const(char)[] s, CdmFormat.QuoteStyle style) @safeWrite a string literal with appropriate quoting.
private fnvoid writeComment(Out)(ref Out buf, const ref CdmComment c, uint depth, const ref SdlWriteOptions opts) @safeWrite a comment with proper SDL formatting.
private fnvoid writeInlineComment(Out)(ref Out buf, const ref CdmComment c) @safeWrite an inline (trailing) comment.
private fnvoid indent(Out)(ref Out buf, uint depth, const ref SdlWriteOptions opts) pure @safeWrite indentation spaces.
private fnstring formatDate(Date d) pure @safeFormat a Date as SDL date literal (yyyy/mm/dd).
private fnstring formatTime(TimeOfDay t) pure @safeFormat a TimeOfDay as SDL time literal (hh:mm:ss).
private fnstring formatDateTime(DateTime dt) pure @safeFormat a DateTime as SDL datetime literal (yyyy/mm/dd hh:mm:ss).
private fnstring formatDuration(Duration d) pure @safeFormat a Duration as SDL timespan literal.
private fnstring encodeBase64(const(ubyte)[] data) @safeEncode ubyte[] as base64 string.