summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/lxml-lpt.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/lxml-lpt.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/lxml-lpt.lua276
1 files changed, 98 insertions, 178 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/lxml-lpt.lua b/Master/texmf-dist/tex/context/base/mkiv/lxml-lpt.lua
index 392c1a4014e..bb6fb456816 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/lxml-lpt.lua
+++ b/Master/texmf-dist/tex/context/base/mkiv/lxml-lpt.lua
@@ -157,47 +157,32 @@ apply_axis['root'] = function(list)
end
apply_axis['self'] = function(list)
- -- local collected = { }
- -- for l=1,#list do
- -- collected[l] = list[l]
- -- end
- -- return collected
+--~ local collected = { }
+--~ for l=1,#list do
+--~ collected[l] = list[l]
+--~ end
+--~ return collected
return list
end
apply_axis['child'] = function(list)
- local collected = { }
- local c = 0
+ local collected, c = { }, 0
for l=1,#list do
local ll = list[l]
local dt = ll.dt
if dt then -- weird that this is needed
- local n = #dt
- if n == 0 then
- ll.en = 0
- elseif n == 1 then
- local dk = dt[1]
+ local en = 0
+ for k=1,#dt do
+ local dk = dt[k]
if dk.tg then
c = c + 1
collected[c] = dk
- dk.ni = 1 -- refresh
- dk.ei = 1
- ll.en = 1
- end
- else
- local en = 0
- for k=1,#dt do
- local dk = dt[k]
- if dk.tg then
- c = c + 1
- en = en + 1
- collected[c] = dk
- dk.ni = k -- refresh
- dk.ei = en
- end
+ dk.ni = k -- refresh
+ en = en + 1
+ dk.ei = en
end
- ll.en = en
end
+ ll.en = en
end
end
return collected
@@ -206,43 +191,25 @@ end
local function collect(list,collected,c)
local dt = list.dt
if dt then
- local n = #dt
- if n == 0 then
- list.en = 0
- elseif n == 1 then
- local dk = dt[1]
+ local en = 0
+ for k=1,#dt do
+ local dk = dt[k]
if dk.tg then
c = c + 1
collected[c] = dk
- dk.ni = 1 -- refresh
- dk.ei = 1
+ dk.ni = k -- refresh
+ en = en + 1
+ dk.ei = en
c = collect(dk,collected,c)
- list.en = 1
- else
- list.en = 0
end
- else
- local en = 0
- for k=1,n do
- local dk = dt[k]
- if dk.tg then
- c = c + 1
- en = en + 1
- collected[c] = dk
- dk.ni = k -- refresh
- dk.ei = en
- c = collect(dk,collected,c)
- end
- end
- list.en = en
end
+ list.en = en
end
return c
end
apply_axis['descendant'] = function(list)
- local collected = { }
- local c = 0
+ local collected, c = { }, 0
for l=1,#list do
c = collect(list[l],collected,c)
end
@@ -252,41 +219,24 @@ end
local function collect(list,collected,c)
local dt = list.dt
if dt then
- local n = #dt
- if n == 0 then
- list.en = 0
- elseif n == 1 then
- local dk = dt[1]
+ local en = 0
+ for k=1,#dt do
+ local dk = dt[k]
if dk.tg then
c = c + 1
collected[c] = dk
- dk.ni = 1 -- refresh
- dk.ei = 1
+ dk.ni = k -- refresh
+ en = en + 1
+ dk.ei = en
c = collect(dk,collected,c)
- list.en = 1
end
- else
- local en = 0
- for k=1,#dt do
- local dk = dt[k]
- if dk.tg then
- c = c + 1
- en = en + 1
- collected[c] = dk
- dk.ni = k -- refresh
- dk.ei = en
- c = collect(dk,collected,c)
- end
- end
- list.en = en
end
+ list.en = en
end
return c
end
-
apply_axis['descendant-or-self'] = function(list)
- local collected = { }
- local c = 0
+ local collected, c = { }, 0
for l=1,#list do
local ll = list[l]
if ll.special ~= true then -- catch double root
@@ -299,8 +249,7 @@ apply_axis['descendant-or-self'] = function(list)
end
apply_axis['ancestor'] = function(list)
- local collected = { }
- local c = 0
+ local collected, c = { }, 0
for l=1,#list do
local ll = list[l]
while ll do
@@ -315,8 +264,7 @@ apply_axis['ancestor'] = function(list)
end
apply_axis['ancestor-or-self'] = function(list)
- local collected = { }
- local c = 0
+ local collected, c = { }, 0
for l=1,#list do
local ll = list[l]
c = c + 1
@@ -333,8 +281,7 @@ apply_axis['ancestor-or-self'] = function(list)
end
apply_axis['parent'] = function(list)
- local collected = { }
- local c = 0
+ local collected, c = { }, 0
for l=1,#list do
local pl = list[l].__p__
if pl then
@@ -354,47 +301,45 @@ apply_axis['namespace'] = function(list)
end
apply_axis['following'] = function(list) -- incomplete
- -- local collected, c = { }, 0
- -- for l=1,#list do
- -- local ll = list[l]
- -- local p = ll.__p__
- -- local d = p.dt
- -- for i=ll.ni+1,#d do
- -- local di = d[i]
- -- if type(di) == "table" then
- -- c = c + 1
- -- collected[c] = di
- -- break
- -- end
- -- end
- -- end
- -- return collected
+--~ local collected, c = { }, 0
+--~ for l=1,#list do
+--~ local ll = list[l]
+--~ local p = ll.__p__
+--~ local d = p.dt
+--~ for i=ll.ni+1,#d do
+--~ local di = d[i]
+--~ if type(di) == "table" then
+--~ c = c + 1
+--~ collected[c] = di
+--~ break
+--~ end
+--~ end
+--~ end
+--~ return collected
return { }
end
apply_axis['preceding'] = function(list) -- incomplete
- -- local collected = { }
- -- local c = 0
- -- for l=1,#list do
- -- local ll = list[l]
- -- local p = ll.__p__
- -- local d = p.dt
- -- for i=ll.ni-1,1,-1 do
- -- local di = d[i]
- -- if type(di) == "table" then
- -- c = c + 1
- -- collected[c] = di
- -- break
- -- end
- -- end
- -- end
- -- return collected
+--~ local collected, c = { }, 0
+--~ for l=1,#list do
+--~ local ll = list[l]
+--~ local p = ll.__p__
+--~ local d = p.dt
+--~ for i=ll.ni-1,1,-1 do
+--~ local di = d[i]
+--~ if type(di) == "table" then
+--~ c = c + 1
+--~ collected[c] = di
+--~ break
+--~ end
+--~ end
+--~ end
+--~ return collected
return { }
end
apply_axis['following-sibling'] = function(list)
- local collected = { }
- local c = 0
+ local collected, c = { }, 0
for l=1,#list do
local ll = list[l]
local p = ll.__p__
@@ -411,8 +356,7 @@ apply_axis['following-sibling'] = function(list)
end
apply_axis['preceding-sibling'] = function(list)
- local collected = { }
- local c = 0
+ local collected, c = { }, 0
for l=1,#list do
local ll = list[l]
local p = ll.__p__
@@ -429,8 +373,7 @@ apply_axis['preceding-sibling'] = function(list)
end
apply_axis['reverse-sibling'] = function(list) -- reverse preceding
- local collected = { }
- local c = 0
+ local collected, c = { }, 0
for l=1,#list do
local ll = list[l]
local p = ll.__p__
@@ -457,8 +400,7 @@ local function apply_nodes(list,directive,nodes)
-- ... currently ignored
local maxn = #nodes
if maxn == 3 then --optimized loop
- local nns = nodes[2]
- local ntg = nodes[3]
+ local nns, ntg = nodes[2], nodes[3]
if not nns and not ntg then -- wildcard
if directive then
return list
@@ -466,47 +408,40 @@ local function apply_nodes(list,directive,nodes)
return { }
end
else
- local collected = { }
- local c = 0
- local m = 0
- local p = nil
+ local collected, c, m, p = { }, 0, 0, nil
if not nns then -- only check tag
for l=1,#list do
- local ll = list[l]
+ local ll = list[l]
local ltg = ll.tg
if ltg then
if directive then
if ntg == ltg then
- local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end
+ local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end
c = c + 1
- collected[c] = ll
- ll.mi = m
+ collected[c], ll.mi = ll, m
end
elseif ntg ~= ltg then
- local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end
+ local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end
c = c + 1
- collected[c] = ll
- ll.mi = m
+ collected[c], ll.mi = ll, m
end
end
end
elseif not ntg then -- only check namespace
for l=1,#list do
- local ll = list[l]
+ local ll = list[l]
local lns = ll.rn or ll.ns
if lns then
if directive then
if lns == nns then
- local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end
+ local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end
c = c + 1
- collected[c] = ll
- ll.mi = m
+ collected[c], ll.mi = ll, m
end
elseif lns ~= nns then
- local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end
+ local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end
c = c + 1
- collected[c] = ll
- ll.mi = m
+ collected[c], ll.mi = ll, m
end
end
end
@@ -519,16 +454,14 @@ local function apply_nodes(list,directive,nodes)
local ok = ltg == ntg and lns == nns
if directive then
if ok then
- local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end
+ local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end
c = c + 1
- collected[c] = ll
- ll.mi = m
+ collected[c], ll.mi = ll, m
end
elseif not ok then
- local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end
+ local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end
c = c + 1
- collected[c] = ll
- ll.mi = m
+ collected[c], ll.mi = ll, m
end
end
end
@@ -536,19 +469,15 @@ local function apply_nodes(list,directive,nodes)
return collected
end
else
- local collected = { }
- local c = 0
- local m = 0
- local p = nil
+ local collected, c, m, p = { }, 0, 0, nil
for l=1,#list do
- local ll = list[l]
+ local ll = list[l]
local ltg = ll.tg
if ltg then
local lns = ll.rn or ll.ns
- local ok = false
+ local ok = false
for n=1,maxn,3 do
- local nns = nodes[n+1]
- local ntg = nodes[n+2]
+ local nns, ntg = nodes[n+1], nodes[n+2]
ok = (not ntg or ltg == ntg) and (not nns or lns == nns)
if ok then
break
@@ -556,16 +485,14 @@ local function apply_nodes(list,directive,nodes)
end
if directive then
if ok then
- local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end
+ local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end
c = c + 1
- collected[c] = ll
- ll.mi = m
+ collected[c], ll.mi = ll, m
end
elseif not ok then
- local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end
+ local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end
c = c + 1
- collected[c] = ll
- ll.mi = m
+ collected[c], ll.mi = ll, m
end
end
end
@@ -576,8 +503,7 @@ end
local quit_expression = false
local function apply_expression(list,expression,order)
- local collected = { }
- local c = 0
+ local collected, c = { }, 0
quit_expression = false
for l=1,#list do
local ll = list[l]
@@ -974,8 +900,7 @@ local function tagstostring(list)
local t = { }
for i=1, #list do
local li = list[i]
- local ns = li.ns
- local tg = li.tg
+ local ns, tg = li.ns, li.tg
if not ns or ns == "" then ns = "*" end
if not tg or tg == "" then tg = "*" end
t[i] = (tg == "@rt@" and "[root]") or format("%s:%s",ns,tg)
@@ -1440,8 +1365,7 @@ expressions.name = function(e,n) -- ns + tg
if n == 0 then
found = type(e) == "table" and e
elseif n < 0 then
- local d = e.__p__.dt
- local k = e.ni
+ local d, k = e.__p__.dt, e.ni
for i=k-1,1,-1 do
local di = d[i]
if type(di) == "table" then
@@ -1454,8 +1378,7 @@ expressions.name = function(e,n) -- ns + tg
end
end
else
- local d = e.__p__.dt
- local k = e.ni
+ local d, k = e.__p__.dt, e.ni
for i=k+1,#d,1 do
local di = d[i]
if type(di) == "table" then
@@ -1469,8 +1392,7 @@ expressions.name = function(e,n) -- ns + tg
end
end
if found then
- local ns = found.rn or found.ns or ""
- local tg = found.tg
+ local ns, tg = found.rn or found.ns or "", found.tg
if ns ~= "" then
return ns .. ":" .. tg
else
@@ -1490,8 +1412,7 @@ expressions.tag = function(e,n) -- only tg
if n == 0 then
found = (type(e) == "table") and e -- seems to fail
elseif n < 0 then
- local d = e.__p__.dt
- local k = e.ni
+ local d, k = e.__p__.dt, e.ni
for i=k-1,1,-1 do
local di = d[i]
if type(di) == "table" then
@@ -1504,8 +1425,7 @@ expressions.tag = function(e,n) -- only tg
end
end
else
- local d = e.__p__.dt
- local k = e.ni
+ local d, k = e.__p__.dt, e.ni
for i=k+1,#d,1 do
local di = d[i]
if type(di) == "table" then
@@ -1672,8 +1592,8 @@ end
-- local w = lpeg.patterns.whitespace
-- local p = w^0 * lpeg.Cf(lpeg.Ct("") * lpeg.Cg(lpeg.C((1-w)^1) * lpeg.Cc(true) * w^0)^1,rawset)
--- function xml.functions.classes(e,class) -- cache
--- class = class and e.at[class] or e.at.class
+-- function xml.functions.classes(e) -- cache
+-- local class = e.at.class
-- if class then
-- return lpegmatch(p,class)
-- else