17 for _, match in ipairs(list) do |
17 for _, match in ipairs(list) do |
18 patt = patt + lpeg.Pi(match); |
18 patt = patt + lpeg.Pi(match); |
19 end |
19 end |
20 return patt; |
20 return patt; |
21 end |
21 end |
|
22 |
|
23 local wordsep = lpeg.S" "; |
22 |
24 |
23 local ordinal = lpeg.P{ lpeg.C(lpeg.R("09")^-2) * (lpeg.Pi("st") + lpeg.Pi("nd") + lpeg.Pi("rd") + lpeg.Pi("th")) + 1 * lpeg.V(1) }; |
25 local ordinal = lpeg.P{ lpeg.C(lpeg.R("09")^-2) * (lpeg.Pi("st") + lpeg.Pi("nd") + lpeg.Pi("rd") + lpeg.Pi("th")) + 1 * lpeg.V(1) }; |
24 local number = lpeg.R "09"^1 |
26 local number = lpeg.R "09"^1 |
25 |
27 |
26 local day_name = lpeg.one_of {'monday', 'tuesday', 'wednesday', |
28 local day_name = lpeg.one_of {'monday', 'tuesday', 'wednesday', |
157 } |
159 } |
158 |
160 |
159 local ret, min_pos, max_pos; |
161 local ret, min_pos, max_pos; |
160 local function check_min_pos(start) start = start - 1; if not min_pos or start < min_pos then min_pos = start; end end; |
162 local function check_min_pos(start) start = start - 1; if not min_pos or start < min_pos then min_pos = start; end end; |
161 for _, pattern in pairs(patterns) do |
163 for _, pattern in pairs(patterns) do |
162 ret = lpeg.match(lpeg.P{ lpeg.Cp()*pattern[1] + 1 * lpeg.V(1) }/check_min_pos, str); |
164 ret = lpeg.match(lpeg.P{ lpeg.Cp()*pattern[1] + 1 * (1-wordsep)^0 * wordsep * lpeg.V(1) }/check_min_pos, str); |
163 if ret then |
165 if ret then |
164 if not max_pos or ret > max_pos then max_pos = ret; end |
166 if not max_pos or ret > max_pos then max_pos = ret; end |
165 --print("Matches ".._.." until "..ret); |
167 --print("Matches ".._.." until "..ret); |
166 end |
168 end |
167 end |
169 end |