diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/java-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/java-ini.lua | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/Master/texmf-dist/tex/context/base/java-ini.lua b/Master/texmf-dist/tex/context/base/java-ini.lua index 1e98de7173f..321e4e24d22 100644 --- a/Master/texmf-dist/tex/context/base/java-ini.lua +++ b/Master/texmf-dist/tex/context/base/java-ini.lua @@ -8,10 +8,12 @@ if not modules then modules = { } end modules ['java-ini'] = { local format = string.format local concat = table.concat -local lpegmatch, lpegP, lpegR, lpegS, lpegC, lpegCarg = lpeg.match, lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Carg +local lpegmatch, P, S, C, Carg, Cc = lpeg.match, lpeg.P, lpeg.S, lpeg.C, lpeg.Carg, lpeg.Cc local allocate = utilities.storage.allocate +local settings_to_array = utilities.parsers.settings_to_array local variables = interfaces.variables +local formatters = string.formatters -- todo: don't flush scripts if no JS key @@ -33,29 +35,29 @@ local preambled = { } local function storefunction(s,preamble) if trace_javascript then - report_javascripts("found: function '%s'",s) + report_javascripts("found function %a",s) end functions[s] = preamble end -local uses = lpegP("uses") -local used = lpegP("used") -local left = lpegP("{") -local right = lpegP("}") -local space = lpegS(" \r\n") +local uses = P("uses") +local used = P("used") +local left = P("{") +local right = P("}") +local space = S(" \r\n") local spaces = space^0 -local braced = left * lpegC((1-right-space)^1) * right -local unbraced = lpegC((1-space)^1) +local braced = left * C((1-right-space)^1) * right +local unbraced = C((1-space)^1) local name = spaces * (braced + unbraced) * spaces -local any = lpegP(1) -local script = lpegC(any^1) -local funct = lpegP("function") -local leftp = lpegP("(") -local rightp = lpegP(")") -local fname = spaces * funct * spaces * (lpegC((1-space-left-leftp)^1) * lpegCarg(1) / storefunction) * spaces * leftp - -local parsecode = name * ((uses * name) + lpeg.Cc("")) * spaces * script -local parsepreamble = name * ((used * name) + lpeg.Cc("")) * spaces * script +local any = P(1) +local script = C(any^1) +local funct = P("function") +local leftp = P("(") +local rightp = P(")") +local fname = spaces * funct * spaces * (C((1-space-left-leftp)^1) * Carg(1) / storefunction) * spaces * leftp + +local parsecode = name * ((uses * name) + Cc("")) * spaces * script +local parsepreamble = name * ((used * name) + Cc("")) * spaces * script local parsefunctions = (fname + any)^0 function javascripts.storecode(str) @@ -72,7 +74,7 @@ function javascripts.storepreamble(str) -- now later preambles[n] = { name, used, script } preambled[name] = n if trace_javascript then - report_javascripts("stored: preamble '%s', state '%s', order '%s'",name,used,n) + report_javascripts("stored preamble %a, state %a, order %a",name,used,n) end lpegmatch(parsefunctions,script,1,n) end @@ -84,7 +86,7 @@ function javascripts.setpreamble(name,script) -- now later preambles[n] = { name, "now", script } preambled[name] = n if trace_javascript then - report_javascripts("adapted: preamble '%s', state '%s', order '%s'",name,"now",n) + report_javascripts("adapted preamble %a, state %a, order %a",name,"now",n) end lpegmatch(parsefunctions,script,1,n) end @@ -96,14 +98,14 @@ function javascripts.addtopreamble(name,script) if p then preambles[p] = { "now", preambles[p] .. " ;\n" .. script } if trace_javascript then - report_javascripts("extended: preamble '%s', state '%s', order '%s'",name,"now",p) + report_javascripts("extended preamble %a, state %a, order %a",name,"now",p) end else local n = #preambles + 1 preambles[n] = { name, "now", script } preambled[name] = n if trace_javascript then - report_javascripts("stored: preamble '%s', state '%s', order '%s'",name,"now",n) + report_javascripts("stored preamble %a, state %a, order %a",name,"now",n) end lpegmatch(parsefunctions,script,1,n) end @@ -112,13 +114,13 @@ end function javascripts.usepreamblenow(name) -- now later if name and name ~= "" and name ~= variables.reset then -- todo: reset - local names = utilities.parsers.settings_to_array(name) + local names = settings_to_array(name) for i=1,#names do local somename = names[i] if not preambled[somename] then preambles[preambled[somename]][2] = "now" if trace_javascript then - report_javascripts("used: preamble '%s', state '%s', order '%s'",somename,"now","auto") + report_javascripts("used preamble %a, state %a, order %a",somename,"now","auto") end end end @@ -139,15 +141,15 @@ function javascripts.code(name,arguments) preambles[p][2] = "now" if trace_javascript and not reported[name] then reported[name] = true - report_javascripts("used: code '%s', preamble '%s'",name,u) + report_javascripts("used code %a, preamble %a",name,u) end elseif trace_javascript and not reported[name] then reported[name] = true - report_javascripts("used: code '%s'",name) + report_javascripts("used code %a",name) end elseif trace_javascript and not reported[name] then reported[name] = true - report_javascripts("used: code '%s'",name) + report_javascripts("used code %a",name) end used = true return code @@ -157,17 +159,17 @@ function javascripts.code(name,arguments) used = true if trace_javascript and not reported[name] then reported[name] = true - report_javascripts("used: function '%s'",name) + report_javascripts("used function %a",name) end preambles[f][2] = "now" -- automatically tag preambles that define the function (as later) if arguments then local args = lpegmatch(splitter,arguments) for i=1,#args do -- can be a helper - args[i] = format("%q",args[i]) + args[i] = formatters["%q"](args[i]) end - return format("%s(%s)",name,concat(args,",")) + return formatters["%s(%s)"](name,concat(args,",")) else - return format("%s()",name) + return formatters["%s()"](name) end end end @@ -179,7 +181,7 @@ function javascripts.flushpreambles() local preamble = preambles[i] if preamble[2] == "now" then if trace_javascript then - report_javascripts("flushed: preamble '%s'",preamble[1]) + report_javascripts("flushed preamble %a",preamble[1]) end t[#t+1] = { preamble[1], preamble[3] } end @@ -194,13 +196,13 @@ local function action(name,foundname) context.startnointerference() context.startreadingfile() context.input(foundname) - status_javascripts("loaded: library '%s'",name) + status_javascripts("loaded: library %a",name) context.stopreadingfile() context.stopnointerference() end local function failure(name) - report_javascripts("unknown: library '%s'",name) + report_javascripts("unknown library %a",name) end function javascripts.usescripts(name) |