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

pretty yaml serialisation preserving comments #5

Open
jayvdb opened this issue Sep 24, 2024 · 1 comment
Open

pretty yaml serialisation preserving comments #5

jayvdb opened this issue Sep 24, 2024 · 1 comment

Comments

@jayvdb
Copy link
Contributor

jayvdb commented Sep 24, 2024

As noted on readme and lib.rs, catalog add uses prettier for formatting of the yaml, and isnt comment preserving.

xbcsmith/ymlfxr#2 was my last foray into comment preserving yaml in Rust.

yaml-rust2 writes pretty yaml, but isnt comment preserving.

https://crates.io/crates/tree-sitter-yaml might be comment preserving.
c.f. https://github.com/tree-sitter-grammars/tree-sitter-yaml/blob/master/src/node-types.json#L483
But that adds a dependency on a C compiler, and is a lot more effort to read and write.

https://github.com/pantoniou/libfyaml is likely the best route, and rust wrappers are improving https://crates.io/search?q=libfyaml

@simonbuchan
Copy link
Owner

Oh boy. My earlier attempt at this got me sniped pretty hard!

I actually did get started with https://lib.rs/crates/yaml_parser which creates rowan concrete syntax trees, but editing those was incomprehensible to me due both to confusing rowan docs and the bizarre structure that it parses. Maybe there's more juice down that path, but the squeeze was no fun.

Inevitably, I thought "surely it's not that hard to write a yaml parser," and my fate was sealed. That said, I think I got it up to recognizing a decent chunk of the test suite with code gen from the grammar repo, but ran into similar lack of docs and it's annoyingly not in sync with the actual spec text, so then i saw it was generated from the spec markdown...

Ugh.

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

2 participants