summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/strc-lst.lua
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2010-05-24 14:05:02 +0000
committerTaco Hoekwater <taco@elvenkind.com>2010-05-24 14:05:02 +0000
commit57ea7dad48fbf2541c04e434c31bde655ada3ac4 (patch)
tree1f8b43bc7cb92939271e1f5bec610710be69097f /Master/texmf-dist/tex/context/base/strc-lst.lua
parent6ee41e1f1822657f7f23231ec56c0272de3855e3 (diff)
here is context 2010.05.24 13:05
git-svn-id: svn://tug.org/texlive/trunk@18445 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-lst.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/strc-lst.lua255
1 files changed, 164 insertions, 91 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-lst.lua b/Master/texmf-dist/tex/context/base/strc-lst.lua
index dd45e7f689d..fefbe52ce29 100644
--- a/Master/texmf-dist/tex/context/base/strc-lst.lua
+++ b/Master/texmf-dist/tex/context/base/strc-lst.lua
@@ -1,6 +1,6 @@
if not modules then modules = { } end modules ['strc-lst'] = {
version = 1.001,
- comment = "companion to strc-lst.tex",
+ comment = "companion to strc-lst.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
@@ -11,9 +11,13 @@ if not modules then modules = { } end modules ['strc-lst'] = {
-- section, metadata cache (internal then has to move up one level) or a
-- shared cache [we can use a fast and stupid serializer]
-local format, tonumber = string.format, tonumber
+local format, gmatch, gsub = string.format, string.gmatch, string.gsub
+local tonumber = tonumber
local texsprint, texprint, texwrite, texcount = tex.sprint, tex.print, tex.write, tex.count
-local insert, remove = table.insert, table.remove
+local concat, insert, remove = table.concat, table.insert, table.remove
+local lpegmatch = lpeg.match
+
+local trace_lists = false trackers.register("structure.lists", function(v) trace_lists = v end)
local ctxcatcodes = tex.ctxcatcodes
@@ -36,6 +40,7 @@ lists.internals = lists.internals or { }
lists.ordered = lists.ordered or { }
local variables = interfaces.variables
+local matching_till_depth, number_at_depth = sections.matching_till_depth, sections.number_at_depth
local function initializer()
-- create a cross reference between internal references
@@ -76,8 +81,7 @@ if job then
job.register('structure.lists.collected', structure.lists.tobesaved, initializer)
end
-local cached = { }
-local pushed = { }
+local cached, pushed = { }, { }
function lists.push(t)
local r = t.references
@@ -103,7 +107,7 @@ function lists.enhance(n)
if l then
--
l.directives = nil -- might change
- -- save in the right order (happen sat shipout)
+ -- save in the right order (happens at shipout)
lists.tobesaved[#lists.tobesaved+1] = l
-- default enhancer (cross referencing)
l.references.realpage = texcount.realpageno
@@ -125,7 +129,7 @@ function lists.pushnesting(i)
local name = r.metadata.name
local numberdata = r and r.numberdata
local n = (numberdata and numberdata.numbers[sections.getlevel(name)]) or 0
- insert(nesting, { number = n, name = name, result = lists.result })
+ insert(nesting, { number = n, name = name, result = lists.result, parent = r })
end
function lists.popnesting()
@@ -133,15 +137,30 @@ function lists.popnesting()
lists.result = old.result
end
-local function filter_collected(names, criterium, number, collected)
+-- will be split
+
+local function filter_collected(names, criterium, number, collected, nested)
local numbers, depth = documents.data.numbers, documents.data.depth
- local hash, result, all = { }, { }, not names or names == "" or names == variables.all
+ local hash, result, all, detail = { }, { }, not names or names == "" or names == variables.all, nil
+ names, criterium = gsub(names," ",""), gsub(criterium," ","")
+ if trace_lists then
+ logs.report("lists","filtering names: %s, criterium: %s, number: %s",names,criterium,number or "-")
+ end
if not all then
- for s in names:gmatch("[^, ]+") do
+ for s in gmatch(names,"[^, ]+") do -- sort of settings to hash
hash[s] = true
end
end
- if criterium == variables.all or criterium == variables.text then
+ if criterium == variables.intro then
+ -- special case, no structure yet
+ for i=1,#collected do
+ local v = collected[i]
+ local r = v.references
+ if r and r.section == 0 then
+ result[#result+1] = v
+ end
+ end
+ elseif criterium == variables.all or criterium == variables.text then
for i=1,#collected do
local v = collected[i]
local r = v.references
@@ -156,26 +175,30 @@ local function filter_collected(names, criterium, number, collected)
end
end
elseif criterium == variables.current then
- for i=1,#collected do
- local v = collected[i]
- local r = v.references
- if r then
- local sectionnumber = jobsections.collected[r.section]
- if sectionnumber then -- and not sectionnumber.hidenumber then
- local cnumbers = sectionnumber.numbers
- local metadata = v.metadata
- if cnumbers then
- if metadata and not metadata.nolist and (all or hash[metadata.name or false]) and #cnumbers > depth then
- local ok = true
- for d=1,depth do
- local cnd = cnumbers[d]
- if not (cnd == 0 or cnd == numbers[d]) then
- ok = false
- break
+ if depth == 0 then
+ return filter_collected(names,variables.intro,number,collected)
+ else
+ for i=1,#collected do
+ local v = collected[i]
+ local r = v.references
+ if r then
+ local sectionnumber = jobsections.collected[r.section]
+ if sectionnumber then -- and not sectionnumber.hidenumber then
+ local cnumbers = sectionnumber.numbers
+ local metadata = v.metadata
+ if cnumbers then
+ if metadata and not metadata.nolist and (all or hash[metadata.name or false]) and #cnumbers > depth then
+ local ok = true
+ for d=1,depth do
+ local cnd = cnumbers[d]
+ if not (cnd == 0 or cnd == numbers[d]) then
+ ok = false
+ break
+ end
+ end
+ if ok then
+ result[#result+1] = v
end
- end
- if ok then
- result[#result+1] = v
end
end
end
@@ -183,26 +206,32 @@ local function filter_collected(names, criterium, number, collected)
end
end
elseif criterium == variables.here then
- for i=1,#collected do
- local v = collected[i]
- local r = v.references
- if r then
- local sectionnumber = jobsections.collected[r.section]
- if sectionnumber then -- and not sectionnumber.hidenumber then
- local cnumbers = sectionnumber.numbers
- local metadata = v.metadata
- if cnumbers then
- if metadata and not metadata.nolist and (all or hash[metadata.name or false]) and #cnumbers >= depth then
- local ok = true
- for d=1,depth do
- local cnd = cnumbers[d]
- if not (cnd == 0 or cnd == numbers[d]) then
- ok = false
- break
+ -- this is quite dirty ... as cnumbers is not sparse we can misuse #cnumbers
+ if depth == 0 then
+ return filter_collected(names,variables.intro,number,collected)
+ else
+ for i=1,#collected do
+ local v = collected[i]
+ local r = v.references
+ if r then
+ local sectionnumber = jobsections.collected[r.section]
+ if sectionnumber then -- and not sectionnumber.hidenumber then
+ local cnumbers = sectionnumber.numbers
+ local metadata = v.metadata
+ if cnumbers then
+--~ print(#cnumbers, depth, table.concat(cnumbers))
+ if metadata and not metadata.nolist and (all or hash[metadata.name or false]) and #cnumbers >= depth then
+ local ok = true
+ for d=1,depth do
+ local cnd = cnumbers[d]
+ if not (cnd == 0 or cnd == numbers[d]) then
+ ok = false
+ break
+ end
+ end
+ if ok then
+ result[#result+1] = v
end
- end
- if ok then
- result[#result+1] = v
end
end
end
@@ -210,26 +239,30 @@ local function filter_collected(names, criterium, number, collected)
end
end
elseif criterium == variables.previous then
- for i=1,#collected do
- local v = collected[i]
- local r = v.references
- if r then
- local sectionnumber = jobsections.collected[r.section]
- if sectionnumber then -- and not sectionnumber.hidenumber then
- local cnumbers = sectionnumber.numbers
- local metadata = v.metadata
- if cnumbers then
- if metadata and not metadata.nolist and (all or hash[metadata.name or false]) and #cnumbers >= depth then
- local ok = true
- for d=1,depth-1 do
- local cnd = cnumbers[d]
- if not (cnd == 0 or cnd == numbers[d]) then
- ok = false
- break
+ if depth == 0 then
+ return filter_collected(names,variables.intro,number,collected)
+ else
+ for i=1,#collected do
+ local v = collected[i]
+ local r = v.references
+ if r then
+ local sectionnumber = jobsections.collected[r.section]
+ if sectionnumber then -- and not sectionnumber.hidenumber then
+ local cnumbers = sectionnumber.numbers
+ local metadata = v.metadata
+ if cnumbers then
+ if metadata and not metadata.nolist and (all or hash[metadata.name or false]) and #cnumbers >= depth then
+ local ok = true
+ for d=1,depth-1 do
+ local cnd = cnumbers[d]
+ if not (cnd == 0 or cnd == numbers[d]) then
+ ok = false
+ break
+ end
+ end
+ if ok then
+ result[#result+1] = v
end
- end
- if ok then
- result[#result+1] = v
end
end
end
@@ -239,33 +272,47 @@ local function filter_collected(names, criterium, number, collected)
elseif criterium == variables["local"] then -- not yet ok
local nested = nesting[#nesting]
if nested then
- return filter_collected(names,nested.name,nested.number,collected)
+ return filter_collected(names,nested.name,nested.number,collected,nested)
elseif sections.autodepth(documents.data.numbers) == 0 then
return filter_collected(names,variables.all,number,collected)
else
return filter_collected(names,variables.current,number,collected)
end
else -- sectionname, number
+ -- not the same as register
local depth = sections.getlevel(criterium)
- local number = tonumber(number) or 0
- for i=1,#collected do
- local v = collected[i]
- local r = v.references
- if r then
- local sectionnumber = jobsections.collected[r.section]
- if sectionnumber then -- and not sectionnumber.hidenumber then
- local cnumbers = sectionnumber.numbers
- local metadata = v.metadata
- if cnumbers then
--- if metadata and not metadata.nolist and (all or hash[metadata.name or false]) and #cnumbers >= depth and cnumbers[depth] == number then
- if metadata and not metadata.nolist and (all or hash[metadata.name or false]) and #cnumbers >= depth and (number == 0 or cnumbers[depth] == number) then
- result[#result+1] = v
+ local number = tonumber(number) or number_at_depth(depth) or 0
+ if trace_lists then
+ local t = sections.numbers()
+ detail = format("depth: %s, number: %s, numbers: %s, startset: %s",depth,number,(#t>0 and concat(t,".",1,depth)) or "?",#collected)
+ end
+ if number > 0 then
+ local parent = nested and nested.parent and nested.parent.numberdata.numbers -- so local as well as nested
+ for i=1,#collected do
+ local v = collected[i]
+ local r = v.references
+ if r then
+ local sectionnumber = jobsections.collected[r.section]
+ if sectionnumber then
+ local metadata = v.metadata
+ local cnumbers = sectionnumber.numbers
+ if cnumbers then
+ if (all or hash[metadata.name or false]) and #cnumbers >= depth and matching_till_depth(depth,cnumbers,parent) then
+ result[#result+1] = v
+ end
end
end
end
end
end
end
+ if trace_lists then
+ if detail then
+ logs.report("lists","criterium: %s, %s, found: %s",criterium,detail,#result)
+ else
+ logs.report("lists","criterium: %s, found: %s",criterium,#result)
+ end
+ end
return result
end
@@ -283,6 +330,7 @@ function lists.process(...)
local r = lists.result[i]
local m = r.metadata
texsprint(ctxcatcodes,format("\\processlistofstructure{%s}{%s}{%i}",m.name,m.kind,i))
+--~ context.processlistofstructure(m.name,m.kind,i)
end
end
@@ -290,12 +338,14 @@ function lists.analyze(...)
lists.result = lists.filter(...)
end
-function lists.userdata(name,r,tag) -- to tex
- local str = lists.result[r]
- str = str and str.userdata
- str = str and str[tag]
- if str then
- texsprint(ctxcatcodes,str)
+function lists.userdata(name,r,tag) -- to tex (todo: xml)
+ local result = lists.result[r]
+ if result then
+ local userdata, metadata = result.userdata, result.metadata
+ local str = userdata and userdata[tag]
+ if str then
+ texsprint(metadata and metadata.catcodes or ctxcatcodes,str)
+ end
end
end
@@ -310,7 +360,7 @@ function lists.size()
texprint(#lists.result)
end
-function lists.location(name,n)
+function lists.location(n)
local l = lists.result[n]
texsprint(l.references.internal or n)
end
@@ -330,7 +380,6 @@ function lists.title(name,n,tag) -- tag becomes obsolete
local titledata = data.titledata
if titledata then
helpers.title(titledata[tag] or titledata.list or titledata.title or "",data.metadata)
---~ texsprint(ctxcatcodes,titledata[tag] or titledata.list or titledata.title or "")
end
end
end
@@ -362,6 +411,7 @@ function lists.savedprefixednumber(name,n)
helpers.prefix(data,data.prefixdata)
local numberdata = data.numberdata
if numberdata then
+--~ print(name,n,table.serialize(numberdata))
sections.typesetnumber(numberdata,"number",numberdata or false)
end
end
@@ -407,7 +457,30 @@ function lists.prefixednumber(name,n,prefixspec,numberspec)
helpers.prefix(data,prefixspec)
local numberdata = data.numberdata
if numberdata then
- sections.typesetnumber(numberdata,"number",spec or false,numberdata or false)
+--~ print(table.serialize(numberspec))
+ sections.typesetnumber(numberdata,"number",numberspec or false,numberdata or false)
+ end
+ end
+end
+
+-- todo, do this in references namespace ordered instead (this is an experiment)
+--
+-- also see lpdf-ano (maybe move this there)
+
+local splitter = lpeg.splitat(":")
+
+function jobreferences.specials.order(var,actions) -- jobreferences.specials !
+ local operation = var.operation
+ if operation then
+ local kind, name, n = lpegmatch(splitter,operation)
+ local order = lists.ordered[kind]
+ order = order and order[name]
+ local v = order[tonumber(n)]
+ local r = v and v.references.realpage
+ if r then
+ actions.realpage = r
+ var.operation = r -- brrr, but test anyway
+ return jobreferences.specials.page(var,actions)
end
end
end