@TheConstructor @fasterthanlime this is a common use case for me, but in that case it’s a lot wider: it’s „keep all formatting intact, whitespace and indent and all, including comments”. Comments are just a part of keeping the meaningless formatting intact.
A parser/serializer that lets me make programmatic semantic changes to a file created and edited by humans without mangling it and generates a minimal text-level diff is *golden*.
@fasterthanlime for some good horror, checkout the "containerless bindings" that knockoutjs has: https://knockoutjs.com/documentation/if-binding.html
(And yes, that webpage is probably as old as you think it is)
@fasterthanlime Full format preserving on edits is non-trivial and should generally handled separately from other parsing.
If you are working with a serde-like API, then it is very complicated to carry forward all formatting. This is especially true for formats with more flexible styling like yaml and toml. For example in toml, you have 3 different ways to define tables and sort order is a cross-table concern.
Whether you do serde-like or work with a Value that has the logical structure, there is a major performance impact to carry forward formatting. In a serde-like API, it is also quite invasive on your types.
@fasterthanlime I'm late, didn't vote, but here's my use case in favor of them.
I run a game server hosting site (full stack Rust) where users edit game config files in a nice web gui or edit the files directly. Games often have comments in their default config files to explain what the values do. If editing from the GUI strips those, then it makes editing the file a lot more confusing for users (e.g. when they need to edit a field we haven't added to the gui yet).
@fasterthanlime For our use case I probably would prefer if it kept all formatting and ordering. Sometimes the grouping of settings helps with context etc., but I probably wouldn't bother writing my own parser if there was an existing one that kept comments and lost some formatting.
So yeah, kind of middle ground, but would still get some value out of full preservation too.