diff options
author | Hans Hagen <pragma@wxs.nl> | 2013-05-20 02:00:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2013-05-20 02:00:00 +0200 |
commit | bd95a21d2b31a5fab1b4cc7c2b0334823fb3a3e9 (patch) | |
tree | 831128c411476f077eb7910d8c08f524d3ee43ec /tex/context/base/lang-lab.lua | |
parent | 9a10021cd4cb23995ad3ffa915fc5b7f6890aaf8 (diff) | |
download | context-bd95a21d2b31a5fab1b4cc7c2b0334823fb3a3e9.tar.gz |
beta 2013.05.20 02:00
Diffstat (limited to 'tex/context/base/lang-lab.lua')
-rw-r--r-- | tex/context/base/lang-lab.lua | 284 |
1 files changed, 142 insertions, 142 deletions
diff --git a/tex/context/base/lang-lab.lua b/tex/context/base/lang-lab.lua index c83cd8bc8..91c258418 100644 --- a/tex/context/base/lang-lab.lua +++ b/tex/context/base/lang-lab.lua @@ -1,142 +1,142 @@ -if not modules then modules = { } end modules ['lang-lab'] = {
- version = 1.001,
- comment = "companion to lang-lab.mkiv",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
-local format, find = string.format, string.find
-local next, rawget, type = next, rawget, type
-local lpegmatch = lpeg.match
-local formatters = string.formatters
-
-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")
-
-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(":")
-
-local function split(tag)
- return lpegmatch(splitter,tag)
-end
-
-labels.split = split
-
-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
- contextsprint(prtcatcodes,"\\setlabeltextpair{",class,"}{",language,"}{",tag,"}{",text[1],"}{",text[2],"}")
- if trace_labels then
- report_labels("language %a, defining label %a as %a and %a",language,rawtag,text[1],text[2])
- end
- else
- contextsprint(prtcatcodes,"\\setlabeltextpair{",class,"}{",language,"}{",tag,"}{",text,"}{}")
- if trace_labels then
- report_labels("language %a, defining label %a as %a",language,rawtag,text)
- end
- end
- end
-end
-
-function labels.define(class,name,prefixed)
- local list = languages.data.labels[name]
- if list then
- report_labels("defining label set %a",name)
- 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,class,formatters["\\v!%s:\\v!%s"](first,second),tag)
- else
- definelanguagelabels(data,class,formatters["\\v!%s:%s"](first,second),tag)
- end
- elseif rawget(variables,second) then
- definelanguagelabels(data,class,formatters["%s:\\v!%s"](first,second),tag)
- else
- definelanguagelabels(data,class,formatters["%s:%s"](first,second),tag)
- end
- elseif rawget(variables,rawtag) then
- definelanguagelabels(data,class,formatters["\\v!%s"](tag),tag)
- else
- definelanguagelabels(data,class,tag,tag)
- end
- else
- definelanguagelabels(data,class,tag,tag)
- end
- end
- else
- report_labels("unknown label set %a",name)
- end
-end
-
--- 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
+if not modules then modules = { } end modules ['lang-lab'] = { + version = 1.001, + comment = "companion to lang-lab.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local format, find = string.format, string.find +local next, rawget, type = next, rawget, type +local lpegmatch = lpeg.match +local formatters = string.formatters + +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") + +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(":") + +local function split(tag) + return lpegmatch(splitter,tag) +end + +labels.split = split + +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 + contextsprint(prtcatcodes,"\\setlabeltextpair{",class,"}{",language,"}{",tag,"}{",text[1],"}{",text[2],"}") + if trace_labels then + report_labels("language %a, defining label %a as %a and %a",language,rawtag,text[1],text[2]) + end + else + contextsprint(prtcatcodes,"\\setlabeltextpair{",class,"}{",language,"}{",tag,"}{",text,"}{}") + if trace_labels then + report_labels("language %a, defining label %a as %a",language,rawtag,text) + end + end + end +end + +function labels.define(class,name,prefixed) + local list = languages.data.labels[name] + if list then + report_labels("defining label set %a",name) + 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,class,formatters["\\v!%s:\\v!%s"](first,second),tag) + else + definelanguagelabels(data,class,formatters["\\v!%s:%s"](first,second),tag) + end + elseif rawget(variables,second) then + definelanguagelabels(data,class,formatters["%s:\\v!%s"](first,second),tag) + else + definelanguagelabels(data,class,formatters["%s:%s"](first,second),tag) + end + elseif rawget(variables,rawtag) then + definelanguagelabels(data,class,formatters["\\v!%s"](tag),tag) + else + definelanguagelabels(data,class,tag,tag) + end + else + definelanguagelabels(data,class,tag,tag) + end + end + else + report_labels("unknown label set %a",name) + end +end + +-- 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 |