From 15ab7c153a96a9befc4e2c1774e701f3c941cc2d Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Mon, 2 Apr 2018 16:25:10 +0200 Subject: 2018-04-02 15:51:00 --- tex/context/base/mkiv/cldf-ini.lua | 72 ++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 14 deletions(-) (limited to 'tex/context/base/mkiv/cldf-ini.lua') diff --git a/tex/context/base/mkiv/cldf-ini.lua b/tex/context/base/mkiv/cldf-ini.lua index a2814877d..8cd6408d3 100644 --- a/tex/context/base/mkiv/cldf-ini.lua +++ b/tex/context/base/mkiv/cldf-ini.lua @@ -319,7 +319,43 @@ local interfacescanners = setmetatablenewindex(function(t,k,v) rawset(t,k,v) end) +function interfaces.registerscanner(name,action,protected,public,call) + if storedscanners[name] then + -- report_cld("warning: scanner %a is already set",k) + -- os.exit() + -- \scan_ is already in the format + -- report_cld("using interface scanner: %s",k) + else + storedscanners[name] = true +-- if protected then +-- -- report_cld("installing expandable interface scanner: %s",k) +-- if public then +-- context("\\installprotectedctxscanner{%s}{interfaces.scanners.%s}",name,name) +-- else +-- context("\\installprotectedctxscanner{clf_%s}{interfaces.scanners.%s}",name,name) +-- end +-- else +-- -- report_cld("installing protected interface scanner: %s",k) +-- if public then +-- context("\\installctxscanner{%s}{interfaces.scanners.%s}",name,name) +-- else +-- context("\\installctxscanner{clf_%s}{interfaces.scanners.%s}",name,name) +-- end +-- end + -- report_cld("installing interface scanner: %s",k) + context("\\install%sctxscanner%s{%s%s}{interfaces.scanners.%s}", + protected and "protected" or "", + call and "call" or "", + public and "" or "clf_", + name, + name + ) + end + rawset(interfacescanners,name,action) +end + interfaces.scanners = storage.mark(interfacescanners) +interfaces._ = interfaces.scanners context.functions = { register = registerfunction, @@ -633,6 +669,20 @@ 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" +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 function writer(parent,command,...) -- already optimized before call flush(currentcatcodes,command) -- todo: ctx|prt|texcatcodes local direct = false @@ -699,8 +749,7 @@ local function writer(parent,command,...) -- already optimized before call elseif tn == 1 then -- some 20% faster than the next loop local tj = ti[1] if type(tj) == "function" then - flush(currentcatcodes,"[\\cldl",storefunction(tj),"]") - -- flush(currentcatcodes,"[",storefunction(tj),"]") + flush(currentcatcodes,s_cldl_option_b,storefunction(tj),s_cldl_option_e) else flush(currentcatcodes,"[",tj,"]") end @@ -710,11 +759,9 @@ local function writer(parent,command,...) -- already optimized before call local tj = ti[j] if type(tj) == "function" then if j == tn then - flush(currentcatcodes,"\\cldl",storefunction(tj),"]") - -- flush(currentcatcodes,"",storefunction(tj),"]") + flush(currentcatcodes,s_cldl_option_s,storefunction(tj),"]") else - flush(currentcatcodes,"\\cldl",storefunction(tj),",") - -- flush(currentcatcodes,"",storefunction(tj),",") + flush(currentcatcodes,s_cldl_option_s,storefunction(tj),",") end else if j == tn then @@ -726,8 +773,8 @@ local function writer(parent,command,...) -- already optimized before call end end elseif typ == "function" then - flush(currentcatcodes,"{\\cldl ",storefunction(ti),"}") -- todo: ctx|prt|texcatcodes - -- flush(currentcatcodes,"{",storefunction(ti),"}") -- todo: ctx|prt|texcatcodes + -- todo: ctx|prt|texcatcodes + flush(currentcatcodes,s_cldl_argument_f,storefunction(ti),s_cldl_argument_e) elseif typ == "boolean" then if ti then flushdirect(currentcatcodes,"\r") @@ -737,8 +784,7 @@ local function writer(parent,command,...) -- already optimized before call elseif typ == "thread" then report_context("coroutines not supported as we cannot yield across boundaries") elseif isnode(ti) then -- slow - flush(currentcatcodes,"{\\cldl",storenode(ti),"}") - -- flush(currentcatcodes,"{",storenode(ti),"}") + flush(currentcatcodes,s_cldl_argument_b,storenode(ti),s_cldl_argument_e) else report_context("error: %a gets a weird argument %a",command,ti) end @@ -762,11 +808,9 @@ end -- if tp == "string" or tp == "number"then -- flush(prtcatcodes,"{",ti,"}") -- elseif tp == "function" then --- flush(prtcatcodes,"{\\cldl ",storefunction(ti),"}") --- -- flush(currentcatcodes,"{",storefunction(ti),"}") -- todo: ctx|prt|texcatcodes +-- flush(prtcatcodes,s_cldl_argument_f,storefunction(ti),s_cldl_argument_e) -- elseif isnode(ti) then --- flush(prtcatcodes,"{\\cldl",storenode(ti),"}") --- -- flush(currentcatcodes,"{",storenode(ti),"}") +-- flush(prtcatcodes,s_cldl_argument_b,storenode(ti),s_cldl_argument_e) -- else -- report_context("fatal error: prt %a gets a weird argument %a",command,ti) -- end -- cgit v1.2.3