RussellSpitzer / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 1 forks source link

Add support for setting/getting comments. #179

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Basically, with the way SnakeYAML currently works.. Even if you manually add 
comments, you can only add them to root values. If SnakeYAML had native support 
for comments in the YAML file, it would allow for easy per-line comments.

Original issue reported on code.google.com by mnmill...@gmail.com on 2 Jul 2013 at 12:39

GoogleCodeExporter commented 9 years ago
How do I change this from Defect to Enhancement? I didn't see an option so I 
just tagged the title.

Original comment by mnmill...@gmail.com on 2 Jul 2013 at 12:40

GoogleCodeExporter commented 9 years ago

Original comment by alexande...@gmail.com on 2 Jul 2013 at 6:29

GoogleCodeExporter commented 9 years ago
From the spec (http://yaml.org/spec/1.1/#id864687):
Comments are a presentation detail and must not have any effect on the 
serialization tree or representation graph. In particular, comments are not 
associated with a particular node.

This requirement cannot be fullfilled when comments are supported in the public 
API.

Original comment by py4fun@gmail.com on 2 Jul 2013 at 7:31

GoogleCodeExporter commented 9 years ago
So.. There is no way to even allow manually adding comments per-node?

Original comment by mnmill...@gmail.com on 5 Jul 2013 at 2:16

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Well, it depends.
If you expect us to do the implementation then no way (at least for me). Not 
because it is against the spec, but because it is difficult to make it 
beautiful and consistent (that is why it is explicitly excluded in the spec). A 
general solution to be used in the public API will be ugly.
If you want to do it yourself - just go ! You have a particular use case in 
mind, and you do not want to support tons of weird requirements. If your 
solution happens to be flexible enough, we can consider to include it to the 
low level API. 

Original comment by py4fun@gmail.com on 5 Jul 2013 at 8:09

GoogleCodeExporter commented 9 years ago
My idea of a way to support per-node comments was just have a Map of the 
comments and each node, similar to the way the node map works. My plan to have 
comments displayed was either above each node, or at the end of the nodes line.

Original comment by mnmill...@gmail.com on 5 Jul 2013 at 8:26

GoogleCodeExporter commented 9 years ago
(what is 'the node map' ?)
Even if you add a property to the Node class, there are no events for comments, 
so they cannot be (de)serialised.

Original comment by py4fun@gmail.com on 5 Jul 2013 at 12:16

GoogleCodeExporter commented 9 years ago
With the node map, I got confused with this implementation - 
https://github.com/sk89q/worldedit/blob/master/src/main/java/com/sk89q/util/yaml
/YAMLNode.java

This implementation manages root comments like this: 
https://github.com/sk89q/worldedit/blob/master/src/main/java/com/sk89q/util/yaml
/YAMLProcessor.java#L195

But due to the way SnakeYAML works, its unable to do any comments other than 
root comments.

Original comment by mnmill...@gmail.com on 5 Jul 2013 at 11:47

GoogleCodeExporter commented 9 years ago
Well, SnakeYAML works exactly as it is described in its specification.

Original comment by py4fun@gmail.com on 7 Jul 2013 at 11:53

GoogleCodeExporter commented 9 years ago
Can we at least get an API to set each individual sub-node so that the manual 
method used above will work for things other than root nodes?

Original comment by mnmill...@gmail.com on 7 Jul 2013 at 12:36

GoogleCodeExporter commented 9 years ago
>Can we at least get an API
it means that my previous explanations were for nothing...

>so that the manual method used above will work
YAMLNode.java is not anyhow connected to SnakeYAML and its Node. YAMLNode is 
NOT a root node. YAMLNode does not even import any of the SnakeYAML classes.

Original comment by py4fun@gmail.com on 7 Jul 2013 at 7:30