@@ -31,26 +31,25 @@ var doc = parseKdl("""
31
31
title \
32
32
"Some title"
33
33
34
+ // Files must be utf8 encoded!
35
+ smile (emoji)"😁" {
36
+ upside-down (emoji)"🙃"
37
+ }
34
38
35
- // Files must be utf8 encoded!
36
- smile (emoji)"😁" {
37
- upside-down (emoji)"🙃"
38
- }
39
+ // Instead of anonymous nodes, nodes and properties can be wrapped
40
+ // in "" for arbitrary node names.
41
+ "!@#$@$%Q#$%~@!40" "1.2.3" "!!!!!"=true
39
42
40
- // Instead of anonymous nodes, nodes and properties can be wrapped
41
- // in "" for arbitrary node names.
42
- "!@#$@$%Q#$%~@!40" "1.2.3" "!!!!!"=true
43
+ // The following is a legal bare identifier:
44
+ foo123~!@#$%^&*.:'|?+ "weeee"
43
45
44
- // The following is a legal bare identifier:
45
- foo123~!@#$%^&*.:'|?+ "weeee "
46
+ // And you can also use unicode!
47
+ ノード お名前="☜(゚ヮ゚☜) "
46
48
47
- // And you can also use unicode!
48
- ノード お名前="☜(゚ヮ゚☜)"
49
-
50
- // kdl specifically allows properties and values to be
51
- // interspersed with each other, much like CLI commands.
52
- foo bar=true "baz" quux=false 1 2 3
53
- """) # You can also read files using parseKdlFile("file.kdl")
49
+ // kdl specifically allows properties and values to be
50
+ // interspersed with each other, much like CLI commands.
51
+ foo bar=true "baz" quux=false 1 2 3
52
+ """) # You can also read files using parseKdlFile("file.kdl")
54
53
55
54
# Nodes are represented like:
56
55
# type KdlNode* = object
@@ -60,28 +59,28 @@ foo bar=true "baz" quux=false 1 2 3
60
59
# props*: Table[string, KdlVal]
61
60
# children*: seq[KdlNode]
62
61
63
- assert doc[0][0].isString() # title "Some title"
62
+ assert doc[0].args [0].isString() # title "Some title"
64
63
65
- assert doc[1][0] == "😁" # smile node
66
- assert doc[1][0].tag.isSome and doc[1][0].tag.get == "emoji" # Type annotation
67
- assert doc[1].children[0][0] == "🙃" # smile node's upside-down child
64
+ assert doc[1].args [0] == "😁" # smile node
65
+ assert doc[1].args [0].tag.isSome and doc[1].args [0].tag.get == "emoji" # Type annotation
66
+ assert doc[1].children[0].args [0] == "🙃" # smile node's upside-down child
68
67
69
68
assert doc[2].name == "!@#$@$%Q#$%~@!40"
70
69
71
70
assert doc[^1]["quux"] == false
72
71
73
- doc[0][0].setString("New title")
72
+ doc[0].args [0].setString("New title")
74
73
75
74
# toKdlNode is a macro that facilitates the creation of `KdlNode`s, there's also toKdl (to create documents) and toKdlVal
76
75
doc[1].children[0] = toKdlNode: sunglasses("😎"[emoji], 3.14)
77
76
78
77
assert $doc[1].children[0] == "\"sunglasses\" (\"emoji\")\"😎\" 3.14"
79
78
80
- assert doc[1].children[0][1].get(uint8) == 3u8 # Converts 3.14 into an uint8
79
+ assert doc[1].children[0].args [1].get(uint8) == 3u8 # Converts 3.14 into an uint8
81
80
82
81
doc[^1]["bar"].setTo(false) # Same as setBool(false)
83
82
84
- doc. writeFile("doc.kdl")
83
+ writeFile("doc.kdl", doc )
85
84
```
86
85
87
86
## Docs
0 commit comments