ndp.lua

changeset 12
a127265f3257
parent 11
a40db377a1b5
child 13
f59a3859363e
--- a/ndp.lua	Sun Jun 21 19:16:54 2009 +0100
+++ b/ndp.lua	Sun Jun 21 22:54:45 2009 +0100
@@ -20,6 +20,8 @@
 	return patt;
 end
 
+local wordsep = lpeg.S" ";
+
 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) };
 local number = lpeg.R "09"^1
 
@@ -159,7 +161,7 @@
 	local ret, min_pos, max_pos;
 	local function check_min_pos(start) start = start - 1; if not min_pos or start < min_pos then min_pos = start; end end;
 	for _, pattern in pairs(patterns) do
-		ret = lpeg.match(lpeg.P{ lpeg.Cp()*pattern[1] + 1 * lpeg.V(1) }/check_min_pos, str);
+		ret = lpeg.match(lpeg.P{ lpeg.Cp()*pattern[1] + 1 * (1-wordsep)^0 * wordsep * lpeg.V(1) }/check_min_pos, str);
 		if ret then
 			if not max_pos or ret > max_pos then max_pos = ret; end
 			--print("Matches ".._.." until "..ret);

mercurial