diff options
author | Karl Berry <karl@freefriends.org> | 2013-04-08 00:43:40 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-04-08 00:43:40 +0000 |
commit | 824f7b0903de8ad7f6ee3d7656005e4c59155e06 (patch) | |
tree | abfc8673ef9916f3ab7074e811207384c301492b /Master/texmf-dist/tex/context/base/mult-ini.lua | |
parent | 689aefb0727676ed3cddf331337b4be226495e72 (diff) |
context import for TL13, from www.pragma-ade.com/context/beta/cont-tmf.zip
git-svn-id: svn://tug.org/texlive/trunk@29731 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mult-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mult-ini.lua | 134 |
1 files changed, 85 insertions, 49 deletions
diff --git a/Master/texmf-dist/tex/context/base/mult-ini.lua b/Master/texmf-dist/tex/context/base/mult-ini.lua index d14f38ad5f6..5571ee3b948 100644 --- a/Master/texmf-dist/tex/context/base/mult-ini.lua +++ b/Master/texmf-dist/tex/context/base/mult-ini.lua @@ -6,16 +6,18 @@ if not modules then modules = { } end modules ['mult-ini'] = { license = "see context related readme files" } -local format, gmatch, gsub = string.format, string.gmatch, string.gsub +local format, gmatch, match = string.format, string.gmatch, string.match local lpegmatch = lpeg.match local serialize = table.serialize -local allocate = utilities.storage.allocate -local mark = utilities.storage.mark -local contextsprint = context.sprint -local setmetatableindex = table.setmetatableindex +local allocate = utilities.storage.allocate +local mark = utilities.storage.mark +local prtcatcodes = catcodes.numbers.prtcatcodes +local contextsprint = context.sprint +local setmetatableindex = table.setmetatableindex +local formatters = string.formatters -local report_interface = logs.reporter("interface","initialization") +local report_interface = logs.reporter("interface","initialization") interfaces = interfaces or { } interfaces.constants = mark(interfaces.constants or { }) @@ -25,27 +27,38 @@ interfaces.formats = mark(interfaces.formats or { }) interfaces.translations = mark(interfaces.translations or { }) interfaces.corenamespaces = mark(interfaces.corenamespaces or { }) -storage.register("interfaces/constants", interfaces.constants, "interfaces.constants") -storage.register("interfaces/variables", interfaces.variables, "interfaces.variables") -storage.register("interfaces/elements", interfaces.elements, "interfaces.elements") -storage.register("interfaces/formats", interfaces.formats, "interfaces.formats") -storage.register("interfaces/translations", interfaces.translations, "interfaces.translations") -storage.register("interfaces/corenamespaces", interfaces.corenamespaces, "interfaces.corenamespaces") +local registerstorage = storage.register +local sharedstorage = storage.shared + +local constants = interfaces.constants +local variables = interfaces.variables +local elements = interfaces.elements +local formats = interfaces.formats +local translations = interfaces.translations +local corenamespaces = interfaces.corenamespaces +local reporters = { } -- just an optimization + +registerstorage("interfaces/constants", constants, "interfaces.constants") +registerstorage("interfaces/variables", variables, "interfaces.variables") +registerstorage("interfaces/elements", elements, "interfaces.elements") +registerstorage("interfaces/formats", formats, "interfaces.formats") +registerstorage("interfaces/translations", translations, "interfaces.translations") +registerstorage("interfaces/corenamespaces", corenamespaces, "interfaces.corenamespaces") interfaces.interfaces = { "cs", "de", "en", "fr", "it", "nl", "ro", "pe", } -storage.shared.currentinterface = storage.shared.currentinterface or "en" -storage.shared.currentresponse = storage.shared.currentresponse or "en" +sharedstorage.currentinterface = sharedstorage.currentinterface or "en" +sharedstorage.currentresponse = sharedstorage.currentresponse or "en" -local currentinterface = storage.shared.currentinterface -local currentresponse = storage.shared.currentresponse +local currentinterface = sharedstorage.currentinterface +local currentresponse = sharedstorage.currentresponse local complete = allocate() interfaces.complete = complete -local function resolve(t,k) -- one access needed to get loaded +local function resolve(t,k) -- one access needed to get loaded (not stored!) report_interface("loading interface definitions from 'mult-def.lua'") complete = dofile(resolvers.findfile("mult-def.lua")) report_interface("loading interface messages from 'mult-mes.lua'") @@ -56,14 +69,6 @@ end setmetatableindex(complete, resolve) -local constants = interfaces.constants -local variables = interfaces.variables -local elements = interfaces.elements -local formats = interfaces.formats -local translations = interfaces.translations -local corenamespaces = interfaces.corenamespaces -local reporters = { } -- just an optimization - local function valueiskey(t,k) -- will be helper t[k] = k return k @@ -75,7 +80,7 @@ setmetatableindex(elements, valueiskey) setmetatableindex(formats, valueiskey) setmetatableindex(translations, valueiskey) -function commands.registernamespace(n,namespace) +function interfaces.registernamespace(n,namespace) corenamespaces[n] = namespace end @@ -85,7 +90,7 @@ local function resolve(t,k) return v end -setmetatableindex(reporters, resolve) +setmetatableindex(reporters,resolve) for category, _ in next, translations do -- We pre-create reporters for already defined messages @@ -122,9 +127,10 @@ end -- the old method: +local replacer = lpeg.replacer { { "--", "%%a" } } + local function fulltag(category,tag) - tag = gsub(tag,"%-%-","%%s") - return format("%s:%s",category,tag) + return formatters["%s:%s"](category,lpegmatch(replacer,tag)) end function interfaces.setmessages(category,str) @@ -132,13 +138,13 @@ function interfaces.setmessages(category,str) if tag == "title" then translations[tag] = translations[tag] or tag else - formats[fulltag(category,tag)] = gsub(message,"%-%-","%%s") + formats[fulltag(category,tag)] = lpegmatch(replacer,message) end end end function interfaces.setmessage(category,tag,message) - formats[fulltag(category,tag)] = gsub(message,"%-%-","%%s") + formats[fulltag(category,tag)] = lpegmatch(replacer,message) end function interfaces.getmessage(category,tag,default) @@ -146,7 +152,7 @@ function interfaces.getmessage(category,tag,default) end function interfaces.doifelsemessage(category,tag) - return commands.testcase(formats[fulltag(category,tag)]) + return formats[fulltag(category,tag)] end local splitter = lpeg.splitat(",") @@ -184,45 +190,38 @@ end logs.setmessenger(context.verbatim.ctxreport) --- status - -function commands.writestatus(category,message,...) - local r = reporters[category] - r(message,...) -end - -- initialization function interfaces.setuserinterface(interface,response) - storage.shared.currentinterface, currentinterface = interface, interface - storage.shared.currentresponse, currentresponse = response, response + sharedstorage.currentinterface, currentinterface = interface, interface + sharedstorage.currentresponse, currentresponse = response, response if environment.initex then local nofconstants = 0 for given, constant in next, complete.constants do constant = constant[interface] or constant.en or given constants[constant] = given -- breedte -> width - contextsprint("\\do@sicon{",given,"}{",constant,"}") + contextsprint(prtcatcodes,"\\ui_c{",given,"}{",constant,"}") -- user interface constant nofconstants = nofconstants + 1 end local nofvariables = 0 for given, variable in next, complete.variables do variable = variable[interface] or variable.en or given variables[given] = variable -- ja -> yes - contextsprint("\\do@sivar{",given,"}{",variable,"}") + contextsprint(prtcatcodes,"\\ui_v{",given,"}{",variable,"}") -- user interface variable nofvariables = nofvariables + 1 end local nofelements = 0 for given, element in next, complete.elements do element = element[interface] or element.en or given elements[element] = given - contextsprint("\\do@siele{",given,"}{",element,"}") + contextsprint(prtcatcodes,"\\ui_e{",given,"}{",element,"}") -- user interface element nofelements = nofelements + 1 end local nofcommands = 0 for given, command in next, complete.commands do command = command[interface] or command.en or given if command ~= given then - contextsprint("\\do@sicom{",given,"}{",command,"}") + contextsprint(prtcatcodes,"\\ui_m{",given,"}{",command,"}") -- user interface macro end nofcommands = nofcommands + 1 end @@ -236,7 +235,7 @@ function interfaces.setuserinterface(interface,response) translations[given] = translation[interface] or translation.en or given noftranslations = noftranslations + 1 end - report_interface("definitions: %s constants, %s variables, %s elements, %s commands, %s formats, %s translations", + report_interface("definitions: %a constants, %a variables, %a elements, %a commands, %a formats, %a translations", nofconstants,nofvariables,nofelements,nofcommands,nofformats,noftranslations) end end @@ -244,12 +243,12 @@ end interfaces.cachedsetups = interfaces.cachedsetups or { } interfaces.hashedsetups = interfaces.hashedsetups or { } -storage.register("interfaces/cachedsetups", interfaces.cachedsetups, "interfaces.cachedsetups") -storage.register("interfaces/hashedsetups", interfaces.hashedsetups, "interfaces.hashedsetups") - local cachedsetups = interfaces.cachedsetups local hashedsetups = interfaces.hashedsetups +storage.register("interfaces/cachedsetups", cachedsetups, "interfaces.cachedsetups") +storage.register("interfaces/hashedsetups", hashedsetups, "interfaces.hashedsetups") + function interfaces.cachesetup(t) local hash = serialize(t) local done = hashedsetups[hash] @@ -271,3 +270,40 @@ function interfaces.interfacedcommand(name) local command = complete.commands[name] return command and command[currentinterface] or name end + +-- interface + +function commands.writestatus(category,message,...) + local r = reporters[category] + if r then + r(message,...) + end +end + +commands.registernamespace = interfaces.registernamespace +commands.setinterfaceconstant = interfaces.setconstant +commands.setinterfacevariable = interfaces.setvariable +commands.setinterfaceelement = interfaces.setelement +commands.setinterfacemessage = interfaces.setmessage +commands.setinterfacemessages = interfaces.setmessages +commands.showmessage = interfaces.showmessage + +function commands.doifelsemessage(category,tag) + commands.doifelse(interfaces.doifelsemessage(category,tag)) +end + +function commands.getmessage(category,tag,default) + context(interfaces.getmessage(category,tag,default)) +end + +function commands.showassignerror(namespace,key,value,line) + local ns, instance = match(namespace,"^(%d+)[^%a]+(%a+)") + if ns then + namespace = corenamespaces[tonumber(ns)] or ns + end + if instance then + context.writestatus("setup",formatters["error in line %a, namespace %a, instance %a, key %a"](line,namespace,instance,key)) + else + context.writestatus("setup",formatters["error in line %a, namespace %a, key %a"](line,namespace,key)) + end +end |