/** * Parser for OpenStreetMap opening_hours values * See exceptions = new ArrayList < ParseException > (); /** * Get the output of the parser * * @param strict if true the parser will run in strict mode * @return a List of Rule elements * @throws OpeningHoursParseException on parse errors */ public List < Rule > rules(boolean strict) throws OpeningHoursParseException { return rules(strict, true); } /** * Get the output of the parser * * @param strict if true the parser will run in strict mode * @param strictTime if false and strict is true, earlier than the start time endings will be fixed up silently * @return a List of Rule elements * @throws OpeningHoursParseException on parse errors */ public List < Rule > rules(boolean strict, boolean strictTime) throws OpeningHoursParseException { try { List < Rule > r = rules0(strict, strictTime); if (exceptions.size() > 1) { throw new OpeningHoursParseException(exceptions); } else if (exceptions.size() == 1) { ParseException t = exceptions.get(0); if (t instanceof OpeningHoursParseException) { throw (OpeningHoursParseException) t; } throw new OpeningHoursParseException(t); } return r; } catch (ParseException pex) { // signature requires this throw (OpeningHoursParseException) pex; } } } PARSER_END(OpeningHoursParser) JAVACODE void error_skip(ParseException e) { exceptions.add(e); Token t; do { t = getNextToken(); } while (t.kind != SEMICOLON && t.kind != COMMA && t.kind != FALLBACKSEPERATOR && t.kind != WS && t.kind != HYPHEN && t.kind != EOF); } JAVACODE boolean precedingWs(Token t) { return t.specialToken != null && t.specialToken.kind == WS; } SPECIAL_TOKEN : { < WS : ["\r", "\n", " ", "\t", "\u200A", "\u2009", "\u00A0", "\u2008", "\u2002", "\u2007", "\u3000", "\u2003", "\u2006", "\u2005", "\u2004"] > } TOKEN : { < COMMA : "," > | < SEMICOLON : ";" > | < COLON : ":" > | < PLUS : "+" > | < HYPHEN : [ "-", "\u2013", "\u2014" ] > | < SLASH : "/" > | < STOP : "." > | < H : "h" > | < BRACKET_LEFT : "[" > | < BRACKET_RIGHT : "]" > } TOKEN : { < QUOTE : "\"" > : COMMENT_STATE } < COMMENT_STATE > TOKEN : { < ENDQUOTE : < QUOTE >> : DEFAULT | < CHAR : ~[ "\"", "\\" ] > } // parse all numbers as number and do the range checking in syntactic lookahead TOKEN : { < NUMBER : (< DIGIT >)+ > } TOKEN : { < DIGIT : [ "0"-"9" ] > } TOKEN : { < FALLBACKSEPERATOR : "||" > } TOKEN : { < ALWAYS : "24/7" > } TOKEN : { < DAYS : "day" ("s")? > | < WEEK : "week" > } TOKEN : { < WEEKDAY : "Mo" | "Tu" | "We" | "Th" | "Fr" | "Sa" | "Su" > { matchedToken.image = Util.capitalize(image.toString()); } | < WEEKDAY3 : "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat" | "Sun" > { matchedToken.image = Util.capitalize(image.toString()).substring(0, 2); } | < WEEKDAYDE : "Mo" | "Di" | "Mi" | "Do" | "Fr" | "Sa" | "So" > { matchedToken.image = Util.deWeekDays2En(image.toString()); } | < MONTH : "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec" > { matchedToken.image = Util.capitalize(image.toString()); } | < HOLIDAYS : "SH" | "PH" > { matchedToken.image = image.toString().toUpperCase(Locale.US); } | < EVENTS : "sunrise" | "sunset" | "dawn" | "dusk" > { matchedToken.image = image.toString().toLowerCase(Locale.US); } | < VARDATE : "easter" > { matchedToken.image = image.toString().toLowerCase(Locale.US); } } TOKEN : { < MODIFIER : "open" | "closed" | "off" | "unknown" > { matchedToken.image = image.toString().toLowerCase(Locale.US); } } TOKEN : { < AM : "am" | ("a"< STOP >"m"(< STOP >)?) > | < PM : "pm" | ("p"< STOP >"m"(< STOP >)?) > } TOKEN : { < TO : " to " | " a " | " \u00E0 " | " \u0434\u043E " | " bis " > } /** * match a number between 1 and 5 */ Token one2five() : { Token n = null; } { LOOKAHEAD({ getToken(1).kind == NUMBER && Util.between(getToken(1).image, 1, 5) }) n = < NUMBER > { return n; } } /** * match a positive number larger than 1 */ Token number() : { Token n = null; } { LOOKAHEAD({ getToken(1).kind == NUMBER && Util.equalsOrMore(getToken(1).image, 1) }) n = < NUMBER > { return n; } } /** * Match a comment. */ String comment() : { StringBuilder builder = new StringBuilder(); } { < QUOTE > ( getChar(builder) )* < ENDQUOTE > { return builder.toString(); } } /** * Match char inside quoted string. */ void getChar(StringBuilder builder) : { Token t; } { (t = < CHAR >) { if (t.image.length() < 2) { // CHAR builder.append(t.image.charAt(0)); } } } /** * returns a number Token if between 0 and 24 * uses semantic lookahead */ Token hours() : { Token h = null; } { LOOKAHEAD({ getToken(1).kind == NUMBER && Util.between(getToken(1).image, 0, 24) }) h = < NUMBER > { return h; } } /** * returns a number Token if between 0 and 59 and starts with a suitable delimiter * uses semantic lookahead */ Token minutes() : { Token delimiter = null; Token m = null; } { ( ( (delimiter = < COLON > ) | (delimiter = < STOP > ) | (delimiter= < H >) ) LOOKAHEAD({ getToken(1).kind == NUMBER && Util.between(getToken(1).image, 0, 59) && (getToken(1).image.length() >= 2 || "0".equals(getToken(1).image))}) m = < NUMBER > ) { if (strict && (m.image.length() != 2 || delimiter.kind != COLON || precedingWs(m) || precedingWs(delimiter))) { ParseException pex = new OpeningHoursParseException(tr("invalid_minutes"), token.next); pex.currentToken = token; throw pex; } return m; } } /** * returns the total number of minutes for a time of the form hh:00 or just hh * * AM/PM handling, see http://www.npl.co.uk/reference/faqs/is-midnight-12-am-or-12-pm-faq-time for why this is a mess * 12:01pm to 12:59pm is 12:01 to 12:59 * 13:00pm and later is considered to be mistyped and in the 24:00 system * 12:00 pm is 12:00 * 12:01am to 12:59am is 00:01 to 00:59 * 12:00am is 00:00 * 13:00am and later is considered to be mistyped and in the 24:00 system */ int time() : { Token h = null; Token m = null; int result = 0; AMPM ampm = null; } { ( h = hours() ) ( LOOKAHEAD(minutes(), { h!=null }) m = minutes() )? ( ampm = ampm() )? { if (strict && m == null) { ParseException pex = new OpeningHoursParseException(tr("hours_without_minutes")); pex.currentToken = token; throw pex; } if (m != null) { result = Integer.parseInt(m.image); } result = result + Integer.parseInt(h.image) * 60; if (ampm == AMPM.PM && result < TWELVEHOURS) { // only use add 12h if the time is less than 12 h result = result + TWELVEHOURS; // 12:01 pm to 12:59 pm are already correct 24h times } else if (ampm == AMPM.AM && result >= TWELVEHOURS && result < TWELVEHOURS + 60) { result = result - TWELVEHOURS; // 12:00am to 12:59am are clearly early morning } return result; } } AMPM ampm() : { String result = null; Token ampm = null; } { ( ( ampm =< AM > ) | ( ampm =< PM > ) ) { if (ampm != null) { if (strict) { ParseException pex = new OpeningHoursParseException(tr("found", ampm.image), token.next); pex.currentToken = token; throw pex; } return ampm.kind == AM ? AMPM.AM : AMPM.PM; } return null; } } /** * returns the total number of minutes for a time of the form hh:00 or just hh with hh up to 48 */ int extendedtime() : { Token h = null; Token m = null; int result = 0; AMPM ampm = null; } { ( LOOKAHEAD({ getToken(1).kind == NUMBER && Util.between(getToken(1).image, 0, 48) }) h = < NUMBER > ) ( LOOKAHEAD(minutes(), { h!=null }) m = minutes() )? ( ampm = ampm() )? { if (strict && m == null) { ParseException pex = new OpeningHoursParseException(tr("hours_without_minutes")); pex.currentToken = token; throw pex; } if (m != null) { result = Integer.parseInt(m.image); } result = result + Integer.parseInt(h.image) * 60; if (ampm == AMPM.PM && result < TWELVEHOURS) { result = result + TWELVEHOURS; } else if (ampm == AMPM.AM && result >= TWELVEHOURS && result < TWELVEHOURS + 60) { result = result - TWELVEHOURS; } return result; } } VariableTime variabletime() : { Token event = null; Token sign = null; int offset = 0; VariableTime vt = new VariableTime(); } { (event = < EVENTS > { vt.setEvent(event.image); return vt; } ) | ( "(" event = < EVENTS > ( sign = < PLUS > | sign = < HYPHEN > ) offset = time() ")" { vt.setEvent(event.image); vt.offset = (sign.image.equals("-") ? - 1 : 1) * offset; } ) { return vt; } } int interval() : { Token number = null; Token hours = null; int interval = 0; } { < SLASH > ( LOOKAHEAD(hours() minutes()) ( hours = hours() number = minutes() { interval = Integer.parseInt(hours.image) * 60 + Integer.parseInt(number.image); } ) | ( ( number = number() ) { interval = Integer.parseInt(number.image); } ) ) { return interval; } } TimeSpan timespan() : { int start = 0; int end =-1; Token startplus = null; Token endplus = null; Token to = null; VariableTime startVT = null; VariableTime endVT = null; TimeSpan ts = new TimeSpan(); int inter = 0; } { ( ( start = time() { ts.start = start; } | startVT = variabletime() { ts.startEvent = startVT; } ) ( startplus = < PLUS > | ( ( < HYPHEN > | (to = < TO >) ) ( end = extendedtime() { if (end < start) { if (!strict || !strictTime) { // non-strict, add 24h end = end + 24*60; } else { ParseException pex = new OpeningHoursParseException(tr("earlier_than_time"), token.next); pex.currentToken = token; throw pex; } } ts.end = end; } | endVT = variabletime() { ts.endEvent = endVT; } ) { if (strict && to != null) { throw new OpeningHoursParseException(tr("to_instead_of_dash"), token.next); } } ( endplus = < PLUS > | ( inter = interval() { ts.interval = inter; } ) )? ) )? { ts.openEnded = startplus != null || endplus != null; return ts; } ) } List < TimeSpan > time_selector() : { TimeSpan ts, ts1; List < TimeSpan > result = new ArrayList < TimeSpan > (); } { ( ts = timespan() { result.add(ts); } ( < COMMA > ts1 = timespan() { result.add(ts1); } )* ) { return result; } } String weekday() : { Token w = null; } { (w = < WEEKDAY > { return w.image; } ) | ( ( w = < WEEKDAY3 > | w = < WEEKDAYDE > ) { if (strict) { String msg = w.kind == OpeningHoursParserConstants.WEEKDAY3 ? tr("invalid_week_day_three") : tr("invalid_week_day_german"); ParseException e = new OpeningHoursParseException(msg, token.next); e.currentToken = token; throw e; } return w.image; } ) } // Mo- // Mo-Fr // Mo[1] // Mo[1,3,5] WeekDayRange weekday_range() : { String startDay = null; String endDay = null; Nth nth = null; Nth nth1 = null; Token m = null; Token n = null; Token to = null; WeekDayRange wdr = new WeekDayRange(); } { startDay = weekday() ( ( ( ( < HYPHEN > | (to = < TO >) ) endDay = weekday() { if (strict && to != null) { throw new OpeningHoursParseException(tr("to_instead_of_dash"), token.next); } wdr.setEndDay(endDay); } ) ) | ( ( < BRACKET_LEFT > nth = nth() { wdr.add(nth); } ( < COMMA > nth1 = nth() { wdr.add(nth1); } )* < BRACKET_RIGHT > ) ( ( ( m = < HYPHEN > | < PLUS > ) n = number() ) < DAYS > { wdr.offset = Integer.parseInt(n.image); if (m != null) { wdr.offset = wdr.offset * -1; } } )? ) )? { wdr.setStartDay(startDay); return wdr; } } Nth nth() : { Nth n = new Nth(); Token t1 = null; Token t2 = null; Token sign = null; Token sign2 = null; } { ( ( sign = < HYPHEN > )? t1 = one2five() { n.startNth = Integer.parseInt(t1.image); if (sign != null) { n.startNth = n.startNth * -1; } } )? ( < HYPHEN > ( sign2 = < HYPHEN > )? t2 = one2five() { n.endNth = Integer.parseInt(t2.image); if (sign2 != null) { n.endNth = n.endNth * -1; } } )? { return n; } } List < WeekDayRange > weekday_selector() : { WeekDayRange wdr, wdr1; List < WeekDayRange > result = new ArrayList < WeekDayRange > (); } { wdr = weekday_range() { result.add(wdr); } ( < COMMA > wdr1 = weekday_range() { result.add(wdr1); } )* { return result; } } Holiday holiday() : { Token h = null; Token n = null; Token m = null; Holiday result = new Holiday(); } { h = < HOLIDAYS > ( ( ( m = < HYPHEN > | < PLUS > ) n = number() ) < DAYS > { result.offset = Integer.parseInt(n.image); if (m != null) { result.offset = result.offset * -1; } } )? { result.type = Holiday.Type.valueOf(h.image.toUpperCase(Locale.US)); // the enum values are in upper case return result; } } List < Holiday > holiday_sequence() : { Holiday h = null; Holiday h1 = null; List < Holiday > result = new ArrayList < Holiday > (); } { h = holiday() { result.add(h); } ( < COMMA > h1 = holiday() { result.add(h1); } )* { return result; } } String month() : { Token m = null; } { m = < MONTH > { return m.image; } } DateRange date_range() : { DateRange mdr = new DateRange(); DateWithOffset startDate = null; DateWithOffset endDate = null; Token plus = null; Token to = null; } { startDate = datewithoffset(false) { if (strict && startDate.getVarDate()==null && startDate.getMonth()==null) { throw new OpeningHoursParseException(tr("missing_month"), token.next); } mdr.startDate = startDate; startDate.openEnded = plus != null; } ( ( < HYPHEN > | (to = < TO >) ) ( endDate = datewithoffset(startDate.undefinedDay()) ( mdr.interval = interval() { if (startDate.day != DateWithOffset.UNDEFINED_MONTH_DAY || endDate.day != DateWithOffset.UNDEFINED_MONTH_DAY || startDate.varDate!=null || endDate.varDate!=null) { throw new OpeningHoursParseException(tr("interval_not_allowed_here"), token != null ? token.next : null); } } )? { if (strict && to != null) { throw new OpeningHoursParseException(tr("to_instead_of_dash"), token != null ? token.next : null); } if ((startDate.undefinedDay() || endDate.undefinedDay()) && mdr.interval == 0 && (!startDate.undefinedYear() || !endDate.undefinedYear())) { if (strict) { throw new OpeningHoursParseException(tr("missing_day_in_range", startDate.toString(), endDate.toString()), token != null ? token.next : null); } else { // fix this up if (startDate.undefinedDay()) { startDate.setDay(1); } if (endDate.undefinedDay()) { endDate.setDay(Month.lastDay(endDate.getYear(), endDate.getMonth())); } } } mdr.endDate = endDate; } ) | < PLUS > { startDate.openEnded = true; } )? { return mdr; } } int daynum() : { Token n = null; } { ( // FIXME LOOKAHEAD({ getToken(1).kind == NUMBER && Util.between(getToken(1).image, 1, 31) && !(getToken(2).kind == COLON && getToken(3).kind == NUMBER && getToken(4).kind != COLON)}) n = < NUMBER > ) { if (strict && n.image.length() != 2) { ParseException pex = new OpeningHoursParseException(tr("invalid_month_day", n.image), token.next); pex.currentToken = token; throw pex; } return Integer.parseInt(n.image); } } int year() : { Token n = null; } { ( LOOKAHEAD({ getToken(1).kind == NUMBER && Util.equalsOrMore(getToken(1).image, 1900)}) n = < NUMBER > ) { return Integer.parseInt(n.image); } } DateWithOffset datewithoffset(boolean mo) : { DateWithOffset dwo = new DateWithOffset(); int y = 0; Token m = null; Token d = null; Token h = null; Token n = null; Token v = null; Token minus = null; Token num = null; Token wd = null; Token nth = null; String nthWd = null; Token sign = null; monthOnly = mo; // hack we can't pass an argument to semantic lookahead } { ( y = year() { dwo.year = y; } )? ( ( ( ( // check that the daynum is not the hour part of a time, month should really only be optional if this is the end of a range LOOKAHEAD(((< MONTH >)? daynum()), {!monthOnly && (getToken(1).kind == NUMBER && (getToken(2).kind != COLON || getToken(2).kind != STOP || getToken(2).kind != H)) || ( getToken(1).kind == MONTH && getToken(2).kind == NUMBER && (getToken(3).kind != COLON || getToken(3).kind != STOP || getToken(3).kind != H)) }) ( ( m = < MONTH > { dwo.setMonth(m.image); } )? dwo.day = daynum() ) | // check that the occurrence spec is not actually part of a weekday range, the OH specification is ambiguous on how this should be handled if it is not a range // examples // Jan,Feb Sa[-2] -1 day,Sa[-2],Sa[-2] +1 day,Sa[-1] -1 day,Sa[-1],Sa[-1] +1 day .... // Jan,Feb Sa[-2],Sa[-2],Sa[-1] -1 day,Sa[-1],Sa[-1] +1 day LOOKAHEAD(11, < MONTH > weekday() < BRACKET_LEFT > (< HYPHEN >)? one2five() < BRACKET_RIGHT > ( (< HYPHEN > | < PLUS >) number() < DAYS >)?, { !monthOnly && ((getToken( getToken(4).kind == HYPHEN ? 9 : 8).kind == DAYS && getToken( getToken(4).kind == HYPHEN ? 10 : 9).kind != COMMA) || (getToken( getToken(4).kind == HYPHEN ? 9 : 8).kind != DAYS && getToken( getToken(4).kind == HYPHEN ? 7 : 6).kind != COMMA) || (getToken( getToken(4).kind == HYPHEN ? 9 : 8).kind == DAYS && getToken( getToken(4).kind == HYPHEN ? 10 : 9).kind == COMMA && getToken( getToken(4).kind == HYPHEN ? 11 : 10).kind != WEEKDAY) || (getToken( getToken(4).kind == HYPHEN ? 9 : 8).kind != DAYS && getToken( getToken(4).kind == HYPHEN ? 7 : 6).kind == COMMA && getToken( getToken(4).kind == HYPHEN ? 8 : 7).kind != WEEKDAY))} ) ( m = < MONTH > { dwo.setMonth(m.image); } nthWd = weekday() < BRACKET_LEFT > ( sign = < HYPHEN > )? nth = one2five() < BRACKET_RIGHT > ) { dwo.nthWeekDay = WeekDay.getValue(nthWd); dwo.nth = Integer.parseInt(nth.image); if (sign != null) { dwo.nth = dwo.nth * -1; } } ) | ( v = < VARDATE > { dwo.setVarDate(v.image); } ) ) ( // This tries to, as lax as possible, differentiate between Jan 31+ Mo and Jan 31+Mo, that is an open ended date vs date with an offset LOOKAHEAD(5, ( < HYPHEN > | < PLUS > ) < WEEKDAY >, { getToken(1).kind == HYPHEN || !precedingWs(getToken(2)) || getToken(5).kind == DAYS }) ( minus = < HYPHEN > | < PLUS > ) wd = < WEEKDAY > { dwo.weekDayOffsetPositive = minus == null; dwo.setWeekDayOffset(wd.image); } )? ( ( ( minus = < HYPHEN > | < PLUS > ) num = number() < DAYS > ) { dwo.dayOffset = Integer.parseInt(num.image) * (minus != null ? - 1 : 1); } )? ) | ( m = < MONTH > { dwo.setMonth(m.image); } ) ) { return dwo; } } List < DateRange > date_selector() : { DateRange mdr, mdr1; Month lastMonth = null; int lastYear = YearRange.UNDEFINED_YEAR; List < DateRange > result = new ArrayList < DateRange > (); } { // the first date either need to be a vardate or have a month LOOKAHEAD( { (getToken(1).kind == NUMBER && (getToken(2).kind == MONTH || getToken(2).kind == VARDATE)) || getToken(1).kind == MONTH || getToken(1).kind == VARDATE }) ( mdr = date_range() { result.add(mdr); } ( < COMMA > mdr1 = date_range() { DateWithOffset dwo = mdr1.getStartDate(); // if the month and maybe the year is missing in the start date patch it up here // in strict mode we will never get to this point if (dwo.getVarDate() == null) { if (dwo.getMonth() == null) { if (strict) { throw new OpeningHoursParseException(tr("missing_month_start"), token.next); } if (lastMonth == null) { DateWithOffset first = mdr.getStartDate(); lastMonth = first.getMonth(); lastYear = first.getYear(); if (lastMonth == null) { // fail, can't fudge the month throw new OpeningHoursParseException(tr("missing_month_start"), token.next); } } dwo.setMonth(lastMonth); dwo.setYear(lastYear); } else { lastMonth = dwo.getMonth(); lastYear = dwo.getYear(); } } result.add(mdr1); } )* { return result; } ) } int weeknum() : { Token n = null; } { ( LOOKAHEAD({ getToken(1).kind == NUMBER && Util.between(getToken(1).image, 1, 54) }) n = < NUMBER > ) { return Integer.parseInt(n.image); } } WeekRange week_range() : { WeekRange wr = new WeekRange(); Token w = null; Token w1 = null; Token to = null; } { wr.startWeek = weeknum() ( ( < HYPHEN > | (to = < TO >) ) ( wr.endWeek = weeknum() ) { if (strict && to != null) { throw new OpeningHoursParseException(tr("to_instead_of_dash"), token.next); } } ( wr.interval = interval() )? )? { return wr; } } List < WeekRange > week_selector() : { WeekRange wr, wr1; List < WeekRange > result = new ArrayList < WeekRange > (); } { < WEEK > wr = week_range() { result.add(wr); } ( < COMMA > wr1 = week_range() { result.add(wr1); } )* { return result; } } YearRange year_range() : { YearRange yr = new YearRange(); Token y = null; Token y1 = null; Token to = null; } { yr.startYear = year() ( ( ( < HYPHEN > | (to = < TO >) ) ( yr.endYear = year() ) { if (strict && to != null) { throw new OpeningHoursParseException(tr("to_instead_of_dash"), token.next); } } ( yr.interval = interval() )? ) | < PLUS > { yr.openEnded = true; } )? { return yr; } } List < YearRange > year_selector() : { YearRange yr, yr1; List < YearRange > result = new ArrayList < YearRange > (); } { LOOKAHEAD({getToken(2).kind != MONTH && getToken(2).kind != VARDATE}) yr = year_range() { result.add(yr); } ( < COMMA > yr1 = year_range() { result.add(yr1); } )* { return result; } } RuleModifier rule_modifier() : { RuleModifier rm = new RuleModifier(); Token m = null; String c = null; } { ( m = < MODIFIER > { rm.setModifier(m.image); } )? ( c = comment() { rm.comment = c; } )? { if (rm.modifier == null && rm.comment == null) { return null; } return rm; } } Rule rule() : { Rule r = null; String comment = null; boolean always = false; List < YearRange > ys = null; List < WeekRange > ws = null; List < DateRange > ms = null; List < Holiday > hs = null; List < Holiday > hs2 = null; List < WeekDayRange > ds = null; List < WeekDayRange > ds2 = null; List < TimeSpan > ts = null; RuleModifier rm = null; boolean colonForClarification = false; } { ( LOOKAHEAD(comment() < COLON >) ( comment = comment() < COLON > ) | LOOKAHEAD( (year_selector() | week_selector() | date_selector())? ) ( ( ys = year_selector() )? ( ws = week_selector() )? ( ms = date_selector() )? ( < COLON > { colonForClarification = true; } )? ) ) ( ( < ALWAYS > { if (strict && (ys != null || ws != null || ms != null)) { ParseException e = new OpeningHoursParseException(tr("24_7_with_other_selectors")); e.currentToken = token; throw e; } else { if (ys != null || ws != null || ms != null) { // correct to proper syntax ts = new ArrayList < TimeSpan > (); TimeSpan t = new TimeSpan(); t.start = 0; t.end = 1440; ts.add(t); } else { always = true; } } } ) | ( ( ( hs = holiday_sequence() )? ( ( ( < COMMA > ds = weekday_selector() { if (hs != null) { for (Holiday h:hs) { h.setUseAsWeekDay(true); } } } ) | ds = weekday_selector() { if (hs != null) { for (Holiday h:hs) { h.setUseAsWeekDay(false); } } } ) ( < COMMA > hs2 = holiday_sequence() { if (hs2 != null) { for (Holiday h:hs2) { h.setUseAsWeekDay(true); h.setAfterWeekDays(true); } } if (hs != null) { hs.addAll(hs2); } else { hs = hs2; } } ( < COMMA > ds2 = weekday_selector() { if (strict && hs2 != null) { ParseException e = new OpeningHoursParseException(tr("holiday_in_weekday_range"), token.next); e.currentToken = token; throw e; } if (ds != null) { ds.addAll(ds2); } else { ds = ds2; } } )* )* )? ) // spec is not clear on this, however ":" is used in real life here a lot ( < COLON > )? ( ts = time_selector() )? ) ) ( rm = rule_modifier() ) { r = new Rule(); r.comment = comment; r.twentyfourseven = always; r.years = ys; r.weeks = ws; r.dates = ms; r.holidays = hs; r.days = ds; r.times = ts; r.modifier = rm; r.colonForClarification = colonForClarification; return r; } } private List < Rule > rules0(boolean strict, boolean strictTime) : { this.strict = strict; this.strictTime = strictTime; List < Rule > result = new ArrayList < Rule > (); Rule r = null; Rule r1 = null; } { try { ( r = rule() ) { result.add(r); } } catch (ParseException e) { error_skip(e); return rules0(strict, strictTime); } try { ( ( < COMMA > ( r1 = rule() { r1.additive = true; r1.fallBack = false; result.add(r1); } ) | < SEMICOLON > ( r1 = rule() { r1.additive = false; r1.fallBack = false; result.add(r1); } ) | < FALLBACKSEPERATOR > ( r1 = rule() { r1.additive = false; r1.fallBack = true; result.add(r1); } ) ) ) * < EOF > } catch (ParseException e) { error_skip(e); return rules0(strict, strictTime); } { r.additive = false; r.fallBack = false; return result; } } < * > TOKEN : { < UNEXPECTED_CHAR : ~[ ] > }