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.

6 Likes

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

2 Likes

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

5 Likes

Garry,

Nice work as this is cool. It is even easier than YAML.

2 Likes

This is the first thing that came to my mind !

OS/2 used that all the way: neat and easy to use. Later Microsoft invented registries :weary:.

Does it support arrays?

sometimes it’s nice to reinvent the wheel, because wheels evolve

1 Like
integers = [ 1, 2, 3 ]
mixed_array = [1, 2, "a", "b", "c"]
string_array = [ "all", "strings", """are the same""", "type" ]

# Mixed-type arrays are allowed
numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]
contributors = [
  "Foo Bar <foo@example.com>",
  { name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }
]
1 Like

Um… why would one not just use JSONItem?

This was a fun project but moving forwards I suggest using Kem’s TOML classes.