Return the position of the start and end of the matched text

Sun, 21 Jun 2009 19:12:26 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 21 Jun 2009 19:12:26 +0100
changeset 9
dc0c8914ac04
parent 8
8c6e74396e22
child 10
6700d4722be7

Return the position of the start and end of the matched text

ndp.lua file | annotate | diff | comparison | revisions
--- a/ndp.lua	Sun Jun 21 18:50:58 2009 +0100
+++ b/ndp.lua	Sun Jun 21 19:12:26 2009 +0100
@@ -156,15 +156,16 @@
 			end }; 
 	}
 	
-	local ret, pos;
+	local ret, min_pos, max_pos;
 	for _, pattern in pairs(patterns) do
-		ret = lpeg.match(lpeg.P{ pattern[1] + 1 * lpeg.V(1) }, str);
+		ret = lpeg.match(lpeg.P{ lpeg.Cp()*pattern[1] + 1 * lpeg.V(1) }
+		/function (start) start = start - 1; if not min_pos or start < min_pos then min_pos = start; end end, str);
 		if ret then
-			pos = ret;
+			if not max_pos or ret > max_pos then max_pos = ret; end
 			--print("Matches ".._.." until "..ret);
 		end
 	end
 	
-	return time, pos;
+	return time, min_pos, max_pos;
 end
 

mercurial