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

Consider alternative approaches to forced reduction #14

Closed
marijnh opened this issue Sep 24, 2021 · 1 comment
Closed

Consider alternative approaches to forced reduction #14

marijnh opened this issue Sep 24, 2021 · 1 comment

Comments

@marijnh
Copy link
Contributor

marijnh commented Sep 24, 2021

Storing a single reduction per state in the parser tables is problematic, because a given state might contain inconsistent rules and rule positions, and blindly reducing any of them may not be valid in a given parse that is in the state. Patch lezer-parser/lr@e931d93 adds a check to avoid corruptions from this, but it might still (in circumstances that are probably quite obscure) produce weirdly structure output trees.

A possible alternative strategy would involve scanning up the stack for a state that has goto entries, and then use one of those to create a reduction. But there is is also tricky to make sure the reduced term actually corresponds to what is being reduced (since the parse tables don't provide us with that information).

A more expensive approach would be to store a set of terms with each state, and use that to pick the right goto entry when scanning up the stack. But again, if applied in the simplest way that doesn't seem to provide 100% guarantee against picking a nonsense reduction, since states don't uniquely determine how they were reached (and might even refer to several positions in the same rule).

In any case this will likely involve a breaking change to the on-disk format, so let's look into it when considering a new breaking release.

@marijnh
Copy link
Contributor Author

marijnh commented Apr 23, 2024

The loop issue seems to be under control with the fixes to #13 , and potential alternative approaches have their own significant downsides, so I'm going to close this.

@marijnh marijnh closed this as completed Apr 23, 2024
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

1 participant