SDLang

Simple Declarative Language

SDLang is a simple and concise way to textually represent data. It has an XML-like structure – tags, values and attributes – which makes it a versatile choice for data serialization, configuration files, or declarative languages. Its syntax was inspired by the C family of languages (C/C++, C#, D, Java, …).

			
// This is a node with a single string value
title "Hello, World"

// Multiple values are supported, too
bookmarks 12 15 188 1234

// Nodes can have attributes
author "Peter Parker" email="peter@example.org" active=true

// Nodes can be arbitrarily nested
contents {
	section "First section" {
		paragraph "This is the first paragraph"
		paragraph "This is the second paragraph"
	}
}

// Anonymous nodes are supported
"This text is the value of an anonymous node!"

// This makes things like matrix definitions very convenient
matrix {
	1 0 0
	0 1 0
	0 0 1
}
			

Implementations

Data types

			
// Strings
"String \"with escape support\""
`String "without escape support"`

// Numbers
10    // 32-bit integer
10.5  // 64-bit float (double)
10L   // 64-bit integer
10BD  // 128-bit integer
10.5f // 32-bit float

// Boolean and null values
true  // boolean true
false // boolean false
on    // boolean true
off   // boolean false
null  // a null value

// Date/time formats
2015/12/06 12:00:00.000-UTC // Date/time value (UTC timezone)
2015/12/06 12:00:00.000     // Date/time value (local time)
2015/12/06                  // Date value
12:14:34     // Duration: 12 hours, 14 minutes, 34 seconds
12:14:34.123 // 12 h, 14 min, 34 s, 123 ms
2d:12:14:34  // 2 days, 12 h, 14 min, 34 s

// Binary data (Base64 encoded)
[sdf789GSfsb2+3324sf2]
			

Comment styles

			
// C++ style

/*
C style multiline
*/

tag /*foo=true*/ bar=false

# Shell style

-- Lua style
			

Syntax details

			
// Trailing semicolons are optional
title "Some title";

// They can be used to separate multiple nodes
title "Some title"; author "Peter Parker"

// Tags may contain certain non-alphanumeric characters
this-is_a.valid$tag-name

// Namespaces are supported
renderer:options "invisible"
physics:options "nocollide"

// Tags can be separated into multiple lines
title \
	"Some title"
			

Tools

Who uses SDLang?

References

Copyright © 2015, Sönke Ludwig. Distributed under the terms of the MIT license. All trademarks in this document are owned by their respective trademark holders.