-1

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.

SeniorLee
  • 805
  • 1
  • 12
  • 25
  • This is clearly a "bump" of your [previous question](http://stackoverflow.com/questions/5101542/script-that-support-merge-feature-like-yaml). I'm sorry you didn't get an answer before, but the solution is to edit it, not waste people's time with duplicates. – Matthew Flaschen Feb 28 '11 at 03:32
  • Well I deleted it before I post this question. And your link is broken now. I don't know how you found my previous question. Maybe it's deleted little while after marked as deleted. Is this still bad way to post question again? What's the difference between editing previous one and delete old one and post new question? My purpose was to put my question on the first page. Does editing previous question do same way? – SeniorLee Feb 28 '11 at 08:00
  • the link is not broken, you just don't have the reputation to view it. As I said, it's bad because it wastes people's time. People who read your previous question see a new one that provides no additional information. There are genuinely new questions that belong on the front page. – Matthew Flaschen Mar 01 '11 at 03:50

3 Answers3

0

Ask 'yaml-cpp' to implement the feature.

Andrey
  • 2,931
  • 22
  • 18
  • There is already an open issue about this(opened since 2009). And I don't have time to wait until it's implemented. Thanks. – SeniorLee Feb 28 '11 at 10:24
0

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.

Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
  • I've tried this but it seems fall into infinite loop. Maybe I put this code somewhere wrong. Have you try this? Does it really work? I might have to try again – SeniorLee Mar 02 '11 at 03:26
  • And one more thing, even if it works, iterating through the node is not supported isn't it? The code just works for when finding by key I guess. – SeniorLee Mar 02 '11 at 05:37
  • @SeniorLee - first, does this in fact work for you? (I can't be sure, since you accepted the answer but posted that comment.) Second, that's correct, you won't be able to iterate through the merged node too, unless you do that explicitly. – Jesse Beder Mar 02 '11 at 05:41
0

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
dreftymac
  • 31,404
  • 26
  • 119
  • 182