summaryrefslogtreecommitdiff
path: root/tex/context/base/util-seq.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/util-seq.lua')
-rw-r--r--tex/context/base/util-seq.lua45
1 files changed, 32 insertions, 13 deletions
diff --git a/tex/context/base/util-seq.lua b/tex/context/base/util-seq.lua
index 35e693285..08fc4e95c 100644
--- a/tex/context/base/util-seq.lua
+++ b/tex/context/base/util-seq.lua
@@ -17,13 +17,15 @@ use locals to refer to them when compiling the chain.</p>
-- todo: protect groups (as in tasks)
-local format, gsub, concat, gmatch = string.format, string.gsub, table.concat, string.gmatch
+local gsub, concat, gmatch = string.gsub, table.concat, string.gmatch
local type, load = type, load
utilities = utilities or { }
local tables = utilities.tables
local allocate = utilities.storage.allocate
+local formatters = string.formatters
+
local sequencers = { }
utilities.sequencers = sequencers
@@ -31,6 +33,7 @@ local functions = allocate()
sequencers.functions = functions
local removevalue = tables.removevalue
+local replacevalue = tables.replacevalue
local insertaftervalue = tables.insertaftervalue
local insertbeforevalue = tables.insertbeforevalue
@@ -189,6 +192,18 @@ function sequencers.removeaction(t,group,action,force)
end
end
+function sequencers.replaceaction(t,group,oldaction,newaction,force)
+ t = known[t]
+ if t then
+ local g = t.list[group]
+ if g and (force or validaction(oldaction)) then
+ replacevalue(g,oldaction,newaction)
+ t.dirty = true
+ t.runner = nil
+ end
+ end
+end
+
local function localize(str)
return (gsub(str,"[%.: ]+","_"))
end
@@ -204,20 +219,23 @@ local function construct(t)
for i=1,#actions do
local action = actions[i]
if not askip[action] then
+ local localized
if type(action) == "function" then
local name = localize(tostring(action))
functions[name] = action
- action = format("utilities.sequencers.functions.%s",name)
+ action = formatters["utilities.sequencers.functions.%s"](name)
+ localized = localize(name) -- shorter than action
+ else
+ localized = localize(action)
end
- local localized = localize(action)
n = n + 1
- variables[n] = format("local %s = %s",localized,action)
+ variables[n] = formatters["local %s = %s"](localized,action)
if not returnvalues then
- calls[n] = format("%s(%s)",localized,arguments)
+ calls[n] = formatters["%s(%s)"](localized,arguments)
elseif n == 1 then
- calls[n] = format("local %s = %s(%s)",returnvalues,localized,arguments)
+ calls[n] = formatters["local %s = %s(%s)"](returnvalues,localized,arguments)
else
- calls[n] = format("%s = %s(%s)",returnvalues,localized,arguments)
+ calls[n] = formatters["%s = %s(%s)"](returnvalues,localized,arguments)
end
end
end
@@ -230,9 +248,9 @@ local function construct(t)
variables = concat(variables,"\n")
calls = concat(calls,"\n")
if results then
- t.compiled = format("%s\nreturn function(%s)\n%s\nreturn %s\nend",variables,arguments,calls,results)
+ t.compiled = formatters["%s\nreturn function(%s)\n%s\nreturn %s\nend"](variables,arguments,calls,results)
else
- t.compiled = format("%s\nreturn function(%s)\n%s\nend",variables,arguments,calls)
+ t.compiled = formatters["%s\nreturn function(%s)\n%s\nend"](variables,arguments,calls)
end
end
-- print(t.compiled)
@@ -258,6 +276,7 @@ compile = function(t,compiler,n) -- already referred to in sequencers.new
if compiled == "" then
runner = false
else
+-- inspect(compiled)
runner = compiled and load(compiled)() -- we can use loadstripped here
end
t.runner = runner
@@ -314,12 +333,12 @@ function sequencers.nodeprocessor(t,nofarguments) -- todo: handle 'kind' in plug
if not askip[action] then
local localized = localize(action)
n = n + 1
- vars[n] = format("local %s = %s",localized,action)
+ vars[n] = formatters["local %s = %s"](localized,action)
-- only difference with tostring is kind and rets (why no return)
if kind[action] == "nohead" then
- calls[n] = format(" ok = %s(head%s) done = done or ok",localized,args)
+ calls[n] = formatters[" ok = %s(head%s) done = done or ok"](localized,args)
else
- calls[n] = format(" head, ok = %s(head%s) done = done or ok",localized,args)
+ calls[n] = formatters[" head, ok = %s(head%s) done = done or ok"](localized,args)
end
-- local s = " print('" .. tostring(group) .. " " .. tostring(action) .. " : ' .. tostring(head)) "
-- calls[n] = s .. calls[n] .. s
@@ -327,6 +346,6 @@ function sequencers.nodeprocessor(t,nofarguments) -- todo: handle 'kind' in plug
end
end
end
- local processor = #calls > 0 and format(template_yes,concat(vars,"\n"),args,concat(calls,"\n")) or template_nop
+ local processor = #calls > 0 and formatters[template_yes](concat(vars,"\n"),args,concat(calls,"\n")) or template_nop
return processor
end