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> codeTokens = asList(lai_codeTokens(tok)); L> numbers = concatMap parseNumber(codeTokens); // "in days" for (P number : numbers) for (P 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)); // " days from now" for (P number : numbers) for (P daysFromNow : parseOneOfFixedTokens(litciset("day from now", "days from now"), number.remaining())) out.add(pwt_combine(new TodayPlus(number!), number, daysFromNow)); L> 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 " for (P weekday : weekdays) for (P next : parseFixedToken_before("next", weekday.start())) out.add(pwt_combine(new Weekday(weekday->weekday, new CurrentWeekPlus(1)), next, weekday)); for (P year : years) for (P slash : parseFixedToken("/", year.remaining())) for (P month : parseMonth(slash.remaining())) for (P slash2 : parseFixedToken("/", month.remaining())) for (P day : parseDayOfMonth(slash2.remaining())) out.add(pwt_combine(new Day(day!, new Month(month!, new Year(year!))), year, day)); ret itIt(out); } ItIt> parseNumber(ListAndIndex toParse) { ret mapI_nonNulls(pwt_followingTokens(1, maxTokens, toParse), p -> isInteger(p!) ? p.withValue(parseInt(p!)) : null); } ItIt> parseYear(ListAndIndex toParse) { ret filterI(parseNumber(toParse), p -> between(p!, 1900, 2100)); } ItIt> parseMonth(ListAndIndex toParse) { ret filterI(parseNumber(toParse), p -> between(p!, 1, 12)); } ItIt> parseDayOfMonth(ListAndIndex toParse) { ret filterI(parseNumber(toParse), p -> between(p!, 1, 31)); } ItIt> parseFixedToken(S token, ListAndIndex toParse) { ret filterI(pwt_followingTokens(1, maxTokens, toParse), p -> eqic(p!, token)); } ItIt> parseFixedToken_before(S token, ListAndIndex toParse) { ret filterI(pwt_precedingTokens(1, maxTokens, toParse), p -> eqic(p!, token)); } ItIt> parseOneOfFixedTokens(Set tokens, ListAndIndex toParse) { ret filterI(pwt_followingTokens(1, maxTokens, toParse), p -> contains(tokens, p!)); } ItIt> parseWeekday(ListAndIndex toParse) { ret pwt_mapI(s -> new Weekday(parseEnglishWeekday(s)), parseOneOfFixedTokens(englishWeekdays_ciSet(), toParse)); } ItIt> parseMonthName(ListAndIndex toParse) { ret pwt_mapI(s -> new Month(parseEnglishMonthName(s)), parseOneOfFixedTokens(englishMonthNames_ciSet(), toParse)); } }