diff options
Diffstat (limited to 'tex/context/base/mkiv/lxml-lpt.lua')
-rw-r--r-- | tex/context/base/mkiv/lxml-lpt.lua | 115 |
1 files changed, 74 insertions, 41 deletions
diff --git a/tex/context/base/mkiv/lxml-lpt.lua b/tex/context/base/mkiv/lxml-lpt.lua index a80a33f42..392c1a401 100644 --- a/tex/context/base/mkiv/lxml-lpt.lua +++ b/tex/context/base/mkiv/lxml-lpt.lua @@ -166,7 +166,8 @@ apply_axis['self'] = function(list) end apply_axis['child'] = function(list) - local collected, c = { }, 0 + local collected = { } + local c = 0 for l=1,#list do local ll = list[l] local dt = ll.dt @@ -240,7 +241,8 @@ local function collect(list,collected,c) end apply_axis['descendant'] = function(list) - local collected, c = { }, 0 + local collected = { } + local c = 0 for l=1,#list do c = collect(list[l],collected,c) end @@ -283,7 +285,8 @@ local function collect(list,collected,c) end apply_axis['descendant-or-self'] = function(list) - local collected, c = { }, 0 + local collected = { } + local c = 0 for l=1,#list do local ll = list[l] if ll.special ~= true then -- catch double root @@ -296,7 +299,8 @@ apply_axis['descendant-or-self'] = function(list) end apply_axis['ancestor'] = function(list) - local collected, c = { }, 0 + local collected = { } + local c = 0 for l=1,#list do local ll = list[l] while ll do @@ -311,7 +315,8 @@ apply_axis['ancestor'] = function(list) end apply_axis['ancestor-or-self'] = function(list) - local collected, c = { }, 0 + local collected = { } + local c = 0 for l=1,#list do local ll = list[l] c = c + 1 @@ -328,7 +333,8 @@ apply_axis['ancestor-or-self'] = function(list) end apply_axis['parent'] = function(list) - local collected, c = { }, 0 + local collected = { } + local c = 0 for l=1,#list do local pl = list[l].__p__ if pl then @@ -367,7 +373,8 @@ apply_axis['following'] = function(list) -- incomplete end apply_axis['preceding'] = function(list) -- incomplete - -- local collected, c = { }, 0 + -- local collected = { } + -- local c = 0 -- for l=1,#list do -- local ll = list[l] -- local p = ll.__p__ @@ -386,7 +393,8 @@ apply_axis['preceding'] = function(list) -- incomplete end apply_axis['following-sibling'] = function(list) - local collected, c = { }, 0 + local collected = { } + local c = 0 for l=1,#list do local ll = list[l] local p = ll.__p__ @@ -403,7 +411,8 @@ apply_axis['following-sibling'] = function(list) end apply_axis['preceding-sibling'] = function(list) - local collected, c = { }, 0 + local collected = { } + local c = 0 for l=1,#list do local ll = list[l] local p = ll.__p__ @@ -420,7 +429,8 @@ apply_axis['preceding-sibling'] = function(list) end apply_axis['reverse-sibling'] = function(list) -- reverse preceding - local collected, c = { }, 0 + local collected = { } + local c = 0 for l=1,#list do local ll = list[l] local p = ll.__p__ @@ -447,7 +457,8 @@ local function apply_nodes(list,directive,nodes) -- ... currently ignored local maxn = #nodes if maxn == 3 then --optimized loop - local nns, ntg = nodes[2], nodes[3] + local nns = nodes[2] + local ntg = nodes[3] if not nns and not ntg then -- wildcard if directive then return list @@ -455,40 +466,47 @@ local function apply_nodes(list,directive,nodes) return { } end else - local collected, c, m, p = { }, 0, 0, nil + local collected = { } + local c = 0 + local m = 0 + local p = 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, m = llp, 1 else m = m + 1 end + local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end c = c + 1 - collected[c], ll.mi = ll, m + collected[c] = ll + ll.mi = m end elseif ntg ~= ltg then - local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end + local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end c = c + 1 - collected[c], ll.mi = ll, m + collected[c] = ll + ll.mi = 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, m = llp, 1 else m = m + 1 end + local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end c = c + 1 - collected[c], ll.mi = ll, m + collected[c] = ll + ll.mi = m end elseif lns ~= nns then - local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end + local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end c = c + 1 - collected[c], ll.mi = ll, m + collected[c] = ll + ll.mi = m end end end @@ -501,14 +519,16 @@ 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, m = llp, 1 else m = m + 1 end + local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end c = c + 1 - collected[c], ll.mi = ll, m + collected[c] = ll + ll.mi = m end elseif not ok then - local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end + local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end c = c + 1 - collected[c], ll.mi = ll, m + collected[c] = ll + ll.mi = m end end end @@ -516,15 +536,19 @@ local function apply_nodes(list,directive,nodes) return collected end else - local collected, c, m, p = { }, 0, 0, nil + local collected = { } + local c = 0 + local m = 0 + local p = 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, ntg = nodes[n+1], nodes[n+2] + local nns = nodes[n+1] + local ntg = nodes[n+2] ok = (not ntg or ltg == ntg) and (not nns or lns == nns) if ok then break @@ -532,14 +556,16 @@ local function apply_nodes(list,directive,nodes) end if directive then if ok then - local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end + local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end c = c + 1 - collected[c], ll.mi = ll, m + collected[c] = ll + ll.mi = m end elseif not ok then - local llp = ll.__p__ ; if llp ~= p then p, m = llp, 1 else m = m + 1 end + local llp = ll.__p__ ; if llp ~= p then p = llp ; m = 1 else m = m + 1 end c = c + 1 - collected[c], ll.mi = ll, m + collected[c] = ll + ll.mi = m end end end @@ -550,7 +576,8 @@ end local quit_expression = false local function apply_expression(list,expression,order) - local collected, c = { }, 0 + local collected = { } + local c = 0 quit_expression = false for l=1,#list do local ll = list[l] @@ -947,7 +974,8 @@ local function tagstostring(list) local t = { } for i=1, #list do local li = list[i] - local ns, tg = li.ns, li.tg + local ns = li.ns + local tg = 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) @@ -1412,7 +1440,8 @@ expressions.name = function(e,n) -- ns + tg if n == 0 then found = type(e) == "table" and e elseif n < 0 then - local d, k = e.__p__.dt, e.ni + local d = e.__p__.dt + local k = e.ni for i=k-1,1,-1 do local di = d[i] if type(di) == "table" then @@ -1425,7 +1454,8 @@ expressions.name = function(e,n) -- ns + tg end end else - local d, k = e.__p__.dt, e.ni + local d = e.__p__.dt + local k = e.ni for i=k+1,#d,1 do local di = d[i] if type(di) == "table" then @@ -1439,7 +1469,8 @@ expressions.name = function(e,n) -- ns + tg end end if found then - local ns, tg = found.rn or found.ns or "", found.tg + local ns = found.rn or found.ns or "" + local tg = found.tg if ns ~= "" then return ns .. ":" .. tg else @@ -1459,7 +1490,8 @@ 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, k = e.__p__.dt, e.ni + local d = e.__p__.dt + local k = e.ni for i=k-1,1,-1 do local di = d[i] if type(di) == "table" then @@ -1472,7 +1504,8 @@ expressions.tag = function(e,n) -- only tg end end else - local d, k = e.__p__.dt, e.ni + local d = e.__p__.dt + local k = e.ni for i=k+1,#d,1 do local di = d[i] if type(di) == "table" then |