summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lang-lab.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lang-lab.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/lang-lab.lua166
1 files changed, 77 insertions, 89 deletions
diff --git a/Master/texmf-dist/tex/context/base/lang-lab.lua b/Master/texmf-dist/tex/context/base/lang-lab.lua
index 360f2aa11b5..91c258418c9 100644
--- a/Master/texmf-dist/tex/context/base/lang-lab.lua
+++ b/Master/texmf-dist/tex/context/base/lang-lab.lua
@@ -6,70 +6,21 @@ if not modules then modules = { } end modules ['lang-lab'] = {
license = "see context related readme files"
}
---~ local function complete()
---~ local function process(what)
---~ for tag, data in next, what do
---~ for k, v in next, data.labels do
---~ languages[k] = true
---~ end
---~ end
---~ end
---~ process(languages.labels.data.titles)
---~ process(languages.labels.data.texts)
---~ process(languages.labels.data.functions)
---~ process(languages.labels.data.tags)
---~ local function process(what)
---~ for tag, data in next, what do
---~ local labels = data.labels
---~ for k, v in next, languages do
---~ if not labels[k] then
---~ labels[k] = ""
---~ end
---~ end
---~ end
---~ end
---~ process(languages.data.labels.titles)
---~ process(languages.data.labels.texts)
---~ process(languages.data.labels.functions)
---~ process(languages.data.labels.tags)
---~ end
---~
---~ local function strip(default)
---~ local function process(what)
---~ for tag, data in next, what do
---~ local labels = data.labels
---~ for k, v in next, labels do
---~ if v == "" then
---~ labels[k] = default
---~ end
---~ end
---~ end
---~ end
---~ process(languages.data.labels.titles)
---~ process(languages.data.labels.texts)
---~ process(languages.data.labels.functions)
---~ process(languages.data.labels.tags)
---~ end
---~
---~ complete()
---~ strip(false)
---~ strip()
-
---~ table.print(languages.data.labels,"languages.data.labels",false,true,true)
-
--- this will move
-
local format, find = string.format, string.find
local next, rawget, type = next, rawget, type
-local prtcatcodes = tex.prtcatcodes
local lpegmatch = lpeg.match
+local formatters = string.formatters
-languages.labels = languages.labels or { }
+local prtcatcodes = catcodes.numbers.prtcatcodes -- todo: use different method
local trace_labels = false trackers.register("languages.labels", function(v) trace_labels = v end)
local report_labels = logs.reporter("languages","labels")
-local variables = interfaces.variables
+languages.labels = languages.labels or { }
+local labels = languages.labels
+
+local variables = interfaces.variables
+local settings_to_array = utilities.parsers.settings_to_array
local splitter = lpeg.splitat(":")
@@ -77,31 +28,32 @@ local function split(tag)
return lpegmatch(splitter,tag)
end
-languages.labels.split = split
+labels.split = split
-local function definelanguagelabels(data,command,tag,rawtag)
+local contextsprint = context.sprint
+
+local function definelanguagelabels(data,class,tag,rawtag)
for language, text in next, data.labels do
if text == "" then
-- skip
elseif type(text) == "table" then
- context("\\%s[%s][%s={{%s},{%s}}]",command,language,tag,text[1],text[2])
+ contextsprint(prtcatcodes,"\\setlabeltextpair{",class,"}{",language,"}{",tag,"}{",text[1],"}{",text[2],"}")
if trace_labels then
- report_labels("language '%s', defining label '%s' as '%s' and '%s'",language,rawtag,text[1],text[2])
+ report_labels("language %a, defining label %a as %a and %a",language,rawtag,text[1],text[2])
end
else
- context("\\%s[%s][%s={{%s},}]",command,language,tag,text)
+ contextsprint(prtcatcodes,"\\setlabeltextpair{",class,"}{",language,"}{",tag,"}{",text,"}{}")
if trace_labels then
- report_labels("language '%s', defining label '%s' as '%s'",language,rawtag,text)
+ report_labels("language %a, defining label %a as %a",language,rawtag,text)
end
end
end
end
-function languages.labels.define(command,name,prefixed)
+function labels.define(class,name,prefixed)
local list = languages.data.labels[name]
if list then
- report_labels("defining label set '%s'",name)
- context.pushcatcodes(prtcatcodes) -- context.unprotect
+ report_labels("defining label set %a",name)
for tag, data in next, list do
if data.hidden then
-- skip
@@ -110,45 +62,81 @@ function languages.labels.define(command,name,prefixed)
if second then
if rawget(variables,first) then
if rawget(variables,second) then
- definelanguagelabels(data,command,format("\\v!%s:\\v!%s",first,second),tag)
+ definelanguagelabels(data,class,formatters["\\v!%s:\\v!%s"](first,second),tag)
else
- definelanguagelabels(data,command,format("\\v!%s:%s",first,second),tag)
+ definelanguagelabels(data,class,formatters["\\v!%s:%s"](first,second),tag)
end
- elseif rawget(variables,second) then
- definelanguagelabels(data,command,format("%s:\\v!%s",first,second),tag)
+ elseif rawget(variables,second) then
+ definelanguagelabels(data,class,formatters["%s:\\v!%s"](first,second),tag)
else
- definelanguagelabels(data,command,format("%s:%s",first,second),tag)
+ definelanguagelabels(data,class,formatters["%s:%s"](first,second),tag)
end
elseif rawget(variables,rawtag) then
- definelanguagelabels(data,command,format("\\v!%s",tag),tag)
+ definelanguagelabels(data,class,formatters["\\v!%s"](tag),tag)
else
- definelanguagelabels(data,command,tag,tag)
+ definelanguagelabels(data,class,tag,tag)
end
else
- definelanguagelabels(data,command,tag,tag)
+ definelanguagelabels(data,class,tag,tag)
end
end
- context.popcatcodes() -- context.protect
else
- report_labels("unknown label set '%s'",name)
+ report_labels("unknown label set %a",name)
end
end
---~ function languages.labels.check()
---~ for category, list in next, languages.data.labels do
---~ for tag, specification in next, list do
---~ for language, text in next, specification.labels do
---~ if type(text) == "string" and find(text,",") then
---~ report_labels("label with comma: category '%s', language '%s', tag '%s', text '%s'",
---~ category, language, tag, text)
---~ end
---~ end
---~ end
---~ end
---~ end
---~
---~ languages.labels.check()
+-- function labels.check()
+-- for category, list in next, languages.data.labels do
+-- for tag, specification in next, list do
+-- for language, text in next, specification.labels do
+-- if type(text) == "string" and find(text,",") then
+-- report_labels("warning: label with comma found, category %a, language %a, tag %a, text %a",
+-- category, language, tag, text)
+-- end
+-- end
+-- end
+-- end
+-- end
+--
+-- labels.check()
+
+-- interface
+
+commands.definelabels = labels.define
-- function commands.setstrippedtextprefix(str)
-- context(string.strip(str))
-- end
+
+-- list : { "a", "b", "c" }
+-- separator : ", "
+-- last : " and "
+
+-- text : "a,b,c"
+-- separators : "{, },{ and }"
+
+function commands.concatcommalist(settings) -- it's too easy to forget that this one is there
+ local list = settings.list or settings_to_array(settings.text or "")
+ local size = #list
+ local command = settings.command and context[settings.command] or context
+ if size > 1 then
+ local separator, last = " ", " "
+ if settings.separators then
+ local set = settings_to_array(settings.separators)
+ separator = set[1] or settings.separator or separator
+ last = set[2] or settings.last or last
+ else
+ separator = settings.separator or separator
+ last = settings.last or last
+ end
+ command(list[1])
+ for i=2,size-1 do
+ context(separator)
+ command(list[i])
+ end
+ context(last)
+ end
+ if size > 0 then
+ command(list[size])
+ end
+end