Sequence Comments
There is one mayor issue with Comments and the SequenceNode.
Lets have a look at the yaml spec 1.1 picture Figure 3.3. Representation Model
https://yaml.org/spec/1.1/represent2.png , this is also the implementation in snakeyaml.
A Node can contain Block and Inline Comments. So a sequence self can contain Comments and every entry of the sequence.
But lets look at this example:
key:
# Comment 1
- #Comment 2
value
Booth comments are valid, but as we can see, every SequenceNode-Entry and every entry self can contain comments, and they are splitted by the -
.
Since this PR https://bitbucket.org/asomov/snakeyaml/pull-requests/16 the Comment 1 is collected together with Comment 2 and belog to the entry and not to the sequence entry. To make it possible to parse booth of the comments correctly, an change is required that probably break the API.
This issue is now for maybe figure out a good solution. If we have one i can try to fix it.
Comments (7)
-
-
reporter The node tree in snakeyaml is the same as the node tree in YAML spec. And now we have to order comments to the nodes. But we do not have the structure to represent the comments before and after the dash. That is simply not possible with the current node tree. So we have to figure out a solution. the easiest way i can imagine is to change the node tree to have sequence entries, they contain the comments before the dash. And the real nodes inside the sequence entries then contain the comments after the dash.
-
That is why comment are explicitly thrown away in the specification.
Please do not use specification as an argument
-
reporter Of course you're right that the specification isn’t the template for the node tree structure, but it currently aligns with it, making it a good visualization.
The issue is that, as the node tree implementation is very similar to this graph from the YAML spec and it thus does not allow adding the comments as described without changing the node tree structure. But changing the node tree structure would be API breaking.
These are the possible ways to progress here I can think of:
- Change the node tree, ensuring a clean design, but breaking API of dependent projects that operate on the node tree.
- Find a workaround to do it with the current structure but it might get quite messy as there now need to be two variants of the same type of comment for list entries.
- Ignore the issue and move comments before the enumeration dash into the enumeration, writing them after the dash.
-
Possible way 1 is not an option
-
@Wolf2323 may I kindly ask to have a look ?
https://bitbucket.org/snakeyaml/snakeyaml-engine/pull-requests/2Since you were busy with Emitter recently it may be ,much faster for you to fix it
-
- changed status to resolved
- Log in to comment
Comments are not part of the Presentation Graph. Why do you connect it to the YAML spec ?