Introducing XOOL and XOOLKit

Hi,

I’ve just released version 1.0 of an open source configuration file format designed specifically for Xojo.

Download XOOLKit.

XOOL (Xojo Optimised Obvious Language), pronounced Zool is a human readable file format for saving configuration data. Think JSON, only simpler. XOOLKit is the reference parser for XOOL written in Xojo.

There are already many formats for saving configuration data but none of them satisfy these aims:

  1. Human readable
  2. Directly translatable to Xojo code
  3. Support comments within the document

JSON has curly braces all over the place and doesn’t support comments. YAML supports comments but uses whitespace for indentation. This means large configuration files can become difficult to edit by hand without an IDE to help. TOML comes really close but as it has matured it has, in my opinion, become overly complex for my needs.

# This is a comment.

# These are values of the root dictionary.
stringValue = "Some value"
doubleValue = 1.00
integerValue = 42
booleanValue = True # Comments run to the end of the line.
colorValue = &cABCDEF

multiLineStringValue = """
Roses are red
Violets are blue"""

[database]
ports = [8080, 80]
enabled = False

[servers.debug]
ip = "123.456.789.0"
password = "123456"

[servers.production]
ip = "123.456.111.2"
password = "password1"

The above XOOL is equivalent to the following JSON:

{
  "stringValue": "Some value", 
  "doubleValue": 1.00, 
  "integerValue": 42,
  "booleanValue": true,
  "colorValue": "&cABCDEF", 
  "multilineStringValue": "Roses are red\nViolets are blue",
  
  "database": {
    "ports": [8080, 80], 
    "enabled": false
  }, 
  
  "servers": {
    "debug": {
      "ip": "123.456.789.0",
      "password": "123456"
    }, 
    "production": {
      "ip": "123.456.111.2", 
      "password": "password1"
    }
  }
}

Using XOOL is dead easy:

// Convert a dictionary to a XOOL document.
Var d As New Dictionary("name" : "Garry", "age" : 40)
Var xool As String = GenerateXOOL(d)

// Parse a XOOL document (e.g. from a file) into a dictionary.
Try
d = ParseXOOL(inputXOOL) // Assumes `inputXOOL` is a XOOL document.
Catch e As XOOLKIT.XKException
// There's a problem with the input XOOL.
End Try

I’m using the format currently for theme files for an editor I’m working on but I’ve also found it more convenient than JSON for preferences files, etc. The support for comments in the document goes a long way to help with readability.

I even include a class interface (XKSerializable) that allows you to serialise your own classes.

Here’s what it can look like with proper syntax highlighting (forgive the gross colours, they are just for testing):

The repository has a detailed specification in the README. It supports lots of things like arrays, inline dictionaries, hex/octal/binary literals, DateTime, etc.

Please let me know what you think about it.

5 Likes

So you reinvented Microsoft INI files changing little things like “#” instead of “;” ?

1 Like

Technically I reinvented Tom Preston-Werner’s TOML format to make it a little simpler with better translation to Xojo.

2 Likes