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

Using gomme for round-trip parsing of YAML? #1

Open
marco-m opened this issue Sep 5, 2022 · 2 comments
Open

Using gomme for round-trip parsing of YAML? #1

marco-m opened this issue Sep 5, 2022 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@marco-m
Copy link

marco-m commented Sep 5, 2022

Hello,

I have two questions:

  • Is gomme suited to parse indentation-based non context-free languages like YAML ?
  • The round-trip refers to the fact that I would like to keep full layout information in the AST, so that if I change a node or a comment or whitespace, the resulting diff is minimal. The use case would be to present the diff to a human being, who wants to keep the file "hand formatted".

thanks!

@oleiade oleiade self-assigned this Sep 5, 2022
@oleiade oleiade added the question Further information is requested label Sep 5, 2022
@oleiade
Copy link
Owner

oleiade commented Sep 5, 2022

Hi @marco-m 👋🏻

I believe you should be able to build a YAML parser with Gomme indeed. Parser combinators are generally suited to build parsers for almost any format I can think of (but I'm sure there are exceptions). But I offer no guarantees on that front, not having built one myself for this specific format yet. If you go ahead and attempt building one, I'd be really eager to get your feedback and input 🤝

In general, I don't see on top of my head why indentation would be an issue, and you can perfectly fit your matches into an AST, by using the Assign and Map combinators.

With a few caveats though:

  • Gomme is not fully finished yet. Although you can perfectly build pretty thorough parsers with it already, we haven't reached a major version yet, and some combinators might be missing still, some others might change, and although I want the API to remain somewhat stable, there will be changes in the future.
  • The error management is not yet as good as I would want it to be. I'm actively working on it, but this might take a bit of time to get right, so that parsers can specifically pin-point where in the input, and why, a failure happen.

I'm currently working on the next minor version of Gomme which will include more examples, with a JSON parser example, for instance, you might find out useful. If that's okay with you, I'll ping you when it's out 👍🏻

🙇🏻

@marco-m
Copy link
Author

marco-m commented Sep 5, 2022

hello @oleiade,
thanks for the quick and complete answer :-)
I understand that gomme is still being developed. A JSON parser would be a very good example indeed.
Another idea is to port some of the examples from participle, that would also allow to compare approaches. I wrote a round-trip INI file parser/writer with participle, and I think that will be my first comparison.

If that's okay with you, I'll ping you when it's out

Yes, please! Merci encore!

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

No branches or pull requests

2 participants