Sequence Comments

Issue #502 resolved
Wolf2323 created an issue

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)

  1. Wolf2323 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.

  2. Andrey Somov

    That is why comment are explicitly thrown away in the specification.

    Please do not use specification as an argument

  3. Wolf2323 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:

    1. Change the node tree, ensuring a clean design, but breaking API of dependent projects that operate on the node tree.
    2. 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.
    3. Ignore the issue and move comments before the enumeration dash into the enumeration, writing them after the dash.

  4. Log in to comment