Felix Krause 29352fa4fe Use global tag handle for NimYAML
* NimYAML now uses the tag prefix tag:nimyaml.org,2016:
 * That tag handle is shortened to !n! when presenting
 * Also fixed some minor bugs dealing with tag handles
2016-10-10 20:16:54 +02:00

37 lines
741 B
Nim

import yaml, streams
type
Person = object
name: string
ContainerKind = enum
ckString, ckInt, ckBool, ckPerson, ckNone
Container = object
case kind: ContainerKind
of ckString:
strVal: string
of ckInt:
intVal: int
of ckBool:
boolVal: bool
of ckPerson:
personVal: Person
of ckNone:
discard
setTagUri(Person, nimTag("demo:Person"))
# tell NimYAML to use Container as implicit type.
# only possible with variant object types where
# each branch contains at most one object.
markAsImplicit(Container)
var list: seq[Container]
var s = newFileStream("in.yaml")
load(s, list)
s.close()
assert(list[0].kind == ckString)
assert(list[0].strVal == "this is a string")
# and so on