NDL Language

NDL (nested data language) is a data serialization and config language for representing nested structures.

// line comment
/* block comment /* with nesting */ */

scene {
    size { x 1920 y 1080 }
    camera.type "orthographic"
    layers [ {
        name "background"
        textures [ `background.png` `mask.png` ]
        scale { x 1.2 y 1.0 }
    } {
        name "foreground"
        enabled false
    } ]
}

Design principles

Goals:

Non-goals:

Specification

Keys are arbitrary strings, that are represented either:

There are following types of values:

Document contains exactly one value of any type. If this type is map, {} brackets must be omitted. Empty (or comment-only) document is an empty map. NDL document file extension is .ndl.

A key in the map may be written as dot-separated path, e.g. k1.k2.kN. In this case, nested maps are created for each path level, e.g. k1 {}, k1 { k2 {} }, etc. No whitespace is allowed between path parts and dots.

After expanding key paths, maps at the same path are merged recursively. If multiple map values have the same path, they are merged. Map/non-map and non-map/non-map conflicts are invalid (NDL does not allow value overriding).

// speaking less formally, this is allowed
category.sub1 { key1 "val1" key2 "val2" }
category.sub2 { key1 "val1" key2 "val2" }
category { key "val" }

// and is interpreted as
category {
    sub1 { key1 "val1" key2 "val2" }
    sub2 { key1 "val1" key2 "val2" }
    key "val"
}

Dotted paths

Maps and arrays may contain values of any type, including other maps and arrays. For any value, it is possible to write a path to it - a sequence of map keys and array indices. NDL semantics allows to unambiguously represent a path to any value as a string, constructed as follows:

category { array [ { 'weird key' "val" } ] }
// a path to the value "val" here can be
// represented as category.array.0.'weird key'

This is a convenient way to refer to a value by its path, and is recommended to implement by libraries. Though, you can't write dotted paths with array indices in NDL code itself, due to ambiguity problems it would cause.

Canonical format

It is recommended to format NDL documents as follows:

Why another standard

You probably thought of the "how standards proliferate" meme. Well, no existing standard covered the needs of OpenWallpaper's declarative scene frontend I'm planning to develop. I tried to avoid making a new standard, but was left with no choice.