diff options
author | Marius <mariausol@gmail.com> | 2013-03-10 15:40:13 +0200 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-03-10 15:40:13 +0200 |
commit | 5f8fcb63f3e90458fa3b9feb9511b538340fd027 (patch) | |
tree | 2a064f6b42da2d7f74f3164d36b8409d6b170999 /tex/context/base/l-lpeg.lua | |
parent | 8bfadcb777942fb94f714df18d4172f0704dcbea (diff) | |
download | context-5f8fcb63f3e90458fa3b9feb9511b538340fd027.tar.gz |
beta 2013.03.10 14:36
Diffstat (limited to 'tex/context/base/l-lpeg.lua')
-rw-r--r-- | tex/context/base/l-lpeg.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tex/context/base/l-lpeg.lua b/tex/context/base/l-lpeg.lua index 9bd9706bf..cfc26a5a5 100644 --- a/tex/context/base/l-lpeg.lua +++ b/tex/context/base/l-lpeg.lua @@ -829,3 +829,24 @@ end -- local s = "12" .. string.rep("AB",20) .. "34" .. string.rep("AB",30) .. "56" -- inspect(p) -- print(lpeg.match(p,s)) + +-- moved here (before util-str) + +local digit = R("09") +local period = P(".") +local zero = P("0") +local trailingzeros = zero^0 * -digit -- suggested by Roberto R +local case_1 = period * trailingzeros / "" +local case_2 = period * (digit - trailingzeros)^1 * (trailingzeros / "") +local number = digit^1 * (case_1 + case_2) +local stripper = Cs((number + 1)^0) + +lpeg.patterns.stripzeros = stripper + +-- local sample = "bla 11.00 bla 11 bla 0.1100 bla 1.00100 bla 0.00 bla 0.001 bla 1.1100 bla 0.100100100 bla 0.00100100100" +-- collectgarbage("collect") +-- str = string.rep(sample,10000) +-- local ts = os.clock() +-- lpegmatch(stripper,str) +-- print(#str, os.clock()-ts, lpegmatch(stripper,sample)) + |