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.lua140
1 files changed, 62 insertions, 78 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-ini.lua b/Master/texmf-dist/tex/context/base/strc-ini.lua
index a9013c641a3..c246ccd2762 100644
--- a/Master/texmf-dist/tex/context/base/strc-ini.lua
+++ b/Master/texmf-dist/tex/context/base/strc-ini.lua
@@ -20,28 +20,22 @@ but it does not make sense to store all processdata.
]]--
-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 format, concat = string.format, table.concat
local lpegmatch = lpeg.match
+local count = tex.count
+local type, next, tonumber = type, next, tonumber
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 ctxcatcodes = tex.ctxcatcodes
+local xmlcatcodes = tex.xmlcatcodes
+local notcatcodes = tex.notcatcodes
+local txtcatcodes = tex.txtcatcodes
-local trace_processors = false trackers.register("structures.processors", function(v) trace_processors = v end)
+local trace_processors = false
+local report_processors = logs.reporter("processors","structure")
-local report_processors = logs.reporter("structure","processors")
-
--- move this
-
-commands = commands or { }
-local commands = commands
-
-function commands.firstinlist(str)
- local first = match(str,"^([^,]+),")
- texsprint(ctxcatcodes,first or str)
-end
+trackers.register("typesetters.processors", function(v) trace_processors = v end)
-- -- -- namespace -- -- --
@@ -58,7 +52,6 @@ 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 { }
@@ -74,6 +67,8 @@ structures.synonyms = structures.synonyms or { }
--~ table.print(structures)
+local processors = typesetters.processors
+
-- -- -- specials -- -- --
-- we can store information and get back a reference; this permits
@@ -104,9 +99,9 @@ function specials.store(class,data)
tobesaved[class] = s
end
s[#s+1] = data
- texwrite(#s)
+ context(#s)
else
- texwrite(0)
+ context(0)
end
end
@@ -121,10 +116,23 @@ end
local helpers = structures.helpers
-function helpers.touserdata(str)
- local hash = str and str ~= "" and settings_to_hash(str)
- if hash and next(hash) then
- return hash
+-- function helpers.touserdata(str)
+-- local hash = str and str ~= "" and settings_to_hash(str)
+-- if hash and next(hash) then
+-- return hash
+-- end
+-- end
+
+function helpers.touserdata(data)
+ if type(data) == "string" then
+ if data == "" then
+ return nil
+ else
+ data = settings_to_hash(data)
+ end
+ end
+ if data and next(data) then
+ return data
end
end
@@ -177,6 +185,8 @@ local tags = {
--
-- local command = format("\\xmlprocessbuffer{%s}{%s}{}",metadata.xmlroot or "main",tag)
+local experiment = true
+
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
@@ -185,12 +195,21 @@ function helpers.title(title,metadata) -- coding is xml is rather old and not th
-- 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)
+if not experiment then
buffers.assign(tag,xmldata)
+end
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
+if experiment then
+ -- the question is: will this be forgotten ... better store in a via file
+ local xmltable = lxml.convert("temp",xmldata or "")
+ lxml.store("temp",xmltable)
+ context.xmlsetup("temp",xmlsetup or "")
+else
context.xmlprocessbuffer("dummy",tag,xmlsetup or "")
+end
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)
@@ -207,68 +226,15 @@ function helpers.title(title,metadata) -- coding is xml is rather old and not th
if trace_processors then
report_processors("cct: %s, txt: %s",catcodes,title)
end
- texsprint(catcodes,title)
+ context.sprint(catcodes,title) -- was: texsprint(catcodes,title)
end
end
else
- texsprint(title) -- no catcode switch
+ context(title) -- no catcode switch, was: texsprint(title)
end
end
end
--- -- -- processors -- -- -- syntax: processor->data ... not ok yet
-
-local processors = structures.processors
-
-local registered = { }
-
-function processors.register(p)
- registered[p] = true
-end
-
-function processors.reset(p)
- registered[p] = nil
-end
-
-local splitter = lpeg.splitat("->",true)
-
-function processors.split(str)
- local p, s = lpegmatch(splitter,str)
- if registered[p] then
- return p, s
- else
- return false, str
- end
-end
-
-function processors.sprint(catcodes,str,fnc,...) -- not ok: mixed
- local p, s = lpegmatch(splitter,str)
- local code
- if registered[p] then
- code = format("\\applyprocessor{%s}{%s}",p,(fnc and fnc(s,...)) or s)
- else
- code = (fnc and fnc(str,...)) or str
- end
- if trace_processors then
- report_processors("cct: %s, seq: %s",catcodes,code)
- end
- texsprint(catcodes,code)
-end
-
-function processors.apply(str)
- local p, s = lpegmatch(splitter,str)
- if registered[p] then
- return format("\\applyprocessor{%s}{%s}",p,s)
- else
- return str
- end
-end
-
-function processors.ignore(str)
- local p, s = lpegmatch(splitter,str)
- return s or str
-end
-
-- -- -- sets -- -- --
local sets = structures.sets
@@ -314,7 +280,20 @@ function sets.getall(namespace,block,name)
end
end
+-- messy (will be another keyword, fixedconversion)
+
+local splitter = lpeg.splitat("::")
+
function sets.get(namespace,block,name,level,default) -- check if name is passed
+ --fixed::R:a: ...
+ local kind, rest = lpegmatch(splitter,name)
+ if kind and rest then
+ if kind == "fixed" then
+ local s = settings_to_array(rest)
+ return s[level] or default
+ end
+ end
+ --
local ds = setlist[namespace]
if not ds then
return default
@@ -336,6 +315,11 @@ function sets.get(namespace,block,name,level,default) -- check if name is passed
if not dn then
return default
end
+-- inspect(dn)
local dl = dn[1][level]
return dl or dn[2] or default
end
+
+-- interface
+
+commands.definestructureset = sets.define