yaml_document_* builder question

William Roberts <[email protected]> Wed, 13 Dec 2023 11:04:39 -0600
Newsgroups gmane.text.yaml.general
Message-ID <CAFftDdqgc9ah2frxKbeAer+wK72KR=zwEzXw1hsF2yrrtrEgQA@mail.gmail.com>
I have been using the yaml_document_add methods to build a
yaml_document_t and then emit it. Everything has been working fine for
emitting maps and sequences. However, what if I just wanted my yaml
output to be just a scalar?

I've tried using  yaml_document_add_scalar() but it just outputs "{}".
Is there an api for adding something like "foo" to the yaml_document_t
so the output is just "foo".


To help debug this I added some printfs to libyaml and Python using
the pylibyaml bindings where I get the output I expected (see below).
It seems its using the event based stream API, is that the only way
this is supported? Is my understanding of what valid yaml is incorrect
(I just used yamllint.com to validate). Is this just a byproduct of
the stream based emitters/parsers?

#!/usr/bin/env python

import pylibyaml
import yaml
import os
s="foo"
x = yaml.safe_dump(s)
print(x)

which prints:
./test.py
BILL: yaml_emitter_initialize
BILL: yaml_emitter_set_output
BILL: yaml_stream_start_event_initialize
BILL: yaml_event_delete
BILL: yaml_document_start_event_initialize
BILL: yaml_scalar_event_initialize
BILL: yaml_check_utf8
BILL: yaml_check_utf8
BILL: yaml_event_delete
BILL: yaml_event_delete
BILL: yaml_document_end_event_initialize
BILL: yaml_event_delete
BILL: yaml_stream_end_event_initialize
BILL: yaml_event_delete
BILL: yaml_emitter_delete
foo