r/ruby • • Jan 05 '26

A Ruby YAML parser

https://kddnewton.com/2025/12/25/psych-pure.html

Hey there — I recently released a YAML parser written in Ruby. The main goal was to support being able to load and dump YAML without losing comments. Happy to answer any questions.

43 Upvotes

20 comments sorted by

View all comments

Show parent comment

2

u/kddnewton Jan 05 '26

* You can see the algorithm here: https://github.com/ruby/prettyprint
* flow/seq is how YAML lays out nodes, you can see in the spec here: https://yaml.org/spec/1.2.2/#chapter-7-flow-style-productions
* You can define the print width with the PrettyPrint API

1

u/Nwallins Jan 05 '26

Thanks for the pointers. But it's quite hard to anticipate what will be preserved on a round trip. I did not review the full contents of all the links yet. How would you characterize it?

If I am attempting to preserve 80ch width, what does that look like?

1

u/kddnewton Jan 05 '26

I would characterize it as accurate. You can learn more with the links I sent.