simonpoole / OpeningHoursParser

Parser for string values according to the OSM opening hours specification
MIT License
32 stars 12 forks source link

Restart parsing on errors for better reporting #53

Closed simonpoole closed 3 years ago

simonpoole commented 3 years ago

This adds reporting for multiple parse errors in a backwards compatible fashion.

simonpoole commented 3 years ago

@simon04 @westnordost https://oss.jfrog.org/artifactory/webapp/#/builds/OpeningHoursParser/1607284995146/1607284995133 has a build of this if you want to test it.

The API remains backwards compatible, but OpeningHoursParseException has an additional method getExceptions() that will return a list of OpeningHoursParseException corresponding to the errors that were detected (it will always contain at least one exception).

This is by far not perfect, in particular I continue to suppress TokenManagerErrors by generating an UNEXPECTED_CHAR token that will cause a ParseException instead, which imho leads to a bit a confusing message as the error will be reported at the start of the token containing an invalid char. I've prototyped a version that does this differently (and returns better error messages) however that depends on an undocumented API so I'm not doing anything with that right now. The other issue is that the restarting isn't particularly fine grained but it seems to work reasonably well as is.