SDL (Simple Declarative Language) was designed to provide a terse and perspicuous format for describing common data structures and data types. Although XML is an excellent format for marking up documents, embedding in free form text, and creating graphs it can be a cumbersome language for expressing basic datastructures. SDL is particularly well suited for this purpose. Lists, maps, trees, tables, and matrixes can be easily expressed in SDL. Following is a list of examples demonstrating construction of various datastructures using typed data.
Because of its terse syntax and type inference capabilities, SDL is ideally suited to applications such as
- Configuration Files
- Build Files
- Property Files
- Simple Object Serialization
- Log files (formatting and parsing)
SDL was designed to be language agnostic. Currently APIs exist for Java and .NET (written in C#.) C++, Python and Ruby ports are planned.
A tag can contain a namespace, a name, a value list, attributes (with namespaces), and children. All components are optional. If the name portion is ommited the tag name defaults to "content". Namespaces default to the empty space (""). Names and namespaces are identifiers.
Tags are written using the form:
Tags are terminated with a new line (\n) or the ending bracket of a child list (}). Lines can be continued by escaping the new line like so:
Values are space separated literals and attributes are space separated key value pairs using the format:
Children are SDL tags and may be nested to an arbitrary depth. They are indented by convention but tabs are not significant in the language.
As of SDL 1.1 tags can be listed separated by semicolons on the same line:
The Tag Data Structure
Tag values and children are modelled as lists. Order is significant and duplicates are allowed.
Tag attributes are modelled as a sorted map. Order is not significant and duplicates are not allowed.
Tags with no name are known as anonymous tags. They are automatically assigned the name "content".
|Note: Anonymous tags must have at least one value|
Anonymous tags must have one or more values. They cannot contain only attributes. This design decision was taken to avoid confusion between a tag with a single value and an anonymous tag containing only one attribute.
An SDL identifier starts with a unicode letter or underscore (_) followed by zero or more unicode letters, numbers, underscores (_), dashes (-), periods (.) and dollar signs ($). Examples of valid identifiers are:
SDL supports 13 literal types. They are (parenthesis indicate optional components):
- unicode string - examples: "hello" or `aloha`
- unicode character - example: '/'
- Note: \uXXXX style unicode escapes are not supported (or needed because sdl files are UTF8)
- integer (32 bits signed) - example: 123
- long integer (64 bits signed) - examples: 123L or 123l
- float (32 bits signed) - examples 123.43F or 123.43f
- double float (64 bits signed) - example: 123.43 or 123.43d or 123.43D
- decimal (128+ bits signed*) - example: 123.44BD or 123.44bd
- boolean - examples: true or false or on or off
- date yyyy/mm/dd - example 2005/12/05
- date time yyyy/mm/dd hh:mm(:ss)(.xxx)(-ZONE)
- example - 2005/12/05 05:21:23.532-JST
- notes: uses a 24 hour clock (0-23), only hours and minutes are mandatory
- time span using the format (d:)hh:mm:ss(.xxx)
- 12:14:42 (12 hours, 14 minutes, 42 seconds)
- 00:09:12 (9 minutes, 12 seconds)
- 00:00:01.023 (1 second, 23 milliseconds)
- 23d:05:21:23.532 (23 days, 5 hours, 21 minutes, 23 seconds, 532 milliseconds)
- note 1: hours, minutes, and seconds are required - days and milliseconds are optional
- note 2: if the day component is included it must be suffixed with a lower case 'd'
- binary [standard Base64] example - [sdf789GSfsb2+3324sf2]
- null A literal for a null value (must be lower case) example - null
* Notes: For platforms that do not support this level of precision, decimal should resolve to the most accurate decimal representation possible.
There are two ways to write a string literal. Double quoted literals begin and end with a double quote ("). They cannot span lines unless the new line is escaped. If the new line is escaped, all white space to the left of the first non-white space character in the next line is ignored. For example, if we write
The test tag's value will be "john doe". The space before the escape is preserved, but the space before the "d" in "doe" is ignored. White space characters (\n\r\t ), backslashes () and double quotes (") must be escaped in double quote literals.
The second type of string literal is the backquote (`) literal. It functions much like Python's triple quote (""") or C#'s at quote (@""). All characters including whitespace between backquotes are preserved. It is not necessary (or possible) to escape any type of character in a backquote literal.
Note: SDL interprets new lines in backquote String literals as a single new line character (\n) regarless of the platform.
Binary literals use base64 characters enclosed in square brackets (). The binary literal type can also span lines. White space is ignored.
Date and Date/Time Literals
SDL supports date and date/time literals. Date and date/time literals use a 24 hour clock (0-23). If a timezone is not specified, the default locale's timezone will be used.
Note: Timezones must be specified using a valid timezone ID (ex. America/Los_Angeles), three letter abbreviation (ex. HST), or GMT(+/-)hh(:mm) formatted custom timezone (ex. GMT+02 or GMT+02:30)
Time Span Literals
SDL Time Span literals represent a length of time (which may be negative.) TimeSpan literals are useful for expressing the duration of an event, intervals, or chronological distances from a reference point.
SDL supports four comment types.
The first three are line comment types. Line comments can start with a #, //, or --. Everything between the beginning of the single line comment and the new line is ignored. The – style separator comment is often used to visually separate sections like so:
The fourth type of comment is the /* */ style multiline comment used in Java and C family languages. Everything between the /* and */ is ignored. /* */ comments may span lines and occur in the middle of lines.
SDL files (any file ending with the extension .sdl) should always be encoded using UTF-8. The use of unicode escaping (such as the \uxxxx format used by Java and C#) is not supported or required. Non ASCII characters should be entered directly using a UTF-8 capable editor.
Note: ASCII is transparently encoded in UTF8, so ASCII files can be used if only ASCII characters are required.
Example SDL File
We evaluated the following languages and frameworks during the development process