Procs
proc elems(n: YNode): seq[YNode] {....raises: [], tags: [], forbids: [].}
-
Get the list value of the node
Throws if n is not a list
Example:
let l = newYList(@[newYNil(), newYString("abc")]) let items = l.elems() doAssert len(items) == 2 doAssert items[0].kind == ynNil doAssert items[1].strVal == "abc"
Source Edit proc newYMapRemoveNils(a: openArray[(string, YNode)]): YNode {....raises: [], tags: [], forbids: [].}
-
Example:
import std/tables let node = newYMapRemoveNils( [("a", newYString("astring")), ("b", newYNil())]) doAssert node.kind == ynMap doAssert node.mapVal.len == 1
Source Edit proc newYString(s: string): YNode {....raises: [], tags: [], forbids: [].}
- Source Edit
proc ofYaml(n: YNode; t: typedesc[bool]): bool
-
Example:
doAssert ofYaml(newYString("true"), bool) == true doAssert ofYaml(newYString("false"), bool) == false
Source Edit proc ofYaml(n: YNode; t: typedesc[float]): float
-
Example:
let n = newYString("3.14") doAssert ofYaml(n, float) == 3.14
Source Edit proc ofYaml(n: YNode; t: typedesc[int]): int
-
Example:
let n = newYString("8675309") doAssert ofYaml(n, int) == 8675309
Source Edit proc ofYaml(n: YNode; t: typedesc[string]): string
-
Example:
let n = newYString("yep") doAssert ofYaml(n, string) == "yep"
Source Edit proc ofYaml[T](n: YNode; t: typedesc[Option[T]]): Option[T]
-
Example:
import std/options let n1 = newYNil() let o1 = ofYaml(n1, Option[string]) doAssert o1.isNone let n2 = newYString("heyo") let o2 = ofYaml(n2, Option[string]) doAssert o2.isSome doAssert o2.get() == "heyo"
Source Edit
Macros
macro deriveYaml(v: typed)
-
Generate ofYaml and toYaml procs for a type
Example:
type Obj = object i: int s: string deriveYaml Obj var sample: string = """ i: 99 s: hello world """ var o: Obj = ofYamlStr(sample, Obj) doAssert o.i == 99 doAssert o.s == "hello world"
Source Edit macro deriveYamls(body: untyped)
-
Derive yamls for multiple types
Example:
type Owner = ref object of RootObj name: string Pet = ref object of RootObj name: string kind: string owner: Owner deriveYamls: Owner Pet let sample = """ name: Garfield kind: cat owner: name: J. Arbuckle """ let garf = ofYamlStr(sample, Pet) doAssert garf.name == "Garfield" doAssert garf.kind == "cat" doAssert garf.owner.name == "J. Arbuckle"
Source Edit
Templates
template assertYList(n: YNode)
- Source Edit
template assertYMap(n: YNode)
- Source Edit
template assertYString(n: YNode)
- Source Edit
template expectYList(n: YNode; body: untyped) {....deprecated.}
- Source Edit
template expectYMap(n: YNode; body: untyped) {....deprecated.}
- Source Edit
template expectYString(n: YNode; body: untyped) {....deprecated.}
- Source Edit