Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

TOML: Trailing Comments in Arrays #3297

Closed
bauhaus93 opened this issue Nov 28, 2019 · 9 comments
Closed

TOML: Trailing Comments in Arrays #3297

bauhaus93 opened this issue Nov 28, 2019 · 9 comments

Comments

@bauhaus93
Copy link
Contributor

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".

@markus2330
Copy link
Contributor

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
Copy link
Contributor Author

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

@stale
Copy link

stale bot commented Nov 29, 2020

I mark this issue stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping the issue by writing a message here or create a new issue with the remainder of this issue.
Thank you for your contributions 💖

@stale stale bot added the stale label Nov 29, 2020
@stale
Copy link

stale bot commented Dec 13, 2020

I closed this issue now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue.
Thank you for your contributions 💖

@stale stale bot closed this as completed Dec 13, 2020
@markus2330
Copy link
Contributor

Currently we lose the comment of the example above:

 # Comment assigned to array
 array = [    # Comment assigned to element 0
-    0,       # Inline 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?
+1        # Inline comment assigned to element 1
 ]            # Inline comment assigned to array

@markus2330 markus2330 reopened this Jul 20, 2021
@stale stale bot removed the stale label Jul 20, 2021
@stale
Copy link

stale bot commented Jul 30, 2022

I mark this issue stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping the issue by writing a message here or create a new issue with the remainder of this issue.
Thank you for your contributions 💖

@stale stale bot added the stale label Jul 30, 2022
@stale
Copy link

stale bot commented Sep 21, 2022

I closed this issue now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue.
Thank you for your contributions 💖

@stale stale bot closed this as completed Sep 21, 2022
@kodebach kodebach reopened this Sep 21, 2022
@stale stale bot removed the stale label Sep 21, 2022
@github-actions
Copy link

I mark this stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping by writing a message here or create a new issue with the remainder of this issue.
Thank you for your contributions 💖

@github-actions github-actions bot added the stale label Sep 22, 2023
Copy link

github-actions bot commented Feb 4, 2024

I closed this now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue.
Thank you for your contributions 💖

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants