Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOML: Trailing Comments in Arrays #3297

Open
bauhaus93 opened this issue Nov 28, 2019 · 2 comments
Assignees
Labels

Comments

@bauhaus93
Copy link

@bauhaus93 bauhaus93 commented Nov 28, 2019

In TOML it is possible to have any amount of comments between the last array element and the closing brackets.
Given the TOML array:

# Comment assigned to array 
array = [    # Comment assigned to element 0
    0,       # Inline comment assigned to element 0
             # Comment assigned to element 1
    1        # Inline comment assigned to element 1
             # Comment we can't store yet, where/how should we do it?
]            # Inline comment assigned to array

How should we store the non-inline comment after value 1, but before the closing brackets?
It is neither before any element that has a key, nor is it an inline comment for any key.

This is the same issue as with comments at the end of a file, which is currently solved by assigning this comments to the file-root key (where comment metakeys have the special meaning of being "at the end of the file"). The same solution is not possible in this case, since any comment metakey with index > 0 assigned to a non-root key is interpreted as "comment before the key".

@bauhaus93 bauhaus93 added the question label Nov 28, 2019
@markus2330

This comment has been minimized.

Copy link
Contributor

@markus2330 markus2330 commented Nov 28, 2019

Thank you for asking the question.

In general I am already impressed how far you already went in preserving the file structure. I do not think we need to go further. At least not at the moment. Now is time to get your plugin to be ready as default storage plugin. But if you need a decision for the implementation...

This is the same issue as with comments at the end of a file, which is currently solved by assigning this comments to the file-root key

Yes, I like this solution. We only need to document this. (Ideally with a whole file where you see where all comments go to.)

How should we store the non-inline comment after value 1, but before the closing brackets?

This is a very tricky question but a bit abusing of the possibility that you can add comments everywhere, e.g.:

key # which number do I get?
=   # which number do I get?
value # this is clear (#0)

or even:

array    # which number do I get?
  =      # which number do I get?
  [      # which number do I get?
    0         # which number do I get?
     ,        #  this is clear (#0)

I think in such situations, like with whitespaces, we do not need to 100% preserve the initial file. So it is okay if your example gets reordered to:

# Comment assigned to array 
# Comment we can't store yet, where/how should we do it?
array = [    # Comment assigned to element 0
    0,       # Inline comment assigned to element 0
             # Comment assigned to element 1
             # Comment we can't store yet, where/how should we do it?
    1        # Inline comment assigned to element 1
]            # Inline comment assigned to array

I am looking forward to a big example file where one sees where everything gets assigned to (full meta key name like comment/#0/...). This file can also be used as test case.

@bauhaus93

This comment has been minimized.

Copy link
Author

@bauhaus93 bauhaus93 commented Nov 30, 2019

Thanks for the solution!
Yeah, I will focus on getting the plugin ready first, and will keep this solution in mind for later implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.