ndp.lua

changeset 11
a40db377a1b5
parent 9
dc0c8914ac04
child 12
a127265f3257
equal deleted inserted replaced
10:6700d4722be7 11:a40db377a1b5
155 end 155 end
156 end }; 156 end };
157 } 157 }
158 158
159 local ret, min_pos, max_pos; 159 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;
160 for _, pattern in pairs(patterns) do 161 for _, pattern in pairs(patterns) do
161 ret = lpeg.match(lpeg.P{ lpeg.Cp()*pattern[1] + 1 * lpeg.V(1) } 162 ret = lpeg.match(lpeg.P{ lpeg.Cp()*pattern[1] + 1 * lpeg.V(1) }/check_min_pos, str);
162 /function (start) start = start - 1; if not min_pos or start < min_pos then min_pos = start; end end, str);
163 if ret then 163 if ret then
164 if not max_pos or ret > max_pos then max_pos = ret; end 164 if not max_pos or ret > max_pos then max_pos = ret; end
165 --print("Matches ".._.." until "..ret); 165 --print("Matches ".._.." until "..ret);
166 end 166 end
167 end 167 end

mercurial