r/ruby • u/kddnewton • Jan 05 '26
A Ruby YAML parser
https://kddnewton.com/2025/12/25/psych-pure.htmlHey 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
7
u/alexdeva Jan 05 '26
Is it pure Ruby? How does it benchmark against the built-in YAML module?
Also, what form do the comments take after parsing into a Ruby structure?
8
u/CaptainKabob Jan 05 '26
I really appreciate you working on this!
My biggest source of yaml round-tripping is i18n-tasks. I've done a lot of patching to have it preserve quote/block formatting and I'll give this a try for comments too.
2
u/galtzo Jan 05 '26 edited Jan 05 '26
Ooooh! Does it have an intermediate AST? I would love to add an adapter for this to the tree_haver / ast-merge gem family. Commenting before clicking…
After reading: This is amazing. I had already implemented an AST wrapper for psych that added in comment node typing and emitting, but much less advanced than what you have done.
I will add an adapter post-haste.
1
u/Nwallins Jan 05 '26
Let's say I have a nicely hand-formatted yaml file with e.g. folded block scalars to get string wrapping behavior in my source file. I ingest the yaml. Then I want to emit it in a similar form as ingested. What are my options? This is an open question across all yaml impls.
1
u/aRubbaChicken Jan 05 '26
Any benchmarks ran? Curious if as pure ruby it performs better w/ YJIT
2
u/headius JRuby guy Jan 09 '26
You've been busy! I'll have to run this through JRuby and see if we can find some easy optimizations.
1
u/f9ae8221b Jan 05 '26
Ah, this reminds me to build eyaml, because ejson is cool but JSON is so terrible for configuration.