sclass EnglishDateParser > DateStructures { replace P with ParsedWithTokens. bool assumeFuture = true; // e.g. for "tuesday" [not used] LS tok; int maxTokens = 3; L
> longestParses(S s) { ret pwt_topDogs(pwt_filterByType SomeDate(allParses(s))); } SomeDate parse(S s) { ret getVar(first(longestParses(s))); } ItIt
allParses(S s) { tok = javaTok(s); new L
out;
L > numbers = concatMap parseNumber(codeTokens);
// "in > years = concatMap parseYear(codeTokens);
print(+years);
out.addAll(years);
L > weekdays = concatMap parseWeekday(codeTokens);
out.addAll(weekdays);
L > months = concatMap parseMonthName(codeTokens);
out.addAll(months);
// "next > parseNumber(ListAndIndex > parseYear(ListAndIndex > parseMonth(ListAndIndex > parseDayOfMonth(ListAndIndex > parseFixedToken(S token, ListAndIndex > parseFixedToken_before(S token, ListAndIndex > parseOneOfFixedTokens(Set > parseWeekday(ListAndIndex > parseMonthName(ListAndIndex in : print("in", asList(parseFixedToken_before("in", number.start()))))
for (P days : print("days", asList(parseOneOfFixedTokens(litciset("day", "days"), print(number.remaining())))))
out.add(pwt_combine(new TodayPlus(number!), in, days));
// " daysFromNow : parseOneOfFixedTokens(litciset("day from now", "days from now"), number.remaining()))
out.add(pwt_combine(new TodayPlus(number!), number, daysFromNow));
L next : parseFixedToken_before("next", weekday.start()))
out.add(pwt_combine(new Weekday(weekday->weekday, new CurrentWeekPlus(1)), next, weekday));
for (P slash : parseFixedToken("/", year.remaining()))
for (P slash2 : parseFixedToken("/", month.remaining()))
for (P toParse) {
ret mapI_nonNulls(pwt_followingTokens(1, maxTokens, toParse),
p -> isInteger(p!) ? p.withValue(parseInt(p!)) : null);
}
ItIt toParse) {
ret filterI(parseNumber(toParse), p -> between(p!, 1900, 2100));
}
ItIt toParse) {
ret filterI(parseNumber(toParse), p -> between(p!, 1, 12));
}
ItIt toParse) {
ret filterI(parseNumber(toParse), p -> between(p!, 1, 31));
}
ItIt toParse) {
ret filterI(pwt_followingTokens(1, maxTokens, toParse), p -> eqic(p!, token));
}
ItIt toParse) {
ret filterI(pwt_precedingTokens(1, maxTokens, toParse), p -> eqic(p!, token));
}
ItIt tokens, ListAndIndex toParse) {
ret filterI(pwt_followingTokens(1, maxTokens, toParse), p -> contains(tokens, p!));
}
ItIt toParse) {
ret pwt_mapI(s -> new Weekday(parseEnglishWeekday(s)), parseOneOfFixedTokens(englishWeekdays_ciSet(), toParse));
}
ItIt toParse) {
ret pwt_mapI(s -> new Month(parseEnglishMonthName(s)), parseOneOfFixedTokens(englishMonthNames_ciSet(), toParse));
}
}