A method for analyzing barley? (YAML-CPP)

I made a yaml file as shown below.

Define1: &Define1
  0: zero
  1: one

Define2:
  <<: *Define1
  2: two

And I tried the YAML Online Parser . The result is as follows. (Just get how the nodes are built.)

{
  "Define1": {
    "0": "zero", 
    "1": "one"
  }, 
  "Define2": {
    "0": "zero", 
    "1": "one", 
    "2": "two"
  }
}

Of course, I expected yaml-cpp to be parsed the same way, but it is somehow different.

I think so. (Almost sure)

{
  "Define1": {
    "0": "zero", 
    "1": "one"
  }, 
  "Define2": {
    "Define1": {
      "0": "zero", 
      "1": "one"
    },  
    "2": "two"
  }
}

What the heck! Then, do I need to check the type of node during the loop?

Is this a known issue? or are yaml-cpp just parsing this path?

This code did just that.

// already parsed
const YAML::Node& node = &(docYAML)["Define2"];

for (YAML::Iterator it=node->begin(); it!=node->end(); ++it)
{
    const YAML::Node& nodeList = it.second();

    std::string str;
    nodeList[0] >> str;
}
+3
source share
1 answer

yaml-cpp does not yet implement the "merge" key. If you want to solve this problem before implementing it, see http://code.google.com/p/yaml-cpp/issues/detail?id=41 .

Currently, yaml-cpp is actually parsing your YAML file as:

{
  "Define1": {
    "0": "zero", 
    "1": "one"
  }, 
  "Define2": {
    "<<": {
      "0": "zero", 
      "1": "one"
    },  
    "2": "two"
  }
}
+4
source

Source: https://habr.com/ru/post/1794109/


All Articles