Skip to content
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

Preserving comments, etc. with round trip decode/encode. #111

Closed
scott-fleischman opened this issue Jun 24, 2017 · 8 comments
Closed

Preserving comments, etc. with round trip decode/encode. #111

scott-fleischman opened this issue Jun 24, 2017 · 8 comments

Comments

@scott-fleischman
Copy link

A few times now I have wanted to preserve comments, whitespace and formatting when doing a round trip, something like: encode . transform . decode.

The use case is a tool that updates some information in configuration files. It is common that configuration files have comments and formatting which help the human readability of the document. It is disappointing to do an update which strips comments and changes formatting and whitespace.

Would you be willing to support such a feature in this language (preservation of "trivia" such as comments and whitespace)? If so, how would you recommend going about this? I would be willing to contribute if there is a reasonable chance of it getting merged in.

It looks like https://hackage.haskell.org/package/yaml-0.8.23.1/docs/Text-Libyaml.html provides a good starting point for this kind of addition.

Thanks for your consideration!

@snoyberg
Copy link
Owner

I'm open to it, but highly doubt it can be done without massive amounts of work. We're using a C library under the surface to parse the yaml itself, and IIRC it does not support comments at all.

@xtianjohns
Copy link

Hey @snoyberg, when you talk about massive amounts of work, are you talking about an implementation in this package that supports comment preservation without a corresponding feature set in libyaml? Or are you addressing the work that would be required in libyaml to support comments? Both?

There is yaml/libyaml#42 for addressing comment preservation in C - if a feature could be delivered, would you gauge the work required to deliver the additional comment feature set in this package as "massive"?

Frankly, I'm new to Haskell but stumbled upon this from commercialhaskell/stack#1933 (which if closed would provide for a nifty feature when installing new dependencies in Stack). While this lack of a capability doesn't seem to be a major problem for consumers of this module, it does seem like implementing it would be useful!

I'd love to help! If we can close out yaml/libyaml#42, would you be open to PRs and perhaps some guidance on the corresponding updates here?

@snoyberg
Copy link
Owner

snoyberg commented Mar 8, 2018

It's mostly work in libyaml. If the upstream library gets support for comments, it's significantly simpler to do that here. However, the current primary API (based on the aeson API) provides no method for dealing with comments, so we'd have to provide an alternative API. The underlying conduit-based API in Text.Libyaml should be much more easily extended.

CCing @NorfairKing, who may be mentoring a GSoC project related to this.

@NorfairKing
Copy link

@xtianjohns and @scott-fleischman There is a GSoC project about this: https://summer.haskell.org/ideas.html#format-preserving-yaml

If you can wait a summer, I'm quite certain this thing will exist by the end of the year.

@snoyberg
Copy link
Owner

snoyberg commented Jul 9, 2018

Closing this as currently out-of-scope for the yaml package, and deferring to the GSoC project instead.

@snoyberg snoyberg closed this as completed Jul 9, 2018
@scott-fleischman
Copy link
Author

Was anything from GSoC merged into this project relating to this issue?

@snoyberg
Copy link
Owner

snoyberg commented Oct 2, 2018

The plan was always to put any GSoC code into its own project. That project was creating a new parser, separate from the C parser used by this library.

@NorfairKing
Copy link

The GSoC project failed, by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants