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

How to do backtracking? #178

Open
RGBCube opened this issue Dec 2, 2024 · 1 comment
Open

How to do backtracking? #178

RGBCube opened this issue Dec 2, 2024 · 1 comment

Comments

@RGBCube
Copy link

RGBCube commented Dec 2, 2024

Is there a recommended / working way of using Rowan to parse a grammar that requires a ton of backtracking? For my use case, forward-parsing and wrapping using checkpoints becomes incredibly hard to understand and convolutes my code up a lot.

Is there a way to "revert" the builder? A simple way to rollback would solve a lot of my problems, even if it is a little less efficient.

@szmarczak
Copy link

In my parser from scratch (based on rust-analyzer's design), instead of building the tree and then discarding it, I have another function that just "parses" without pushing to the tree, only advances are performed. It does not parse the entire syntax, but only up to the point where the ambiguity is resolved. Then, the parser position is reverted and an appropriate function is called to parse disambiguated syntax. This way modifying the tree is avoided, which in theory should be faster. However, this results in (almost) duplicate code. Best ambiguity is no ambiguity. Unfortunately, the amount of available ASCII bracket characters is too limiting in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants