libyaml icon indicating copy to clipboard operation
libyaml copied to clipboard

Support for emitting and parsing comments

Open Tricertops opened this issue 9 years ago • 3 comments

Currently, there is no way to write or read comments using this library.

I understand that comments are intended only for humans, so parsing them into runtime model makes little sense. However, there might be a valid case when some runtime model is written to a file that will be read by humans. Imagine an auto-generated configuration file annotated with comments for further human editing.

This would also allow editing files using this lib without losing human-created coments (even if the exact formatting would be lost).

Supporting comments would probably require these new public APIs:

  • value YAML_COMMENT_TOKEN in enum yaml_token_type_t
  • value YAML_COMMENT_EVENT in enum yaml_event_type_t
  • function yaml_comment_event_initialize(yaml_event_t *event, yaml_char_t *content)

Tricertops avatar Dec 17 '16 09:12 Tricertops

Hi @Tricertops. I agree with you in principal. libyaml should also have a mode where it parses and emits whitespace, for use in things like editors that can't throw away any characters.

With comments the devil is in the details. Full line comments might be easier to start with.

I think to move this idea forward, you should add a number of tests to the test suite. That will allow us to think through the details.

The test suite is: [email protected]:yaml/yaml-test-suite Send us a PR or two.

ingydotnet avatar Jan 01 '17 02:01 ingydotnet

bump

Is that topic still worth researching or is it a WONTFIX?

Would it make sense to establish a more exhaustive list of what's needed to get full line comments support?

tobozo avatar Nov 28 '22 16:11 tobozo