-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge keys appear not to be supported #168
Comments
Apparently this "Working Draft" did not make it into "Final Draft" YAML 1.1 specification. There are no mentions of "<<" or "merge". |
Yes, I noticed that. It seems to be supported in many other tools (e.g. If we decide not to support this for now, I think it would be good to at least:
|
For a parser, the scalar At the parsing level nothing special should be done with a scalar Btw, as you mentioned pyyaml - yes, pyyaml supports merge keys, and even when it's used with libyaml as the backend. Since libyaml doesn't resolve boolans, numbers etc. as it only does the parsing, there is nothing to implement. |
I see. So to clarify, it's intended that C code that wants to use merge keys needs to implement that itself? This seems pretty non-trivial to implement on top of libyaml. Do you have an example of how this work? It seems like a lot of code. Is there a higher-level C library on top of libyaml that I could use to implement without writing a lot of custom code? |
A higher level library like pyyaml processes merge keys when it already has constructed a partial data structure. So if you want to add this on top of libyaml, you need to have the previous anchors stored in a mapping-like data structure, and additionally the currently processed mapping has to be constructed already before you can add the data from the merge keys. You could try out https://github.com/pantoniou/libfyaml, its documentation says it supports merge keys on request. |
I don't think it will be too much code... If you are interested I can probably provide an example. |
Yes, an example would be helpful. I'm a little confused about something: anchors seem to be working just fine. For instance, the following parses without issue:
I guess I'm trying to understand if this is a question of "we haven't implemented this but would like to", or is it "we plan never to implement this, by design." |
An alias is part of the syntax. Aliases will be parsed as an It's hard to help if we don't know what you are actually doing. |
I'm using document parsing. This is the code if you want to look: https://github.com/XevoInc/yobd/blob/master/src/parser.c |
@martingkelly ok, like I said, resolving of booleans and other types does not happen in the document loader, so also merge keys are simple scalar nodes like I'm not saying it would be impossible to implement that in the document loader. But post processing would probably a better idea than putting it directly into the existing loader code. |
In my link, I parse directly into my own data structures; I don't do intermediate processing or translation of the YAML. e.g. in https://github.com/XevoInc/yobd/blob/master/src/parser.c#L320, we convert a scalar to a number and stick it into a data structure. It sounds like this issue can be resolved as "by design", as libyaml is intended to do only parsing and not composing/construction, and alias resolution is considered part of composing/construction. Is this correct? |
I found this in my own project when attempting to use merge keys ("<<:", https://yaml.org/type/merge.html). Specifically, the key gets parsed literally as a scalar with value "<<". To see this, try the following:
You will see a node like this in the output:
The text was updated successfully, but these errors were encountered: