diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/cldf-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/cldf-ini.lua | 660 |
1 files changed, 258 insertions, 402 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/cldf-ini.lua b/Master/texmf-dist/tex/context/base/mkiv/cldf-ini.lua index e22de5a5b80..bb5a058a530 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/cldf-ini.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/cldf-ini.lua @@ -26,7 +26,7 @@ if not modules then modules = { } end modules ['cldf-ini'] = { -- 0.651 local foo = getcount("ctxcatcodes") -- 0.408 local foo = getcount(ctxcatcodes) -- local ctxcatcodes = tex.iscount("ctxcatcodes") --- maybe: (escape) or 0x2061 (apply function) or 0x2394 (software function ⎔) +-- maybe: (escape) or 0x2061 (apply function) or 0x2394 (software function ⎔) (old) -- note : tex.print == line with endlinechar appended -- todo : context("%bold{total: }%s",total) -- todo : context.documentvariable("title") @@ -58,6 +58,20 @@ if not modules then modules = { } end modules ['cldf-ini'] = { -- time (for the better or worse). There have been no fundamental changes for many years -- and performance has not changed much either. +-- The code here has evolved over time, and was already present in the early versions of +-- mkiv. However, it got adapted when feature were added to luatex, like the ability to +-- "print" nodes and later tokens. We use to have control over the method used (if only +-- for testing) but the older code has been removed now. The history is in the archives. +-- These were the controls: + +-- local tokenflushmode = true +-- local nodeflushmode = true +-- local scannerdefmode = true +-- local maxflushnodeindex = 0x10FFFF - 1 + +-- In earlier experiments a function tables was referred to as lua.calls and the primitive +-- \luafunctions was \luacall and we used our own implementation of a function table (more +-- indirectness). local format, stripstring = string.format, string.strip local next, type, tostring, tonumber, unpack, select, rawset = next, type, tostring, tonumber, unpack, select, rawset @@ -83,10 +97,6 @@ local tex = tex local texsprint = tex.sprint -- just appended (no space,eol treatment) local texprint = tex.print -- each arg a separate line (not last in directlua) ----- texwrite = tex.write -- all 'space' and 'character' -local texgetcount = tex.getcount - --- local function texsprint(...) print("sprint",...) tex.sprint(...) end --- local function texprint (...) print("print", ...) tex.print (...) end local isnode = node.is_node local writenode = node.write @@ -99,6 +109,19 @@ local newtoken = token.new local createtoken = token.create local setluatoken = token.set_lua +local isprintable = tex.isprintable or function(n) + return n and (type(n) == "string" or isnode(n) or istoken(n)) +end + +if tex.runlocal then + -- obselete names + tex.runtoks = tex.runlocal + tex.quittoks = tex.quitlocal +else + tex.runlocal = tex.runtoks + tex.quitlocal = tex.quittoks +end + local catcodenumbers = catcodes.numbers local ctxcatcodes = catcodenumbers.ctxcatcodes @@ -118,45 +141,35 @@ local report_cld = logs.reporter("cld","stack") local processlines = true -- experiments.register("context.processlines", function(v) processlines = v end) -local tokenflushmode = true -local nodeflushmode = true -local scannerdefmode = true -local maxflushnodeindex = 0x10FFFF - 1 - --- tokenflushmode = false --- nodeflushmode = false --- scannerdefmode = false +local trialtypesetting = function() return false end --- In earlier experiments a function tables was referred to as lua.calls and the --- primitive \luafunctions was \luacall and we used our own implementation of --- a function table (more indirectness). - -local trialtypesettingstate = createtoken("trialtypesettingstate").index - -function context.trialtypesetting() - return texgetcount(trialtypesettingstate) ~= 0 +function context.settrialtypesettingmethod(f) + trialtypesetting = f + context.trialtypesetting = f end +context.trialtypesetting = function() return trialtypesetting() end -- can be aliased ! + local knownfunctions = (lua.getfunctionstable or lua.get_functions_table)(true) local showstackusage = false trackers.register("context.stack",function(v) showstackusage = v end) -local freed, nofused, noffreed = { }, 0, 0 +local freed = { } +local nofused = 0 +local noffreed = 0 local usedstack = function() return nofused, noffreed end local flushfunction = function(slot,arg) - if arg() then + if arg() or trialtypesetting() then -- keep - elseif texgetcount(trialtypesettingstate) == 0 then + else noffreed = noffreed + 1 freed[noffreed] = slot knownfunctions[slot] = false - else - -- keep end end @@ -176,13 +189,13 @@ local storefunction = function(arg) end local flushnode = function(slot,arg) - if texgetcount(trialtypesettingstate) == 0 then + if trialtypesetting() then + writenode(copynodelist(arg)) + else writenode(arg) noffreed = noffreed + 1 freed[noffreed] = slot knownfunctions[slot] = false - else - writenode(copynodelist(arg)) end end @@ -208,11 +221,11 @@ local initex = environment.initex storage.register("storage/storedfunctions", storedfunctions, "storage.storedfunctions") local f_resolve = nil -local p_resolve = ((1-lpegP("."))^1 / function(s) f_resolve = f_resolve[s] end * lpegP(".")^0)^1 +local p_resolve = ((1-lpegP("."))^1 / function(s) f_resolve = f_resolve[s] end * lpegP(".")^0)^1 local function resolvestoredfunction(str) if type(str) == "string" then - f_resolve = global + f_resolve = global -- namespace lpegmatch(p_resolve,str) return f_resolve else @@ -257,9 +270,11 @@ else end end -local registerfunction = function(f,direct) -- either f=code or f=namespace,direct=name - local slot, func - if noffreed > 0 then +local registerfunction = function(f,direct,slot) -- either f=code or f=namespace,direct=name + local func + if slot then + -- already used + elseif noffreed > 0 then slot = freed[noffreed] freed[noffreed] = nil noffreed = noffreed - 1 @@ -269,12 +284,8 @@ local registerfunction = function(f,direct) -- either f=code or f=namespace,dire end if direct then if initex then - func = function(...) - expose(slot,f,...) - end - if initex then - storedfunctions[slot] = f - end + func = function(...) expose(slot,f,...) end + storedfunctions[slot] = f else func = resolvestoredfunction(f) end @@ -357,73 +368,109 @@ do end --- so far - --- The next hack is a convenient way to define scanners at the Lua end and --- get them available at the TeX end. There is some dirty magic needed to --- prevent overload during format loading. +-- The next hack is a convenient way to define scanners at the Lua end and get them +-- available at the TeX end. There is some dirty magic needed to prevent overload +-- during format loading. Nowadays we prefer to use the slightly less efficient way +-- of defining interfaces using the implementer. There is a little more overhead in +-- defining as well as runtime overhead, but we accept that. -- interfaces.scanners.foo = function() context("[%s]",tokens.scanners.string()) end : \scan_foo -interfaces.storedscanners = interfaces.storedscanners or { } -local storedscanners = interfaces.storedscanners +local storedscanners = interfaces.storedscanners or { } +local namesofscanners = interfaces.namesofscanners or { } +local interfacescanners = { } +local privatenamespace = "clf_" + +interfaces.storedscanners = storedscanners +interfaces.namesofscanners = namesofscanners storage.register("interfaces/storedscanners", storedscanners, "interfaces.storedscanners") -local interfacescanners = setmetatablenewindex(function(t,k,v) - rawset(t,k,v) - if storedscanners[k] then - -- report_cld("warning: scanner %a is already set (mode 1a)",k) - -- os.exit() - -- \scan_<k> is already in the format - -- report_cld("using interface scanner: %s",k) - elseif scannerdefmode then - -- report_cld("installing interface scanner: %s (mode 1b)",k) - -- local n = registerfunction(interfaces.scanners[k],true) - local n = registerfunction("interfaces.scanners."..k,true) - storedscanners[k] = n - local name = "clf_" .. k - setluatoken(name,n,"global") -- todo : protected and "protected" or "" - else - -- report_cld("installing interface scanner: %s (mode 1c)",k) - storedscanners[k] = true - context("\\installctxscanner{clf_%s}{interfaces.scanners.%s}",k,k) +-- local function registerscanner(name,action,protected,public,usage) -- todo: combine value and condition +-- rawset(interfacescanners,name,action) +-- local n = storedscanners[name] +-- n = registerfunction("interfaces.scanners."..name,true,n) +-- storedscanners[name] = n +-- namesofscanners[n] = name +-- name = public and name or (privatenamespace .. name) +-- -- print(">>",name,protected and "protected" or "",usage or "macro") +-- setluatoken(name,n,"global",protected and "protected" or "",usage or "macro") +-- end + +-- todo: bitmap + +local registerscanner if CONTEXTLMTXMODE > 0 then + + -- always permanent but we can consider to obey permanent==false + + local function toflags(specification) + local protected = specification.protected and "protected" -- or "" + local usage = specification.usage + if usage == "value" then + return "global", "value", "permanent", protected + elseif usage == "condition" then + return "global", "conditional", "permanent", protected + elseif specification.frozen then + return "global", "frozen", protected + elseif specification.permanent == false or specification.onlyonce then -- for now onlyonce here + return "global", protected + else + return "global", "permanent", protected + end end - -- rawset(t,k,v) -end) -function interfaces.registerscanner(name,action,protected,public,call) - rawset(interfacescanners,name,action) - if storedscanners[name] then - -- report_cld("warning: scanner %a is already set (mode 2a)",name) - -- os.exit() - -- \scan_<k> is already in the format - -- report_cld("using interface scanner: %s",k) - elseif scannerdefmode then - -- report_cld("installing interface scanner: %s (mode 2b)",name) - -- local n = registerfunction(action,true) -- todo - local n = registerfunction("interfaces.scanners."..name,true) + registerscanner = function(name,action,specification) + rawset(interfacescanners,name,action) + local n = registerfunction("interfaces.scanners."..name,true,storedscanners[name]) storedscanners[name] = n - local name = public and name or ("clf_" .. name) - setluatoken(name,n,"global",protected and "protected" or "") - else - storedscanners[name] = true - -- report_cld("installing interface scanner: %s (mode 2c)",name) - context("\\install%sctxscanner{%s%s}{interfaces.scanners.%s}", - protected and "protected" or "", - public and "" or "clf_", - name, - name - ) - end - -- rawset(interfacescanners,name,action) + namesofscanners[n] = name + name = specification.public and name or (privatenamespace .. name) + setluatoken(name,n,toflags(specification)) + end + +else + + registerscanner = function(name,action,specification) + rawset(interfacescanners,name,action) + local n = storedscanners[name] + n = registerfunction("interfaces.scanners."..name,true,n) + storedscanners[name] = n + namesofscanners[n] = name + name = specification.public and name or (privatenamespace .. name) + setluatoken(name,n,"global",specification.protected and "protected" or "") + end + +end + +interfaces.registerscanner = registerscanner + +function interfaces.knownscanner(name) + return interfacescanners[name] +end + +function interfaces.nameofscanner(slot) + return namesofscanners[slot] or slot +end + +if CONTEXTLMTXMODE > 0 then + + callback.register("show_lua_call", function(what, slot) + local name = namesofscanners[slot] + -- return name and formatters["%s: \\%s, slot: %i"](what,name,slot) or "" + return name and formatters["%s \\%s"](what,name) or "" + end) + end +setmetatablenewindex(interfacescanners, function(t,k,v) + report_cld("don't register scanner %a directly",k) + -- registerscanner(k,v) +end) + interfaces.scanners = storage.mark(interfacescanners) -interfaces._ = interfaces.scanners context.functions = { - register = registerfunction, + register = function(qualifiedname) return registerfunction(qualifiedname) end, -- only one argument unregister = unregisterfunction, reserve = reservefunction, known = knownfunctions, @@ -448,7 +495,7 @@ function commands.ctxresetter(name) -- to be checked return function() if storedscanners[name] then rawset(interfacescanners,name,dummy) - context.resetctxscanner("clf_" .. name) + context.resetctxscanner(privatenamespace .. name) end end end @@ -540,25 +587,11 @@ local endstripper = beginstripper * lpegP(-1) local justaspace = space * lpegCc("") local justanewline = newline * lpegCc("") -local function n_content(s) - flush(contentcatcodes,s) -end - -local function n_verbose(s) - flush(vrbcatcodes,s) -end - -local function n_endofline() - flush(currentcatcodes," \r") -end - -local function n_emptyline() - flushdirect(currentcatcodes,"\r") -end - -local function n_simpleline() - flush(currentcatcodes," \r") -end +local function n_content (s) flush (contentcatcodes,s ) end +local function n_verbose (s) flush (vrbcatcodes, s ) end +local function n_endofline () flush (currentcatcodes," \r") end +local function n_emptyline () flushdirect(currentcatcodes,"\r" ) end +local function n_simpleline() flush (currentcatcodes," \r") end local n_exception = "" @@ -646,7 +679,7 @@ function context.newverbosehandler(specification) -- a special variant for e.g. specification = specification or { } -- local f_line = specification.line or function() flushdirect("\r") end - local f_space = specification.space or function() flush(" ") end + local f_space = specification.space or function() flush (" ") end local f_content = specification.content or n_verbose local f_before = specification.before local f_after = specification.after @@ -700,20 +733,6 @@ function context.printlines(str,raw) -- todo: see if via file is useable end end --- function context.printtable(t,separator) -- todo: see if via file is useable --- if separator == nil or separator == true then --- separator = "\r" --- elseif separator == "" then --- separator = false --- end --- for i=1,#t do --- context(t[i]) -- we need to go through catcode handling --- if separator then --- context(separator) --- end --- end --- end - function context.printtable(t,separator) -- todo: see if via file is useable if separator == nil or separator == true then separator = "\r" @@ -730,24 +749,7 @@ end local containseol = patterns.containseol -local s_cldl_option_b = "[\\cldl" -local s_cldl_option_f = "[\\cldl" -- add space (not needed) -local s_cldl_option_e = "]" -local s_cldl_option_s = "\\cldl" ------ s_cldl_option_d = "\\cldd" -local s_cldl_option_d = s_cldl_option_s -local s_cldl_argument_b = "{\\cldl" -local s_cldl_argument_f = "{\\cldl " -local s_cldl_argument_e = "}" - --- local s_cldl_option_b = "[" --- local s_cldl_option_f = "" -- add space (not needed) --- local s_cldl_option_s = "" --- local s_cldl_argument_b = "{" --- local s_cldl_argument_f = "{ " - -local t_cldl_luafunction = newtoken("luafunctioncall",0) -local lua_expandable_call_token_code = token.command_id and token.command_id("lua_expandable_call") +local lua_call_code = tokens.commands.lua_expandable_call or tokens.commands.lua_call local sortedhashindeed = false @@ -756,17 +758,12 @@ directives.register("context.sorthash",function(v) end) local function writer(parent,command,...) -- already optimized before call - if type(command) == "string" then -- for now flush(currentcatcodes,command) -- todo: ctx|prt|texcatcodes else flush(command) -- todo: ctx|prt|texcatcodes end - local direct = false - -- local t = { ... } - -- for i=1,#t do - -- local ti = t[i] for i=1,select("#",...) do local ti = select(i,...) if direct then @@ -849,15 +846,7 @@ local function writer(parent,command,...) -- already optimized before call local tj = ti[1] if type(tj) == "function" then tj = storefunction(tj) - if tokenflushmode then - -- if newtoken then - flush(currentcatcodes,"[",newtoken(tj,lua_expandable_call_token_code),"]") - -- else - -- flush(currentcatcodes,"[",t_cldl_luafunction,tj,"]") - -- end - else - flush(currentcatcodes,s_cldl_option_b,tj,s_cldl_option_e) - end + flush(currentcatcodes,"[",newtoken(tj,lua_call_code),"]") else flush(currentcatcodes,"[",tj,"]") end @@ -867,15 +856,7 @@ local function writer(parent,command,...) -- already optimized before call local tj = ti[j] if type(tj) == "function" then tj = storefunction(tj) - if tokenflushmode then - -- if newtoken then - flush(currentcatcodes,"[",newtoken(tj,lua_expandable_call_token_code),j == tn and "]" or ",") - -- else - -- flush(currentcatcodes,"[",t_cldl_luafunction,tj,j == tn and "]" or ",") - -- end - else - flush(currentcatcodes,s_cldl_option_s,tj,j == tn and "]" or ",") - end + flush(currentcatcodes,"[",newtoken(tj,lua_call_code),j == tn and "]" or ",") else if j == tn then flush(currentcatcodes,tj,"]") @@ -888,15 +869,7 @@ local function writer(parent,command,...) -- already optimized before call elseif typ == "function" then -- todo: ctx|prt|texcatcodes ti = storefunction(ti) - if tokenflushmode then - -- if newtoken then - flush(currentcatcodes,"{",newtoken(ti,lua_expandable_call_token_code),"}") - -- else - -- flush(currentcatcodes,"{",t_cldl_luafunction,ti,"}") - -- end - else - flush(currentcatcodes,s_cldl_argument_f,ti,s_cldl_argument_e) - end + flush(currentcatcodes,"{",newtoken(ti,lua_call_code),"}") elseif typ == "boolean" then if ti then flushdirect(currentcatcodes,"\r") @@ -905,123 +878,58 @@ local function writer(parent,command,...) -- already optimized before call end elseif typ == "thread" then report_context("coroutines not supported as we cannot yield across boundaries") - elseif isnode(ti) then -- slow | why {} here ? - if nodeflushmode then - local n = tonut(ti) - if n <= maxflushnodeindex then - flush(currentcatcodes,"{",ti,"}") - else - flush(currentcatcodes,s_cldl_argument_b,storenode(ti),s_cldl_argument_e) - end + -- elseif isnode(ti) or istoken(ti) then + elseif isprintable(ti) then + flush(currentcatcodes,"{",ti,"}") + else + local s = tostring(ti) + if s then + flushdirect(currentcatcodes,s) else - flush(currentcatcodes,s_cldl_argument_b,storenode(ti),s_cldl_argument_e) + report_context("error: %a gets a weird argument %a",command,ti) end - else - report_context("error: %a gets a weird argument %a",command,ti) end --- else --- local n = isnode(ti) --- if n then --- if nodeflushmode and n <= maxflushnodeindex then --- flush(ti) --- else --- flush(currentcatcodes,s_cldl_argument_b,storenode(ti),s_cldl_argument_e) --- end --- else --- report_context("error: %a gets a weird argument %a",command,ti) --- end --- end + -- else + -- local n = isnode(ti) + -- if n then + -- flush(ti) + -- else + -- report_context("error: %a gets a weird argument %a",command,ti) + -- end end end end -local core - -if tokenflushmode then -- combine them +local toks = tokens.cache +context.tokenizedcs = toks - local toks = tokens.cache - - context.tokenizedcs = toks - - core = setmetatableindex(function(parent,k) - local t - local f = function(first,...) - if not t then - t = toks[k] - end - if first == nil then - flush(t) - else - return writer(context,t,first,...) - end +local core = setmetatableindex(function(parent,k) + local t + local f = function(first,...) + if not t then + t = toks[k] end - parent[k] = f - return f - end) - --- core = setmetatableindex(function(parent,k) --- local t --- local f = function(first,...) --- if not t then --- t = toks[k] --- end --- local f = function(first,...) --- if first == nil then --- flush(t) --- else --- return writer(context,t,first,...) --- end --- end --- parent[k] = f --- if first == nil then --- flush(t) --- else --- return writer(context,t,first,...) --- end --- end --- parent[k] = f --- return f --- end) - - core.cs = setmetatableindex(function(parent,k) - local t - local f = function() - if not t then - t = toks[k] - end + if first == nil then flush(t) + else + return writer(context,t,first,...) end - parent[k] = f - return f - end) - -else - - context.tokenizedcs = false - - core = setmetatableindex(function(parent,k) - local c = "\\" .. k - local f = function(first,...) - if first == nil then - flush(currentcatcodes,c) - else - return writer(context,c,first,...) - end - end - parent[k] = f - return f - end) + end + parent[k] = f + return f +end) - core.cs = setmetatableindex(function(parent,k) - local c = "\\" .. k -- tostring(k) - local f = function() - flush(currentcatcodes,c) +core.cs = setmetatableindex(function(parent,k) + local t + local f = function() + if not t then + t = toks[k] end - parent[k] = f - return f - end) - -end + flush(t) + end + parent[k] = f + return f +end) local indexer = function(parent,k) if type(k) == "string" then @@ -1117,15 +1025,7 @@ local caller = function(parent,f,a,...) elseif typ == "function" then -- ignored: a ... f = storefunction(f) - if tokenflushmode then - -- if newtoken then - flush(currentcatcodes,"{",newtoken(f,lua_expandable_call_token_code),"}") - -- else - -- flush(currentcatcodes,"{",t_cldl_luafunction,f,"}") - -- end - else - flush(currentcatcodes,s_cldl_argument_b,f,s_cldl_argument_e) -- todo: ctx|prt|texcatcodes - end + flush(currentcatcodes,"{",newtoken(f,lua_call_code),"}") elseif typ == "boolean" then if f then if a ~= nil then @@ -1143,43 +1043,31 @@ local caller = function(parent,f,a,...) end elseif typ == "thread" then report_context("coroutines not supported as we cannot yield across boundaries") - elseif isnode(f) then -- slow - if nodeflushmode then - local n = tonut(f) - if n <= maxflushnodeindex then - flush(f) - else - flush(currentcatcodes,s_cldl_option_s,storenode(f)," ") - end + -- elseif isnode(f) or istoken(f) then + elseif isprintable(f) then + flush(f) + else + local s = tostring(f) + if s then + flushdirect(currentcatcodes,s) else - flush(currentcatcodes,s_cldl_option_s,storenode(f)," ") + report_context("error: %a gets a weird argument %a","context",f) end - else - report_context("error: %a gets a weird argument %a","context",f) end --- else --- local n = isnode(f) --- if n then --- if nodeflushmode and n <= maxflushnodeindex then --- flush(f) --- else --- flush(currentcatcodes,s_cldl_option_s,storenode(f)," ") --- end --- else --- report_context("error: %a gets a weird argument %a","context",f) --- end --- end + -- else + -- local n = isnode(f) + -- if n then + -- flush(f) + -- else + -- report_context("error: %a gets a weird argument %a","context",f) + -- end end end context.nodes = { -- todo store = storenode, flush = function(n) - if nodeflushmode and tonut(n) <= maxflushnodeindex then - flush(n) - else - flush(currentcatcodes,d and s_cldl_option_d or s_cldl_option_s,storenode(n)," ") - end + flush(n) end, } @@ -1188,11 +1076,7 @@ context.nuts = { -- todo return storenode(tonut(n)) end, flush = function(n,d) - if nodeflushmode and n <= maxflushnodeindex then - flush(tonode(n)) - else - flush(currentcatcodes,d and s_cldl_option_d or s_cldl_option_s,storenode(tonode(n))," ") - end + flush(tonode(n)) end, } @@ -1252,23 +1136,30 @@ statistics.register("traced context", function() end end) +-- The cmd names were synchronized with the normal call cmd names. + +local luacalls = { -- luatex luametatex + lua_expandable_call = true, -- normal + lua_call = true, -- protected normal + lua_protected_call = true, -- protected +} + local function userdata(argument) if isnode(argument) then return formatters["<< %s node %i>>"](nodes.nodecodes[argument.id],tonut(argument)) - end - if istoken(argument) then + elseif istoken(argument) then local csname = argument.csname if csname then -- return formatters["<<\\%s>>"](csname) return formatters["\\%s"](csname) end - local cmdname = argument.cmdname - if cmdname == "lua_expandable_call" or cmdname == "lua_call" then + if luacall[argument.cmdname] then return "<<function>>" -- argument.mode end return "<<token>>" + else + return "<<userdata>>" end - return "<<userdata>>" end @@ -1630,22 +1521,7 @@ function context.newindexer(catcodes,cmdcodes) contentcatcodes = savedcatcodes end - if tokenflushmode then - - handler.cs = core.cs - - else - - handler.cs = setmetatableindex(function(parent,k) - local c = "\\" .. k -- tostring(k) - local f = function() - flush(cmdcodes,c) - end - parent[k] = f - return f - end) - - end + handler.cs = core.cs setmetatableindex(handler,indexer) setmetatablecall (handler,caller) @@ -1665,23 +1541,6 @@ do -- formatted.command([catcodes,]format[,...]) --- local function formattedflush(parent,c,catcodes,fmt,...) --- if type(catcodes) == "number" then --- if fmt then --- local result --- pushcatcodes(catcodes) --- result = writer(parent,c,formatters[fmt](...)) --- popcatcodes() --- return result --- else --- -- no need to change content catcodes --- return writer(parent,c) --- end --- else --- return writer(parent,c,formatters[catcodes](fmt,...)) --- end --- end - local function formattedflush(parent,c,catcodes,fmt,...) if not catcodes then return writer(parent,c) @@ -1698,51 +1557,26 @@ do end end - local indexer - - if tokenflushmode then -- combine them - - local toks = tokens.cache + local toks = tokens.cache - indexer = function(parent,k) - if type(k) == "string" then - local t - local f = function(first,...) - if not t then - t = toks[k] - end - if first == nil then - flush(t) - else - return formattedflush(parent,t,first,...) - end + local indexer = function(parent,k) + if type(k) == "string" then + local t + local f = function(first,...) + if not t then + t = toks[k] end - parent[k] = f - return f - else - return context -- catch - end - end - - else - - indexer = function(parent,k) - if type(k) == "string" then - local c = "\\" .. k - local f = function(first,...) - if first == nil then - flush(currentcatcodes,c) - else - return formattedflush(parent,c,first,...) - end + if first == nil then + flush(t) + else + return formattedflush(parent,t,first,...) end - parent[k] = f - return f - else - return context -- catch end + parent[k] = f + return f + else + return context -- catch end - end -- formatted([catcodes,]format[,...]) @@ -1947,3 +1781,25 @@ end -- function context.template(template,variables) -- context(replace(template,variables)) -- end + +do + + -- not the best namespace -- some day maybe texs a la nodes and tokens .. also, + -- we already have tex.modes so we need a different name + + local modelevels = tex.getmodevalues() + local t = table.keys(modelevels) + tex.modelevels = table.swapped(modelevels,modelevels) -- utilities.storage.allocate() + + for i=1,#t do local k = t[i] modelevels[-k] = modelevels[k] end + + if CONTEXTLMTXMODE > 0 then + + -- also elsewhere + + local flagcodes = tex.getflagvalues() + tex.flagcodes = table.swapped(flagcodes,flagcodes) -- utilities.storage.allocate() + + end + +end |