~dbuckley/zx4

Implementation of the zzz data format
update build module name
feat: add ability to parse StringArrayHashMaps and strings into ArrayLists

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~dbuckley/zx4
read/write
git@git.sr.ht:~dbuckley/zx4

You can also use your local clone with git send-email.

#ZX4

An implementation and slight extension of the ZZZ data format. The goal is to fully implement ZZZ with an addition of indented multiline strings. See the ZZZ README for full details on the data format.

#Testing

zig build test

#Using

See the example for how to use this library.

You can run the example with:

zig run examples/simple.zig --pkg-begin zx4 src/main.zig --pkg-end

#Spec

zzz text describes a tree of strings. Special characters (and spaces) are used to go up and down the tree. The tree has an implicit empty root node.

#Descending the tree:

grandparent:parent:child:grandchild

Output:

null -> "grandparent" -> "parent" -> "child" -> "grandchild"

#Traversing the children of root (siblings):

sibling1,sibling2,sibling3

Output:

null -> "sibling1"
     -> "sibling2"
     -> "sibling3"

#Going up to the parent:

parent:child;anotherparent

Output:

null -> "parent" -> "child"
     -> "anotherparent"

#White space and newlines are significant. A newline will take you back to the root:

parent:child
anotherparent

Output:

null -> "parent" -> "child"
     -> "anotherparent"

#Exactly two spaces are used to to go down a level in the tree:

parent:child
  sibling

Output:

null -> "parent" -> "child"
                 -> "sibling"

#You can only go one level deeper than the previous line's depth. Anything more is an error:

parent:child
    sibling

Output:

Error!

#Trailing commas, semicolons, and colons are optional. So the above (correct one) can be written as:

parent
  child
  sibling

Output:

null -> "parent" -> "child"
                 -> "sibling"

#Strings are trimmed:

parent:     child:      grand child      ;

Output:

null -> "parent" -> "child" -> "grand child"

#Strings can be quoted with double quotes, single quotes, or Lua strings:

"parent":[[ child ]]:[==[grand child]=]]==]:'great grand child'

Output:

null -> "parent" -> " child " -> "grand child]=]" -> "great grand child"

#Lua strings will skip the first newline if it's empty:

[[
some text]]

Output:

null -> "some text"

#Strings are not escaped and taken as-is.

"\n\t\r"

Output:

null -> "\n\t\r"

#Comments begin with # and run up to the end of the line. Their indentation follows the same rules as nodes.

# A comment
a node
  # Another comment
  a child

Output:

null -> "a node" -> "a child"

#Indented multiline strings use the style of TOML and start and end with """. The first newline is skipped if it is empty.

a node: """
  123""""

Output:

null -> "a node" -> "123"
Do not follow this link