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

comment-preserving parser/generator? #284

Closed
tve opened this Issue Jan 8, 2015 · 8 comments

Comments

Projects
None yet
7 participants
@tve
Copy link

tve commented Jan 8, 2015

Has anyone written a comment-preserving parser/generator? The reason I'm asking is that I like config files, but I also like to be able to machine-edit them, for example through a web interface. Using the plain parser/generator one looses all comments in the config file.

@mojombo

This comment has been minimized.

Copy link
Member

mojombo commented Jan 15, 2015

I'm not aware of any, but that would be a great addition to a TOML parser.

@mojombo

This comment has been minimized.

Copy link
Member

mojombo commented Jan 16, 2015

I don't think you're going to get an answer here. Have you tried asking on Twitter or browsing through the list of parsers? Gonna close for now.

@mojombo mojombo closed this Jan 16, 2015

@kawing-chiu

This comment has been minimized.

Copy link

kawing-chiu commented Sep 6, 2017

I think this feature should really go into the toml spec...

@TheElectronWill

This comment has been minimized.

Copy link
Contributor

TheElectronWill commented Sep 6, 2017

@tve @kawing-chiu If it helps, I've written one in java that preserve most comments (not 100%, e.g. comments in arrays are not preserved for now). It's part of the Night-Config library.

@tshepang

This comment has been minimized.

Copy link

tshepang commented Sep 6, 2017

tomllib (written in Rust) preserves comments I believe

@shadow-light

This comment has been minimized.

Copy link

shadow-light commented Aug 19, 2018

Python tomlkit preserves comments. In fact that is why I was going to change all of my projects to TOML! Since learning it isn't actually in the spec I'm not so sure now. Putting this in the spec would give a huge advantage in my opinion over other config languages.

@ChristianSi

This comment has been minimized.

Copy link

ChristianSi commented Aug 20, 2018

@shadow-light Why should something like that be in the spec? Parsers/writers can implement things like preserving comments and order of elements, but most TOML apps will only read or write TOML files, not both, hence preserving syntactic sugar is irrelevant for them. If Python tomlkit preserves such details, that might be nice for some use cases (say a built-in editor for your TOML config), so by all means use it if it fits your needs.

Just remember that TOML tables are unordered so you cannot require your users to write keys in a specific order; and, since comments are ignored, you cannot rely on the absence or presence of specific comments. I think that's a good thing.

@shadow-light

This comment has been minimized.

Copy link

shadow-light commented Aug 21, 2018

Because comments are highly valuable sources of information to remember why certain values have been set. When you've written a lot of comments in a config file, it is very annoying to have them all wiped out because one of the values needed to be updated by a CLI for example.

It is sufficient for my use cases at least that the Python implementation does this. But putting it in the spec would guarantee it stays that way, and the feature doesn't get removed, or one can switch to another language implementation and not worry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment