ollef / Earley

Parsing all context-free grammars using Earley's algorithm in Haskell.
BSD 3-Clause "New" or "Revised" License
361 stars 24 forks source link

Is there any possible optimization for getting non-exhaustive outputs for ambiguous grammars #59

Open expipiplus1 opened 1 year ago

expipiplus1 commented 1 year ago

I'm parsing an ambiguous grammar and I'd like to distinguish the following cases (more quickly than dealing with a list of all results):

The use case is being able to tell the user: "Hey, you gave me ambiguous input, here are some places to check for ambiguity". Giving them 20000 results isn't helpful, especially as any large number is bound to be the result of some combinatorial explosion, and solving one ambiguity makes good progress.

I had a quick go at modifying fullParses in a few ways to prompt an earlier return but there wasn't a quick "no-understanding" fix.

expipiplus1 commented 1 year ago

I think that the disambiguation work would be a good solution here. It's not an exact fix, but it solves the combinatorial explosion, and one could even make their expression type something like Unique Expr | Plural Int