yaml spec on comments

"Martin Eisengardt" <MEP_Eisen-S0/[email protected]> Sat, 7 Jan 2017 14:05:52 +0100
Newsgroups gmane.text.yaml.general
Message-ID <trinity-538a7ad5-67fb-4dfc-a1d9-0e98338bb311-1483794352044@3capp-webde-bap57>
Hi.

My library is manipulating yml files. My users are requesting to not eliminate comments. Administrators like to keep comments for some sections of the file or get comments in newly created files. My task is to parse the files and change them without breaking existing comments.

Using snakeyml I found that there are already fragments in it to parse comments. So I created a patch and contributed to owner. https://bitbucket.org/asomov/snakeyaml/pull-requests/15/options-to-preserve-and-return-yml/diff

Currently snakeyml follows the spec and drops the comments silently as part of the presentation. With patch it is able to request comments from parser. However Andrey Somov quoted to discuss the change on mailing list because it may break the specification.

Getting more deeper into the spec I can see the problem. So my simple question ist: How to solve without breaking the specs?

1) Specification already contains the comment: http://www.yaml.org/spec/1.2/spec.html#id2766150

But it is not associated with any other node. Is it possible for a parser to violate the model and explicitly create associations between node and comment?

Any other suggestions how a parser being interested in returning comments should handle them?

My patch currently simply adds the comments to the Node object following the comment.

2) Specification does not solve a problem associating comments with correct node.

I know it is not important for the specification because it simpl says "comments may be everywhere and we silently drop them during parsing".

But I am not that familiar with yaml spec.

Where may comments be placed?

Am i right with following?

A) comments preceding a document

B) comments preceding a node

C) comments at the end of the file (no more content)

D) comments following a node (f.e. "foo: 1 # my comment")

Or do I miss something?

Greetings

Martin

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot

_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core