c++yaml-cpp

Using yaml-cpp to parse YAML files with complex keys


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?


Solution

  • 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