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

Provide a mode that produce *all* possible parse trees for ambiguous grammars #3219

Open
yanok opened this issue Mar 26, 2024 · 3 comments
Open
Labels
enhancement Feature request

Comments

@yanok
Copy link

yanok commented Mar 26, 2024

Problem

Tree-sitter generates GLR parsers, that can parse truly ambiguous languages. Yet, at the moment, I think tree-sitter uses some heuristics to pick a single parse tree. I totally understand that for most practical applications that's what people usually want, but would it be possible to provide an extra API that would return all possible parse trees? Or, at least, return a flag indicating that the returned tree is not the only possible one?

Expected behavior

No response

@yanok yanok added the enhancement Feature request label Mar 26, 2024
@WarpspeedSCP
Copy link

I'm just passing by here, but this could very easily result in a combinatorial explosion of possible parse trees depending on size and ambiguity.

@yanok
Copy link
Author

yanok commented Apr 11, 2024

Sure, if a grammar is wildly ambiguous, there is a chance of combinatorial explosion. Even though I don't think that's going to be an issue in practice, but yeah, then maybe just returning a flag indicating "we had to guess, another parse trees are possible" would be better performance wise.

@ObserverOfTime
Copy link
Member

Printing a warning when running tree-sitter generate (or tree-sitter parse?) might be the best option.

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

No branches or pull requests

3 participants