You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/kdl.nim
+29-19Lines changed: 29 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
## # kdl-nim
2
-
## kdl-nim is an implementation of the [KDL document language](https://kdl.dev) in the Nim programming language.
2
+
## kdl-nim is an implementation of the [KDL document language](https://kdl.dev) v1.0.0 in the Nim programming language.
3
3
##
4
4
## ## Installation
5
5
## ```
@@ -8,18 +8,19 @@
8
8
##
9
9
## ## Overview
10
10
## ### Parsing KDL
11
-
## kdl-nim parses strings (or files) into a `KdlDoc` which is a sequence of `KdlNode`s.
11
+
## kdl-nim parses strings, files or streams into a `KdlDoc` which is a sequence of `KdlNode`s.
12
12
##
13
13
## Each `KdlNode` holds a name, an optional type annotation (tag), zero ore more arguments, zero or more properties and optionally children nodes.
14
-
##
15
-
## Arguments and properties' values are represented by an object variant `KdlVal`. `KdlVal` can be any of `KString`, `KFloat`, `KBool`, `KNull` or `KInt`.
14
+
## Arguments are a sequence of values, while properties are an unordered table of string and values.
15
+
## Arguments and properties' values are represented by the object variant `KdlVal`. `KdlVal` can be of any kind `KString`, `KFloat`, `KBool`, `KNull` or `KInt`.
16
16
runnableExamples:
17
-
let doc =parseKdl("node 1 null {child \"abc\" true}") # You can also read files using parseKdlFile("file.kdl")
let doc =parseKdl("node (i8)1 null key=\"val\" {child \"abc\" true}") # You can also read files using parseKdlFile("file.kdl")
18
+
assert doc ==@[
19
+
initKNode("node",
20
+
args =@[initKVal(1, "i8".some), initKNull()],
21
+
props = {"key": initKVal("val")}.toTable,
22
+
children =@[initKNode("child", args =@[initKVal("abc"), initKVal(true)])])
23
+
]
23
24
24
25
## ### Reading nodes
25
26
runnableExamples:
@@ -51,9 +52,8 @@ runnableExamples:
51
52
assert doc[0].args[0].get(float32) ==1f
52
53
assert doc[0].args[1].get(int) ==3
53
54
assert doc[0].args[2].get(uint8) ==255u8
55
+
assert doc[0].args[0].get(string) =="1"
54
56
55
-
## It only converts between numbers, you can't `val.get(string)` if `val.isBool()`.
56
-
##
57
57
## ### Setting values
58
58
runnableExamples:
59
59
var doc =parseKdl("node 1 3.14 {child \"abc\" true}")
@@ -72,9 +72,9 @@ runnableExamples:
72
72
assert doc[0].children[0].args[0] =="def"
73
73
74
74
## ### Creating KDL
75
-
## To create KDL documents, nodes or values without parsing you can also use the `toKdl`, `toKdlNode` and`toKdlVal` macros which have a similar syntax to KDL:
75
+
## To create KDL documents, nodes or values without parsing or object constructors you can use the `toKdlDoc`, `toKdlNode` and`toKdlVal` macros which have a similar syntax to KDL:
## `-d:kdlDecoderAllowHoleyEnums`: to allow converting integers into holey enums.
97
+
## `-d:kdlDecoderNoCaseTransitionError`: to not get a compile error when trying to change a discriminator field from an object variant in an init hook.
89
98
90
99
## ## More
91
-
## Checkout these other useful modules as well:
92
-
## - [kdl/decoder](kdl/decoder.html) for KDL deserializing
93
-
## - [kdl/encoder](kdl/encoder.html) for KDL serializing
100
+
## Checkout these other useful modules:
101
+
## - [kdl/encoder](kdl/encoder.html) for KDL serializing (Nim objects to KDL)
102
+
## - [kdl/decoder](kdl/decoder.html) for KDL deserializing (KDL to Nim objects)
94
103
## - [kdl/xix](kdl/xik.html) for [XML-in-KDL](https://github.com/kdl-org/kdl/blob/main/XML-IN-KDL.md)
95
104
## - [kdl/jix](kdl/jix.html) for [JSON-in-KDL](https://github.com/kdl-org/kdl/blob/main/JSON-IN-KDL.md)
96
-
## - [kdl/prefs](kdl/prefs.html) for simple preferences sytem.
105
+
## - [kdl/prefs](kdl/prefs.html) for a simple preferences sytem.
0 commit comments