1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-10-18 00:16:11 -04:00

add special case for stream with one document

This commit is contained in:
Philipp Otterbein 2022-11-05 18:49:02 +01:00
parent 54fef9510c
commit 086eedf3fb

View file

@ -85,7 +85,7 @@ static RegisterPrimOp primop_fromYAML({
.name = "__fromYAML",
.args = {"e"},
.doc = R"(
Convert a YAML string to a Nix value, if a conversion is possible. For example,
Convert a YAML 1.2 string to a Nix value, if a conversion is possible. For example,
```nix
builtins.fromYAML ''{x: [1, 2, 3], y: !!str null, z: null}''
@ -109,7 +109,10 @@ static RegisterPrimOp primop_fromYAML({
auto tree = parser.parse_in_arena({}, ryml::csubstr(yaml.begin(), yaml.size()));
tree.resolve(); // resolve references
visitYAMLNode(context, val, tree.rootref());
auto root = tree.rootref();
if (root.is_stream() && root.num_children() == 1)
root = root.child(0);
visitYAMLNode(context, val, root);
}
});