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.lua100
1 files changed, 62 insertions, 38 deletions
diff --git a/Master/texmf-dist/tex/context/base/lang-lab.lua b/Master/texmf-dist/tex/context/base/lang-lab.lua
index 1947616a99c..360f2aa11b5 100644
--- a/Master/texmf-dist/tex/context/base/lang-lab.lua
+++ b/Master/texmf-dist/tex/context/base/lang-lab.lua
@@ -61,56 +61,77 @@ if not modules then modules = { } end modules ['lang-lab'] = {
local format, find = string.format, string.find
local next, rawget, type = next, rawget, type
-local texsprint = tex.sprint
local prtcatcodes = tex.prtcatcodes
+local lpegmatch = lpeg.match
-languages.labels = languages.labels or { }
-
-local trace_labels = false trackers.register("languages.labels", function(v) trace_labels = v end)
+languages.labels = languages.labels or { }
+local trace_labels = false trackers.register("languages.labels", function(v) trace_labels = v end)
local report_labels = logs.reporter("languages","labels")
-function languages.labels.define()
- local variables = interfaces.variables
- local data = languages.data.labels
- local function define(command,list,prefixed)
- if list then
- for tag, data in next, list do
- if data.hidden then
- -- skip
- else
- for language, text in next, data.labels do
- if text == "" then
- -- skip
- elseif prefixed and rawget(variables,tag) then
- if type(text) == "table" then
- texsprint(prtcatcodes,format("\\%s[%s][\\v!%s={{%s},{%s}}]",command,language,tag,text[1],text[2]))
- else
- texsprint(prtcatcodes,format("\\%s[%s][\\v!%s={{%s},}]",command,language,tag,text))
- end
+local variables = interfaces.variables
+
+local splitter = lpeg.splitat(":")
+
+local function split(tag)
+ return lpegmatch(splitter,tag)
+end
+
+languages.labels.split = split
+
+local function definelanguagelabels(data,command,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])
+ if trace_labels then
+ report_labels("language '%s', defining label '%s' as '%s' and '%s'",language,rawtag,text[1],text[2])
+ end
+ else
+ context("\\%s[%s][%s={{%s},}]",command,language,tag,text)
+ if trace_labels then
+ report_labels("language '%s', defining label '%s' as '%s'",language,rawtag,text)
+ end
+ end
+ end
+end
+
+function languages.labels.define(command,name,prefixed)
+ local list = languages.data.labels[name]
+ if list then
+ report_labels("defining label set '%s'",name)
+ context.pushcatcodes(prtcatcodes) -- context.unprotect
+ for tag, data in next, list do
+ if data.hidden then
+ -- skip
+ elseif prefixed then
+ local first, second = lpegmatch(splitter,tag)
+ if second then
+ if rawget(variables,first) then
+ if rawget(variables,second) then
+ definelanguagelabels(data,command,format("\\v!%s:\\v!%s",first,second),tag)
else
- if type(text) == "table" then
- texsprint(prtcatcodes,format("\\%s[%s][%s={{%s},{%s}}]",command,language,tag,text[1],text[2]))
- else
- texsprint(prtcatcodes,format("\\%s[%s][%s={{%s},}]",command,language,tag,text))
- end
- end
- if trace_labels then
- if type(text) == "table" then
- report_labels("language '%s', defining label '%s' as '%s' and '%s'",language,tag,text[1],text[2])
- else
- report_labels("language '%s', defining label '%s' as '%s'",language,tag,text)
- end
+ definelanguagelabels(data,command,format("\\v!%s:%s",first,second),tag)
end
+ elseif rawget(variables,second) then
+ definelanguagelabels(data,command,format("%s:\\v!%s",first,second),tag)
+ else
+ definelanguagelabels(data,command,format("%s:%s",first,second),tag)
end
+ elseif rawget(variables,rawtag) then
+ definelanguagelabels(data,command,format("\\v!%s",tag),tag)
+ else
+ definelanguagelabels(data,command,tag,tag)
end
+ else
+ definelanguagelabels(data,command,tag,tag)
end
end
+ context.popcatcodes() -- context.protect
+ else
+ report_labels("unknown label set '%s'",name)
end
- define("setupheadtext", data.titles, true)
- define("setuplabeltext", data.texts, true)
- define("setupmathlabeltext", data.functions)
- define("setuptaglabeltext", data.tags)
end
--~ function languages.labels.check()
@@ -128,3 +149,6 @@ end
--~
--~ languages.labels.check()
+-- function commands.setstrippedtextprefix(str)
+-- context(string.strip(str))
+-- end