Commit e6bec2ae authored by David Faure's avatar David Faure
Browse files

Extend the extended syntax for month day sets

2021 Dec 26-28,Dec 30-31 was being simplified to 2021 Dec 26-28,30-31
which then couldn't be parsed back. The unofficial grammar at
https://wiki.openstreetmap.org/wiki/Key:opening_hours
does support this:

    daily: months [   monthdays [ , monthdays ]... ]
    months: Mth [ -Mth ]
    monthdays: dd [ -dd ]
parent c77da889
......@@ -209,6 +209,11 @@ private Q_SLOTS:
T2("Mo, We, Fr 06:30-21:30; Tu, Th 09:00-21:30; Sa 09:00-17:00; Su 09:00-14:00", "Mo,We,Fr 06:30-21:30; Tu,Th 09:00-21:30; Sa 09:00-17:00; Su 09:00-14:00");
T2("Lunes a sábado, 9:30 AM-5:30 PM", "Mo-Sa 09:30-17:30"); // bug 445784
// lists of specific days
T("2021 Dec 26-28,30-31,2022 Jan 02-03 off");
T2("2021 Dec 26-28,Dec 30-31,2022 Jan 02-03 off", "2021 Dec 26-28,30-31,2022 Jan 02-03 off");
T2("2021 Dec 22, 26-28, 29, 31, 2022 Jan 02-03 off", "2021 Dec 22,26-28,29,31,2022 Jan 02-03 off");
// technically wrong but often found content in OSM for which we have error recovery
T2("So", "Su");
T2("Ph", "PH");
......
......@@ -43,7 +43,7 @@ static void applySelectors(const Selectors &sels, Rule *rule)
rule->m_wideRangeSelectorComment = QString::fromUtf8(sels.wideRangeSelectorComment.str, sels.wideRangeSelectorComment.len);
}
static bool extendMonthdaySelector(MonthdayRange *monthdaySelector, int day)
static bool extendMonthdaySelector(MonthdayRange *monthdaySelector, int beginDay, int endDay)
{
const auto prevSelector = lastSelector(monthdaySelector);
if (prevSelector->begin.year == prevSelector->end.year
......@@ -53,7 +53,8 @@ static bool extendMonthdaySelector(MonthdayRange *monthdaySelector, int day)
{
auto sel = new MonthdayRange;
sel->begin = sel->end = prevSelector->end;
sel->begin.day = sel->end.day = day;
sel->begin.day = beginDay;
sel->end.day = endDay;
appendSelector(prevSelector, sel);
return true;
}
......@@ -607,7 +608,7 @@ MonthdaySelector:
// month day sets, not covered the official grammar but in the
// description in https://wiki.openstreetmap.org/wiki/Key:opening_hours#Summary_syntax
$$ = $S;
if (!extendMonthdaySelector($$.monthdaySelector, $D)) {
if (!extendMonthdaySelector($$.monthdaySelector, $D, $D)) {
delete $$.monthdaySelector;
YYABORT;
}
......@@ -615,7 +616,23 @@ MonthdaySelector:
| MonthdaySelector[S] T_ADDITIONAL_RULE_SEPARATOR T_INTEGER[D] {
// same as the above, just with the wrong ", " separator
$$ = $S;
if (!extendMonthdaySelector($$.monthdaySelector, $D)) {
if (!extendMonthdaySelector($$.monthdaySelector, $D, $D)) {
delete $$.monthdaySelector;
YYABORT;
}
}
| MonthdaySelector[S] T_COMMA T_INTEGER[D1] T_MINUS T_INTEGER[D2] {
// same with a range of days
$$ = $S;
if (!extendMonthdaySelector($$.monthdaySelector, $D1, $D2)) {
delete $$.monthdaySelector;
YYABORT;
}
}
| MonthdaySelector[S] T_ADDITIONAL_RULE_SEPARATOR T_INTEGER[D1] T_MINUS T_INTEGER[D2] {
// same as the above, just with the wrong ", " separator
$$ = $S;
if (!extendMonthdaySelector($$.monthdaySelector, $D1, $D2)) {
delete $$.monthdaySelector;
YYABORT;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment