simonpoole / OpeningHoursParser

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

non-strict mode: Allow no space after months if there is a colon #50

Closed westnordost closed 3 years ago

westnordost commented 4 years ago

I noticed that these opening hours Oct-Mar:07:00-20:00; Apr:07:00-22:00; May-Sep:07:00-23:00 (node#3736714410) are not parseable by the parser.

I reckon that this is because there is no space after the colon of the month(s range(s)). Non-strict mode could allow to have no spaces after the months if there is no colon.

P.S: StreetComplete is now using this parser, works like a charm, thank you! I've written a (StreetComplete centric) test to see how much percent of opening hours strings are parseable, and how much of these are supported by StreetComplete. If you are interested, these are the results. 97.7% of all opening hours strings worldwide can be parsed by OpeningHoursParser (non-strict mode)

simonpoole commented 3 years ago

This is actually a bit tricky, the problem is that the choice is ambiguous (the parser doesn't actually require the space but it forces a different choice to be made). Probably needs some liberal use of semantic lookahead.

simonpoole commented 3 years ago

@westnordost see https://github.com/simonpoole/OpeningHoursParser/pull/54

westnordost commented 3 years ago

Nice!

Am 5. Januar 2021 12:00:11 MEZ schrieb Simon Poole notifications@github.com:

@westnordost see https://github.com/simonpoole/OpeningHoursParser/pull/54

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/simonpoole/OpeningHoursParser/issues/50#issuecomment-754565312

-- Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.

simonpoole commented 3 years ago

I reckon that this is because there is no space after the colon of the month(s range(s)). Non-strict mode could allow to have no spaces after the months if there is no colon.

The spec doesn't seem to require a space, not that it is anything to go by in that respect it is more or less random that is why I've in general just ignored them in the parser, however I could now enforce them if necessary with the changes in https://github.com/simonpoole/OpeningHoursParser/commit/083f7c8d35dec9c1fed63d3aa5e1b23c53c07398

westnordost commented 3 years ago

You mean enforce them in strict mode? Well, I guess if the spec doesn't require it, then the version without a space if there is a colon should also be parseable in strict mode.

But since it is/seems to be easier for parsers to always excpect a whitespace there, the OpeningHoursParser's canoncial version of the opening hours string should include that whitespace in any case.

simonpoole commented 3 years ago

Changed in https://github.com/simonpoole/OpeningHoursParser/pull/54