kach / nearley

📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
https://nearley.js.org
MIT License
3.59k stars 232 forks source link

Collect all matched parsings for ambiguous sub-grammar? #584

Closed KillyMXI closed 3 years ago

KillyMXI commented 3 years ago

Let's say I have an ambiguous expression that can be parsed in two or more different ways. Client code will know which one to choose, but I can't include that knowledge into the grammar itself. Is there a way to get an array of all matches rather that the first match?

UPD: As a workaround, I can probably return ambiguous part as a raw string and provide options to parse it in different ways as a separate step.

KillyMXI commented 3 years ago

That's kind of how it works already, albeit on a different level. I was thinking in a frame of particular sub-grammar while it returns all valid interpretations for the whole thing. Diffing the result objects to find ambiguous fragments doesn't seem practical.

I've since abandoned the idea that lead to this request.