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

Report doesn't include enough information #57

Open chowells79 opened 2 years ago

chowells79 commented 2 years ago

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.

expipiplus1 commented 1 year ago

You could check the position field of your Report, or check the unconsumed field for emptiness.

chowells79 commented 1 year ago

@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.