Alternative script for YAML?

742 views Asked by At

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.

3

There are 3 answers

3
Jesse Beder On BEST ANSWER

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.

1
Andrey On

Ask 'yaml-cpp' to implement the feature.

0
dreftymac On

Problem

Using YAML merge keys.

Solution

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

The following YAML implementations support the desired feature as of this writing

  • Ruby 2.x
  • Python 2.x // 3.x