From 5f2ef13d20837eb9c0fe84a378e70c5066e6d021 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Fri, 21 May 2010 06:22:29 +0300 Subject: Sync with ConTeXt beta (beta 2010.05.20) Needed to sync luaotfload. --- lualibs-lpeg.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lualibs-lpeg.lua') diff --git a/lualibs-lpeg.lua b/lualibs-lpeg.lua index f060f3b..b107a8e 100644 --- a/lualibs-lpeg.lua +++ b/lualibs-lpeg.lua @@ -98,6 +98,15 @@ lpeg.splitat = splitat local cache = { } +function lpeg.split(separator,str) + local c = cache[separator] + if not c then + c = Ct(splitat(separator)) + cache[separator] = c + end + return match(c,str) +end + function string:split(separator) local c = cache[separator] if not c then @@ -107,8 +116,21 @@ function string:split(separator) return match(c,self) end +lpeg.splitters = cache + local cache = { } +function lpeg.checkedsplit(separator,str) + local c = cache[separator] + if not c then + separator = P(separator) + local other = C((1 - separator)^0) + c = Ct(separator^0 * other * (separator^1 * other)^0) + cache[separator] = c + end + return match(c,str) +end + function string:checkedsplit(separator) local c = cache[separator] if not c then -- cgit v1.2.3