dlang-community/D-YAML

Building Node structures to dump out

Closed this issue · 2 comments

I believe all the examples show starting by reading a YAML file to create a Node tree and then fiddling with the tree before dumping it out. Are there any simple examples of building a Node tree programmatically from scratch; the yaml_gen example is hard to follow – but this maybe that I am not trying hard enough.

A small example. A loaded YAML results in:

Node([Pair(Node(use_opengl, line 2,column 1, ZeroString!"Tag"(7F149248E040), Plain, Invalid), Node(true, line 2,column 13, ZeroString!"Tag"(7F149248E220), Plain, Invalid))], line 2,column 1, ZeroString!"Tag"(7F149248E080), Invalid, Block)

How might I create programmatically this Node tree?

For the most part, it's as simple as Node(someArray) or Node(someScalar). You can use (associative/regular) arrays of nodes for more complicated things.

This one is as simple as

auto node = Node(["use_opengl": true]);

or

auto node = Node(string[string].init);
node.add("use_opengl", true);

That second example is looking a bit ugly... Perhaps it would be a good idea to skip the mapping check if the node is empty and allow the use of auto node = Node(); in that example instead.

Opened #144 to make the latter example easier.