I am completely aware of the duplicate keys problem with yaml spec:
The content of a mapping node is an unordered set of key: value node pairs, with the restriction that each of the keys is unique.
For instance, I have emitted a yaml file using yaml-cpp library with a nested tree structure which looks like this:
work:
- run:
type: workout
figures:
start_time:
start: 9
end_time:
end: 12
- run:
type: workout
figures:
start_time:
start: 16
end_time:
end: 18
Evidently, it has duplicate keys and yaml-validator treats it as a normal file. But when i try to parse it using yaml-cpp
void parser(const std::string& path)
{
const YAML::Node& baseNode = YAML::Loadfile(path);
for (const auto& item : baseNode["work"]);
{
switch (item.second.Type()) //Error not a valid yaml node
{
//If it is a NullNode
case YAML::NodeType::Null:
break;
//If it is a ScalarNode
case YAML::NodeType::Scalar:
scalarNodeIterator(item.second, item.first.as<std::string>());
break;
//If it is a SequenceNode
case YAML::NodeType::Sequence:
sequenceNodeIterator(item.second, item.first.as<std::string>());
break;
//If it is a MapNode
case YAML::NodeType::Map:
mapNodeIterator(item.second, item.first.as<std::string>());
break;
}
}
}
What do i want:
As you can see i have my own node dependent iterators to read through any kind of yaml tree. I need to use duplicate keys and when i do, the parser should work as intended.
Is it possible to implement a parser which can read through a node like run? If yes, how can i achieve it? If not, any other solutions to emit a yaml file with readable duplicate keys?