summaryrefslogtreecommitdiff
path: root/tex/context/base/l-lpeg.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/l-lpeg.lua')
-rw-r--r--tex/context/base/l-lpeg.lua30
1 files changed, 8 insertions, 22 deletions
diff --git a/tex/context/base/l-lpeg.lua b/tex/context/base/l-lpeg.lua
index 6feb7089c..399b3ad65 100644
--- a/tex/context/base/l-lpeg.lua
+++ b/tex/context/base/l-lpeg.lua
@@ -6,10 +6,6 @@ if not modules then modules = { } end modules ['l-lpeg'] = {
license = "see context related readme files"
}
--- lpeg 12 vs lpeg 10: slower compilation, similar parsing speed (i need to check
--- if i can use new features like capture / 2 and .B (at first sight the xml
--- parser is some 5% slower)
-
-- a new lpeg fails on a #(1-P(":")) test and really needs a + P(-1)
-- move utf -> l-unicode
@@ -19,15 +15,14 @@ lpeg = require("lpeg")
-- The latest lpeg doesn't have print any more, and even the new ones are not
-- available by default (only when debug mode is enabled), which is a pitty as
--- as it helps nailign down bottlenecks. Performance seems comparable: some 10%
--- slower pattern compilation, same parsing speed, although,
+-- as it helps bailign down bottlenecks. Performance seems comparable, although
--
-- local p = lpeg.C(lpeg.P(1)^0 * lpeg.P(-1))
--- local a = string.rep("123",100)
+-- local a = string.rep("123",10)
-- lpeg.match(p,a)
--
--- seems slower and is also still suboptimal (i.e. a match that runs from begin
--- to end, one of the cases where string matchers win).
+-- is nearly 20% slower and also still suboptimal (i.e. a match that runs from
+-- begin to end, one of the cases where string matchers win).
if not lpeg.print then function lpeg.print(...) print(lpeg.pcode(...)) end end
@@ -79,9 +74,7 @@ local lpegtype, lpegmatch, lpegprint = lpeg.type, lpeg.match, lpeg.print
-- let's start with an inspector:
-if setinspector then
- setinspector(function(v) if lpegtype(v) then lpegprint(v) return true end end)
-end
+setinspector(function(v) if lpegtype(v) then lpegprint(v) return true end end)
-- Beware, we predefine a bunch of patterns here and one reason for doing so
-- is that we get consistent behaviour in some of the visualizers.
@@ -176,14 +169,12 @@ patterns.whitespace = whitespace
patterns.nonspacer = nonspacer
patterns.nonwhitespace = nonwhitespace
-local stripper = spacer ^0 * C((spacer ^0 * nonspacer ^1)^0) -- from example by roberto
-local fullstripper = whitespace^0 * C((whitespace^0 * nonwhitespace^1)^0)
+local stripper = spacer^0 * C((spacer^0 * nonspacer^1)^0) -- from example by roberto
----- collapser = Cs(spacer^0/"" * ((spacer^1 * endofstring / "") + (spacer^1/" ") + P(1))^0)
local collapser = Cs(spacer^0/"" * nonspacer^0 * ((spacer^0/" " * nonspacer^1)^0))
patterns.stripper = stripper
-patterns.fullstripper = fullstripper
patterns.collapser = collapser
patterns.lowercase = lowercase
@@ -478,7 +469,7 @@ end
-- local pattern1 = P(1-P(pattern))^0 * P(pattern) : test for not nil
-- local pattern2 = (P(pattern) * Cc(true) + P(1))^0 : test for true (could be faster, but not much)
-function lpeg.finder(lst,makefunction,isutf) -- beware: slower than find with 'patternless finds'
+function lpeg.finder(lst,makefunction) -- beware: slower than find with 'patternless finds'
local pattern
if type(lst) == "table" then
pattern = P(false)
@@ -494,12 +485,7 @@ function lpeg.finder(lst,makefunction,isutf) -- beware: slower than find with 'p
else
pattern = P(lst)
end
- if isutf then
--- pattern = ((utf8char or 1)-pattern)^0 * pattern
- pattern = ((utf8char or 1)-pattern)^0 * pattern
- else
- pattern = (1-pattern)^0 * pattern
- end
+ pattern = (1-pattern)^0 * pattern
if makefunction then
return function(str)
return lpegmatch(pattern,str)