-
Notifications
You must be signed in to change notification settings - Fork 269
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
Add (optional) support for preserving and round-tripping comments. #121
Comments
Hi TkTech, thank you for your suggestion. I also wanted to preserve comments before but found it difficult to implement. Adding a new TYPE would not work, because comments are not structured data, and this would break the function of |
I agree with you for the general use case, so how about as a compile-time flag that is disabled by default? My example use case is a VSCode linter. In such a case I don't care about peak performance, but the flexibility and correctness of yyjson's parser and its support for _RAW types and comments. I believe it would still perform very well, in real time from the perspective of a slow human brain. |
Maybe I can try it out and see how it actually performs. |
If you don't have a preference for how this is done, I'm happy to take a stab at a proof-of-concept PR. |
Thanks. I would be happy to take a look. |
No rush mate, you don't owe anyone anything:) |
More or less summed up by the title :)
There are quite a few (very) popular projects like VSCode that store their configuration files in JSON with comments. yyjson can currently read these with no problem by enabling comments, but this simply strips them.
It would be ideal if these could (optionally) be stored and serialized to support round-tripping of these types of configuration files. It seems unreasonable to expect byte-perfect round tripping, since yyjson wasn't built for that and it would likely be too much work.
I see 2 options that appear reasonable, IMO:
comments
pointer toyyjson_mut_val
, which is simply a character blob that gets prepended when serializing thatyyjson_mut_val
(and so must include the "//" in front of each line in the string). Existing code wouldn't break, and code that doesn't care about comments could simply ignore it. When the parser encounters a comment, just start storing it up until the nextyyjson_val
is a found and then add it. As an edge case, if a comment occurs outside the documents root, it becomes a comment on the root node (even if it occurred after the root).YYJSON_TYPE_COMMENT
which is added to the document. This feels more difficult to get right. How would you add it to an object for example? It has no key.The text was updated successfully, but these errors were encountered: