To.ml icon indicating copy to clipboard operation
To.ml copied to clipboard

Comments

Open cljoly opened this issue 9 years ago • 9 comments

Could the library support comments parsing and setting?

We could for example attach string to keys, and this could write comments in the Toml file.

cljoly avatar Mar 07 '15 18:03 cljoly

Yes, support for comments attached to a key could be supported.

Comments which are not clearly identified as metada of a precise key are more tricky to handle, so I guess there will not be supported, but that is not what you asked for.

I do not have much time, but I might be able to look at it this week.

Or if you know what to do, feel free to submit a pull request :+1:

sagotch avatar Mar 08 '15 17:03 sagotch

I said key but it would actually be values with attached comments.

sagotch avatar Mar 08 '15 20:03 sagotch

While it is easy to add a comment to a value programmatically and easy to print. It is more difficult to parse.

Support for comments would be nice. But it seems that it is not likely to be implemented soon...

sagotch avatar Mar 10 '15 11:03 sagotch

Thanks for your quick answer!

I hope to have time to (try to) implement it someday...

cljoly avatar Mar 10 '15 18:03 cljoly

I actually might have something working (more or less) soon (https://github.com/mackwic/To.ml/tree/comments).

sagotch avatar Mar 12 '15 17:03 sagotch

Seems to me that the fact that To.ml doesn't try to keep the order of the original file the same would be a related problem. If you have comments before or after a key, you would like them to be there after rewriting the file as well.

eras avatar May 08 '15 13:05 eras

On Fri, May 8, 2015 at 3:03 PM, Erkki Seppälä [email protected] wrote:

Seems to me that the fact that To.ml doesn't try to keep the order of the original file the same would be a related problem. If you have comments before or after a key, you would like them to be there after rewriting the file as well.

It seems difficult to do in a robust way. I don't think I have met any config file format library which preserves comments...

Emm avatar May 08 '15 14:05 Emm

Well, the simplest way is to not just put the data into a map but instead search the list in linear fashion when a value needs to be found or put next to each other. The placement when adding new values is always a question, of course, but replacing old values should be simple as well as adding values next to a known value. Newlines at the end of each value might be their own object to uniformly handle the case of adding a comment at the end of the value or to the next line.

To be well-performing this would need some more sophisticated data format, though, most likely some indices to the linear list (ropes and maps?).

But, to be honest, I doubt there are very many big Toml-documents around :-).

eras avatar May 08 '15 19:05 eras

We would be able to handle a subset of well-attached comments, not all of them because you do not know if a comment is supposed to be part of the previous value, the next one, or none of them (like some comments about authors).

Saying that comments on the same line than key or value could be attached and others would be lost seems acceptable to me. Doing that, the order (or lake of) in which we record values would not be an issue (but this question is a different problem, and please feel free to open an issue about it if you think it is needed anyway).

So yes, I think newline is the key for comment handling.

sagotch avatar May 10 '15 23:05 sagotch