-
Notifications
You must be signed in to change notification settings - Fork 0
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 emitter support for integer bases and block strings #10
Add emitter support for integer bases and block strings #10
Conversation
1. Add a `Meta` node type for emitter options which are not round-trip-able. 2. Support emitting nodes with different integer bases. 3. Support emitting nodes with different string formatting options. Signed-off-by: Chris Frantz <frantzcj@gmail.com>
This ports some of my formatter extensions on top of your comment support. As I mentioned in dtolnay/serde-yaml#234, I thought I should refactor my extensions to the yaml-rust library a bit. I don't have a use case for round-tripping these things through the library as you do for comments, so I didn't bother to try to make the parser preserve this information. The |
Hey @cfrantz , thanks for the PR. I'll try to merge stuff on Sunday when I come back. On another note... I was checking |
I investigated extending serde-yaml quite a bit when I implemented my first attempt in dtolnay/serde-yaml#234. My conclusion was that I had to create a new trait to express what I wanted to do and then implement that trait on every For comments, I had implemented three options:
This would yield the following output when serialized:
In order for the serializer in serde-yaml to know that it can call members of my trait, I need either:
The former is not in stable yet, so I had to opt for the latter. The biggest problem I had was that Assuming my "type-of" does run afoul of the optimizer, the way attaching comments during serialization works is to have the proc-macro derive I'd planned on reworking my serde-yaml PR to use your fork for yaml-rust. There may be a few more mods I want to make to yaml-rust. One that comes to mind is an I'll send you an update for 128-bit support and when I refactor my fork of serde-yaml onto your fork. |
Yeah, I was trying I've merged the two outstanding PRs. Now that I know you are working on the fork, let's work on master. For the moment comment support is only available when I was thinking also of adding some configurations on the emitter to support human-friendly outputs... for example, adding a line break between top-level nodes or something like that, so you can easily navigate by paragraph. |
Yes, currently my changes apply only to Serialization. I'm curious about your use case for preserving comments on deserialzation. Are you writing a formatter, or do you have some other case, such as meta-information being conveyed in comments? |
Now that you ask me this question... You're making me wonder if it's really worth it. Let's say you have a tool that manipulates a configuration file. The user may annotate with a comment a section, for other people reading the file. If you were to run the tool such that it has to write the config again, you will lose these comments (eg https://github.com/alevinval/vendor/blob/master/example/.vendor.yml) To be honest... thinking well about this, it's a seriously complicated problem... just having a vec of entries that you keep sorted, if a new entry is added you'd need to re-sort the entries but also keep into account the comments. Maybe this is just a terrible idea after all. If you were to support such a case, then you'd probably be writing a custom converter from your struct to the |
Meta
node type for emitter options which are notround-trip-able.
Signed-off-by: Chris Frantz frantzcj@gmail.com