summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/strc-ini.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-ini.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/strc-ini.lua143
1 files changed, 91 insertions, 52 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-ini.lua b/Master/texmf-dist/tex/context/base/strc-ini.lua
index 61c26a20eed..a9013c641a3 100644
--- a/Master/texmf-dist/tex/context/base/strc-ini.lua
+++ b/Master/texmf-dist/tex/context/base/strc-ini.lua
@@ -24,60 +24,76 @@ local format, concat, match = string.format, table.concat, string.match
local count, texwrite, texprint, texsprint = tex.count, tex.write, tex.print, tex.sprint
local type, next, tonumber, tostring = type, next, tonumber, tostring
local lpegmatch = lpeg.match
+local settings_to_array, settings_to_hash = utilities.parsers.settings_to_array, utilities.parsers.settings_to_hash
+local allocate = utilities.storage.allocate
local ctxcatcodes, xmlcatcodes, notcatcodes = tex.ctxcatcodes, tex.xmlcatcodes, tex.notcatcodes -- tricky as we're in notcatcodes
-local trace_processors = false trackers.register("structure.processors", function(v) trace_processors = v end)
+local trace_processors = false trackers.register("structures.processors", function(v) trace_processors = v end)
+
+local report_processors = logs.reporter("structure","processors")
-- move this
-commands = commands or { }
+commands = commands or { }
+local commands = commands
-function commands.first_in_list(str)
+function commands.firstinlist(str)
local first = match(str,"^([^,]+),")
texsprint(ctxcatcodes,first or str)
end
-- -- -- namespace -- -- --
-structure = structure or { }
-
--- -- -- cache -- -- --
-
-structure.shares = structure.shares or { }
-structure.shares.cache = structure.shares.cache or { }
-
-local shares = structure.shares
-local cache = shares.cache
-
-function shares.put(data)
- cache[#cache+1] = data
- return #cache
-end
-
-function shares.get(n) -- n can be string
- n = tonumber(n) or -1
- return cache[n]
-end
+-- This is tricky: we have stored and initialized already some of
+-- the job.registered tables so we have a forward reference!
+
+structures = structures or { }
+local structures = structures
+
+structures.blocks = structures.blocks or { }
+structures.sections = structures.sections or { }
+structures.pages = structures.pages or { }
+structures.registers = structures.registers or { }
+structures.references = structures.references or { }
+structures.lists = structures.lists or { }
+structures.helpers = structures.helpers or { }
+structures.processors = structures.processors or { }
+structures.documents = structures.documents or { }
+structures.notes = structures.notes or { }
+structures.descriptions = structures.descriptions or { }
+structures.itemgroups = structures.itemgroups or { }
+structures.specials = structures.specials or { }
+structures.counters = structures.counters or { }
+structures.tags = structures.tags or { }
+structures.formulas = structures.formulas or { }
+structures.sets = structures.sets or { }
+structures.marks = structures.marks or { }
+structures.floats = structures.floats or { }
+structures.synonyms = structures.synonyms or { }
+
+--~ table.print(structures)
-- -- -- specials -- -- --
-- we can store information and get back a reference; this permits
-- us to store rather raw data in references
-local specials = { } structure.specials = specials
+local specials = structures.specials
-specials.collected = specials.collected or { }
-specials.tobesaved = specials.collected or { }
+local collected = allocate()
+local tobesaved = allocate()
-local collected, tobesaved = specials.collected, specials.tobesaved
+specials.collected = collected
+specials.tobesaved = tobesaved
local function initializer()
- collected, tobesaved = specials.collected, specials.tobesaved
+ collected = specials.collected
+ tobesaved = specials.tobesaved
end
if job then
- job.register('structure.specials.collected', structure.specials.tobesaved, initializer)
+ job.register('structures.specials.collected', tobesaved, initializer)
end
function specials.store(class,data)
@@ -103,12 +119,10 @@ end
-- -- -- helpers -- -- --
-structure.helpers = structure.helpers or { }
-
-local helpers = structure.helpers
+local helpers = structures.helpers
function helpers.touserdata(str)
- local hash = str and str ~= "" and aux.settings_to_hash(str)
+ local hash = str and str ~= "" and settings_to_hash(str)
if hash and next(hash) then
return hash
end
@@ -129,8 +143,6 @@ local function simplify(d,nodefault)
t[k] = v
end
end
---~ print(table.serialize(d,"before"))
---~ print(table.serialize(t,"after"))
return next(t) and t
elseif nodefault then
return nil
@@ -158,21 +170,43 @@ local tags = {
entry = "ctx:registerentry",
}
-function helpers.title(title,metadata) -- brrr
- if title and title ~= "" then
+-- We had the following but it overloads the main document so it's a no-go as we
+-- no longer push and pop. So now we use the tag as buffername, namespace and also
+-- (optionally) as a setups to be applied but keep in mind that document setups
+-- also get applied (when they use #1's).
+--
+-- local command = format("\\xmlprocessbuffer{%s}{%s}{}",metadata.xmlroot or "main",tag)
+
+function helpers.title(title,metadata) -- coding is xml is rather old and not that much needed now
+ if title and title ~= "" then -- so it might disappear
if metadata then
+ local xmlsetup = metadata.xmlsetup
if metadata.coding == "xml" then
- tag = tags[metadata.kind] or tags.generic
- buffers.set(tag,format("<?xml version='1.0'?><%s>%s</%s>",tag,title,tag))
- texsprint(ctxcatcodes,format("\\xmlprocessbuffer{%s}{%s}{}",metadata.xmlroot or "main",tag))
- elseif metadata.xmlsetup then
- texsprint(ctxcatcodes,format("\\xmlsetup{%s}{%s}",title,metadata.xmlsetup)) -- nasty
+ -- title can contain raw xml
+ local tag = tags[metadata.kind] or tags.generic
+ local xmldata = format("<?xml version='1.0'?><%s>%s</%s>",tag,title,tag)
+ buffers.assign(tag,xmldata)
+ if trace_processors then
+ report_processors("putting xml data in buffer: %s",xmldata)
+ report_processors("processing buffer with setup '%s' and tag '%s'",xmlsetup or "",tag)
+ end
+ context.xmlprocessbuffer("dummy",tag,xmlsetup or "")
+ elseif xmlsetup then -- title is reference to node (so \xmlraw should have been used)
+ if trace_processors then
+ report_processors("feeding xmlsetup '%s' using node '%s'",xmlsetup,title)
+ end
+ context.xmlsetup(title,metadata.xmlsetup)
else
local catcodes = metadata.catcodes
---~ print(tex.ctxcatcodes,tex.xmlcatcodes,catcodes,title)
if catcodes == notcatcodes or catcodes == xmlcatcodes then
- texsprint(ctxcatcodes,title) -- nasty
+ if trace_processors then
+ report_processors("cct: %s (overloads %s), txt: %s",ctxcatcodes,catcodes,title)
+ end
+ context(title) -- nasty
else
+ if trace_processors then
+ report_processors("cct: %s, txt: %s",catcodes,title)
+ end
texsprint(catcodes,title)
end
end
@@ -182,9 +216,9 @@ function helpers.title(title,metadata) -- brrr
end
end
--- -- -- processors -- -- -- syntax: processor->data
+-- -- -- processors -- -- -- syntax: processor->data ... not ok yet
-local processors = { } structure.processors = processors
+local processors = structures.processors
local registered = { }
@@ -207,7 +241,7 @@ function processors.split(str)
end
end
-function processors.sprint(catcodes,str,fnc,...)
+function processors.sprint(catcodes,str,fnc,...) -- not ok: mixed
local p, s = lpegmatch(splitter,str)
local code
if registered[p] then
@@ -216,7 +250,7 @@ function processors.sprint(catcodes,str,fnc,...)
code = (fnc and fnc(str,...)) or str
end
if trace_processors then
- logs.report("processors","cct: %s, seq: %s",catcodes,code)
+ report_processors("cct: %s, seq: %s",catcodes,code)
end
texsprint(catcodes,code)
end
@@ -230,14 +264,19 @@ function processors.apply(str)
end
end
+function processors.ignore(str)
+ local p, s = lpegmatch(splitter,str)
+ return s or str
+end
+
-- -- -- sets -- -- --
-structure.sets = structure.sets or { }
-structure.sets.setlist = structure.sets.setlist or { }
+local sets = structures.sets
+
+sets.setlist = sets.setlist or { }
-storage.register("structure/sets/setlist", structure.sets.setlist, "structure.sets.setlist")
+storage.register("structures/sets/setlist", structures.sets.setlist, "structures.sets.setlist")
-local sets = structure.sets
local setlist = sets.setlist
function sets.define(namespace,name,values,default,numbers)
@@ -249,7 +288,7 @@ function sets.define(namespace,name,values,default,numbers)
if values == "" then
dn[name] = { { }, default }
else
- local split = aux.settings_to_array(values)
+ local split = settings_to_array(values)
if numbers then
-- convert to numbers (e.g. for reset)
for i=1,#split do