-1

Does lib-yaml support complex keys, for example:

thr:
  - ? {cpu: 1, mem: 1} : 24
  - ? {cpu: 2, mem: 2} : 42

The following test program

#include <yaml-cpp/yaml.h>

int main()
{
    YAML::Node config = YAML::LoadFile("complex_keys.yaml");
}

Fails to parse the YAML file prints the error

terminate called after throwing an instance of 'YAML::ParserException'
  what():  yaml-cpp: error at line 3, column 22: illegal map value
Aborted (core dumped)

The following YAML file also fails to parse with the same error.

---
thr:
  ? 
    cpu: 2
    mem: 1
  : 42

Or am I doing something wrong?


Update

Rather than delete, for posterity's sake, I voted to close my own question after I found a solution from 12 years ago. Back then yaml-cpp parsed the file but today it segfaults terminates. Could this be a yaml-cpp regression?

7
  • It does not segfault. It terminates the program: terminate called after throwing an instance of 'YAML::ParserException'. Commented Apr 10 at 18:26
  • Time to file a bug report. I've worked with YAML quite a bit, but I couldn't justify whether this is valid or not, so it may be a challenge to justify. Out of curiosity, what are you using this for? Commented Apr 10 at 18:31
  • @UlrichEckhardt I am designing a config for a that is in some sections a table. I'll file a bug report tonight. Commented Apr 10 at 18:45
  • What version do you use? I just checkedout the latest released version (0.8.0) and built that and compiled your program using it - no issues. I also compiled the latest on master and tried with that - no issues. Commented Apr 10 at 19:13
  • @TedLyngmo I too compiled and ran version 0.8.0 on Ubuntu 22.04.5 LTS. Did you run the example? Commented Apr 11 at 8:48

1 Answer 1

0

I found the problem. NBSPs "found their way" into the file.

Its a silly mistake but an "unsupported character" error on line X would be helpful.

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

I wouldn't have guessed that. map is something like a dictionary to me, so I'd have expected something wrong with the values in one of the YAML dicts. So even though you found the problem, a better error message would really help the next person.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.