haskell-hvr / HsYAML

YAML 1.2 implementation in pure Haskell
https://hackage.haskell.org/package/HsYAML
GNU General Public License v2.0
55 stars 17 forks source link

Empty lines fail to round trip #48

Open TristanCacqueray opened 4 years ago

TristanCacqueray commented 4 years ago

It seems like empty lines do not have a corresponding Event:

a: 1

# comment
b: 2

Results in (after passing through yaml-test yaml2yaml):

a: 1
# comment
b : 2

Would it be possible to add a new event or comment attribute to preserve empty lines?

vijayphoenix commented 4 years ago

Yes, line spaces and extra indentation is not preserved in a round trip. See https://hackage.haskell.org/package/HsYAML-0.2.1.0/docs/Data-YAML-Event.html#g:4 for more details.

TristanCacqueray commented 4 years ago

My use-case is to edit/format YAML document while preserving the file structure, and loosing empty lines is not very practical. It doesn't seems like a very intrusive change to add EmptyLine event and I would be interested in contributing such a feature if that would be acceptable (and fit the scope of HsYAML).

I also noticed parseEvents returns a list of Event, Pos Record, but writeEvents only accept a list of Event. Is there a particular reason a writeEventsWithPos function isn't provided? And if such function is technically feasible, then that seems like a better solution to my use-case.

vijayphoenix commented 4 years ago

It would be nice to have such a feature. Any suggestions @hvr on how to proceed with this feature?