Earley
Earley copied to clipboard
Report doesn't include enough information
I was working on AoC problem (https://adventofcode.com/2021/day/10) recently and saw that recognizing whether an input matches a grammar was part of it. (I ended up going a different direction to solve it, but...)
Since I thought I only needed to identify whether something parsed or not, I wanted to use report to test acceptance without bothering with parse results. But.. that actually isn't sufficient. At least, not unless you add names to the productions, and in sufficient granularity. If you have skipped that portion for your grammar, the Report value doesn't give sufficient information to determine whether something parsed in its entirety - only whether it ran into an error or was able to consume the entire input without errors. The only way to determine if any parse ran to completion is checking whether fullParses returned any parses.
It would be really nice if report returned some way to determine whether there was a full parse without requiring sufficiently granular naming of productions.
You could check the position field of your Report, or check the unconsumed field for emptiness.
@expipiplus1 That covers the case when there was input that was unexpected. It does not cover the case of not enough input. I should know, it's exactly what I tried to do. It doesn't handle the situation.