Search code examples
yamlparser-generatoryaml-cpp

Alternative script for YAML?


I was going to use yaml because it has great feature called merge! ("<<" key)

And I'm using 'yaml-cpp' for parser since i'm working on cpp.

But! yaml-cpp does not support merge. What can I do for alternatives?

Other scripts, other parser, other way to parse or whatever is good if I can use merge feature.

BUT I don't need to merge more than one object. I just need define something and create another object inheritd from the first one and override some values. That it.

Thanks for reading.


Solution

  • If you're unable to wait and need merges, you can follow the suggestion by "barma" on the yaml-cpp issue: http://code.google.com/p/yaml-cpp/issues/detail?id=41#c12

    The change is to insert the lines below into FindValueForKey template (between for-loop and return 0):

    const Node *pValueMerge = FindValueForKey(std::string("<<"));
    if(pValueMerge) {
        return pValueMerge->FindValueForKey(key);
    }
    

    The problem (as I mentioned on the issue page) is that the spec allows

    <<: [*dict1, *dict2]
    

    to merge multiple dictionaries; but it appears you don't need that.