Once the parser finishes parsing some ambiguity, it would be really nice to expose this ambiguity to the user, rather than just multiplying the output by this ambiguity size.
For example disambiguate :: ([a] -> b) -> Prod a -> Prod b or more generally ([a] -> [b]) -> Prod a -> Prod b.
I had a look at naively changing some things in parse and following the types but was unable to get this to work without better understanding the algorithm.
OK, after taking some time to actually understand what's going on I think I've got this working for nonterminals at least, and think I see a way to get it working for terminals also.
Once the parser finishes parsing some ambiguity, it would be really nice to expose this ambiguity to the user, rather than just multiplying the output by this ambiguity size.
For example
disambiguate :: ([a] -> b) -> Prod a -> Prod b
or more generally([a] -> [b]) -> Prod a -> Prod b
.I had a look at naively changing some things in
parse
and following the types but was unable to get this to work without better understanding the algorithm.The discussion here makes it seem as though this is actually non-trivial! https://github.com/ollef/Earley/issues/18
Perhaps some important reading: https://dinhe.net/~aredridel/.notmine/PDFs/Parsing/SCOTT%2C%20Elizabeth%20-%20SPPF-Style%20Parsing%20From%20Earley%20Recognizers.pdf