summaryrefslogtreecommitdiff
path: root/tex/context/base/lxml-lpt.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-02-13 19:20:32 +0200
committerMarius <mariausol@gmail.com>2013-02-13 19:20:32 +0200
commit13706211c6f53d83a620a845c9c0e5bb736345a3 (patch)
tree45c2d15d5a70813202748cea43832e2f8caba00f /tex/context/base/lxml-lpt.lua
parent298e57104a0c60ee6fbf14ff67b9515512a8b7cd (diff)
downloadcontext-13706211c6f53d83a620a845c9c0e5bb736345a3.tar.gz
beta 2013.02.13 18:06
Diffstat (limited to 'tex/context/base/lxml-lpt.lua')
-rw-r--r--tex/context/base/lxml-lpt.lua89
1 files changed, 72 insertions, 17 deletions
diff --git a/tex/context/base/lxml-lpt.lua b/tex/context/base/lxml-lpt.lua
index 875b6bb96..d73b87287 100644
--- a/tex/context/base/lxml-lpt.lua
+++ b/tex/context/base/lxml-lpt.lua
@@ -1346,34 +1346,89 @@ end
</typing>
--ldx]]--
-local wrap, yield = coroutine.wrap, coroutine.yield
+-- local wrap, yield = coroutine.wrap, coroutine.yield
+-- local dummy = function() end
+--
+-- function xml.elements(root,pattern,reverse) -- r, d, k
+-- local collected = applylpath(root,pattern)
+-- if collected then
+-- if reverse then
+-- return wrap(function() for c=#collected,1,-1 do
+-- local e = collected[c] local r = e.__p__ yield(r,r.dt,e.ni)
+-- end end)
+-- else
+-- return wrap(function() for c=1,#collected do
+-- local e = collected[c] local r = e.__p__ yield(r,r.dt,e.ni)
+-- end end)
+-- end
+-- end
+-- return wrap(dummy)
+-- end
+--
+-- function xml.collected(root,pattern,reverse) -- e
+-- local collected = applylpath(root,pattern)
+-- if collected then
+-- if reverse then
+-- return wrap(function() for c=#collected,1,-1 do yield(collected[c]) end end)
+-- else
+-- return wrap(function() for c=1,#collected do yield(collected[c]) end end)
+-- end
+-- end
+-- return wrap(dummy)
+-- end
+
+-- faster:
+
+local dummy = function() end
function xml.elements(root,pattern,reverse) -- r, d, k
local collected = applylpath(root,pattern)
- if collected then
- if reverse then
- return wrap(function() for c=#collected,1,-1 do
- local e = collected[c] local r = e.__p__ yield(r,r.dt,e.ni)
- end end)
- else
- return wrap(function() for c=1,#collected do
- local e = collected[c] local r = e.__p__ yield(r,r.dt,e.ni)
- end end)
+ if not collected then
+ return dummy
+ elseif reverse then
+ local c = #collected + 1
+ return function()
+ if c > 1 then
+ c = c - 1
+ local e = collected[c]
+ local r = e.__p__
+ return r, r.dt, e.ni
+ end
+ end
+ else
+ local n, c = #collected, 0
+ return function()
+ if c < n then
+ c = c + 1
+ local e = collected[c]
+ local r = e.__p__
+ return r, r.dt, e.ni
+ end
end
end
- return wrap(function() end)
end
function xml.collected(root,pattern,reverse) -- e
local collected = applylpath(root,pattern)
- if collected then
- if reverse then
- return wrap(function() for c=#collected,1,-1 do yield(collected[c]) end end)
- else
- return wrap(function() for c=1,#collected do yield(collected[c]) end end)
+ if not collected then
+ return dummy
+ elseif reverse then
+ local c = #collected + 1
+ return function()
+ if c > 1 then
+ c = c - 1
+ return collected[c]
+ end
+ end
+ else
+ local n, c = #collected, 0
+ return function()
+ if c < n then
+ c = c + 1
+ return collected[c]
+ end
end
end
- return wrap(function() end)
end
-- handy