Skip to content
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

anchor in sequence dereferenced in a map fail, replaced by a scalar. #268

Closed
Schwartzp opened this issue Jun 28, 2022 · 4 comments · Fixed by #339
Closed

anchor in sequence dereferenced in a map fail, replaced by a scalar. #268

Schwartzp opened this issue Jun 28, 2022 · 4 comments · Fixed by #339

Comments

@Schwartzp
Copy link

I was using the library in order to parse a yaml to json.
I had this yaml as input :

Constants:
  - &bar bar
Thisis: 
  ATree: *bar

Strangely instead of "{"ATree" : "bar"} in the last map i had "bar" in the json emitted document.

my code:

std::string strIn; // input yaml string 
auto tree = ryml::parse_in_place(ryml::to_substr(strIn));
tree.resolve(); 
std::string out = ryml::emitrs_json<std::string>(tree);

Putting " - bar: &bar bar" in the first line of the yaml did the trick. But i believe this may be a bug.
Thanks for the library by the way !

@biojppm
Copy link
Owner

biojppm commented Jul 8, 2022

Thanks for reporting, and sorry for the late reply. Can you clarify exactly what you had as the result in out?

@Schwartzp
Copy link
Author

Schwartzp commented Jul 12, 2022

From this code :

#include <ryml_std.hpp>
#include <ryml.hpp>
#include <iostream>
int main(int argc,char*argv[]){
 std::string strIn ="\
Constants:\n\
  - &bar bar\n\
Thisis:\n\
  ATree: *bar";
 auto tree = ryml::parse_in_place(ryml::to_substr(strIn));
 tree.resolve();
 std::string out = ryml::emitrs_json<std::string>(tree);
 std::cout << out;
}

output is:
{"Constants": ["bar"],"Thisis": {"bar"}}
when i was expecting:
{"Constants": ["bar"],"Thisis": {"Atree":"bar"}}

@biojppm
Copy link
Owner

biojppm commented Jul 12, 2022

I see. I will have to look at the situation; expect some time before this gets fixed.

@Schwartzp
Copy link
Author

No problem for me.
Like i said putting the anchor in a map instead of a sequence work and is fine with my use.
I just reported to help the project. Thanks again.

NaN-git pushed a commit to NaN-git/rapidyaml that referenced this issue Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants