-
Notifications
You must be signed in to change notification settings - Fork 6
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
Status of Single-line and Multiline Comments #19
Comments
Yes, of cause I also want to support over-line, "island" and multi-line comments. The main difficulty I meet, is that there seems no good way to describe which does a comment belong to (while parsing or stringifying). The commens could be too whimsical. Think about this: # overall
# a
# a.a
a.a = 1
# a.b
a.b.x = 1
a.b.y = 1
#a.b.z = 1 How would you treat that? If we just remain the comments, without correct belonging relationship which most likely meeting the writer's intention, then it rarely help, and will break the compatibility when we finally find a good enough rule in the future. I'm glad to discuss any possible idea, welcome to feedback. |
Yeah, totally understood. The island comments seem to be the hardest to handle here, but I think that you could create a few rules which would capture most situations. For example, today you only capture inline comments, and drop the rest. You could also enable a feature where single / multi-line comments are attached to the nearest TOML line below it, and the rest would be dropped just as before. So using your example above, we would get:
At least in this case, we capture what is arguably the most common kind of comment in the way that is most normally expected. Here we still drop the island comment, and the tricky comment at the end of the file, but this would be a large step forward from what is available today. And, at the end, I believe more rules like this could be configurable as xOptions, allowing the user to play with the rules for their desired behavior. |
I think I need to confirm your final need about comment. Firstly, Here are two main cases to stringify a TOML document with comments: 1) a table parsed from existing file (which means you only want to change some value, and want to remain the comments without changes); 2) a brand new table with new structure, or change existing comments info. If only 1st case is usually needed, then the mechanisms can be in black box; if both, then here must be a good enough api, and I need to design it systematically. |
# overall
# a
# a.a
a.a = 1
# a.b
a.b.x = 1
a.b.y = 1
#a.b.z = 1
Does this look good enough? (Won't distinguish over-line comment and "island" comment, which can be designed, but I found it's easy to see mixing up in your samples.) |
@LongTengDao first, thank you for your time to discuss this with me. I think this might work. As I understand this syntax, you are keeping track of the comments and where they are relative to certain keys. In this case Ultimately, I would need to test this logic on some of the files by doing |
I have read in the documentation that that parsing and handling comments is one of the "sore points".
Specifically, it seems your library only parses and allows for inline comments, whereas it is pretty regular to see TOML files with comments over the lines they are modifying, or even multiline comments which act as separators between sections of TOML configuration.
Examples of comments over the lines can be found in the TOML specification: https://toml.io/en/
And a basic Rust toml file uses an "island" comment:
In our project Substrate, we take advantage of multiline comments in
toml
like this:What are the current limitations around parsing and handling these TOML comments? Is this something that this library could support in the future?
If you have an idea how you would like it implemented, could you write some notes so maybe I (or others) could try a stab at it?
Thanks!
The text was updated successfully, but these errors were encountered: