summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lang-ini.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lang-ini.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/lang-ini.lua179
1 files changed, 64 insertions, 115 deletions
diff --git a/Master/texmf-dist/tex/context/base/lang-ini.lua b/Master/texmf-dist/tex/context/base/lang-ini.lua
index 97528097f15..4ae7656d354 100644
--- a/Master/texmf-dist/tex/context/base/lang-ini.lua
+++ b/Master/texmf-dist/tex/context/base/lang-ini.lua
@@ -17,7 +17,6 @@ if not modules then modules = { } end modules ['lang-ini'] = {
--~ lang:hyphenation(string) string = lang:hyphenation() lang:clear_hyphenation()
local type, tonumber = type, tonumber
-local utf = unicode.utf8
local utfbyte = utf.byte
local format, gsub = string.format, string.gsub
local concat, sortedkeys, sortedpairs = table.concat, table.sortedkeys, table.sortedpairs
@@ -29,12 +28,14 @@ local trace_patterns = false trackers.register("languages.patterns", function(v
local report_initialization = logs.reporter("languages","initialization")
-local prehyphenchar = lang.prehyphenchar -- global per language
+local prehyphenchar = lang.prehyphenchar -- global per language
local posthyphenchar = lang.posthyphenchar -- global per language
local lefthyphenmin = lang.lefthyphenmin
local righthyphenmin = lang.righthyphenmin
+local lang = lang
lang.exceptions = lang.hyphenation
+local new_langage = lang.new
languages = languages or {}
local languages = languages
@@ -65,7 +66,7 @@ local function resolve(tag)
if data then
instance = data.instance
if not instance then
- instance = lang.new(data.number)
+ instance = new_langage(data.number)
data.instance = instance
end
end
@@ -78,7 +79,7 @@ local function tolang(what) -- returns lang object
if data then
local instance = data.lang
if not instance then
- instance = lang.new(data.number)
+ instance = new_langage(data.number)
data.instance = instance
end
return instance
@@ -87,7 +88,8 @@ end
-- languages.tolang = tolang
--- todo: en+de => merge
+-- patterns=en
+-- patterns=en,de
local function loaddefinitions(tag,specification)
statistics.starttiming(languages)
@@ -95,44 +97,44 @@ local function loaddefinitions(tag,specification)
local definitions = settings_to_array(specification.patterns or "")
if #definitions > 0 then
if trace_patterns then
- report_initialization("pattern specification for language '%s': %s",tag,specification.patterns)
+ report_initialization("pattern specification for language %a: %s",tag,specification.patterns)
end
local dataused, ok = data.used, false
for i=1,#definitions do
local definition = definitions[i]
- if definition ~= "" then
- if definition == "reset" then -- interfaces.variables.reset
+ if definition == "" then
+ -- error
+ elseif definition == "reset" then -- interfaces.variables.reset
+ if trace_patterns then
+ report_initialization("clearing patterns for language %a",tag)
+ end
+ instance:clear_patterns()
+ elseif not dataused[definition] then
+ dataused[definition] = definition
+ local filename = "lang-" .. definition .. ".lua"
+ local fullname = resolvers.findfile(filename) or ""
+ if fullname ~= "" then
if trace_patterns then
- report_initialization("clearing patterns for language '%s'",tag)
+ report_initialization("loading definition %a for language %a from %a",definition,tag,fullname)
end
- instance:clear_patterns()
- elseif not dataused[definition] then
- dataused[definition] = definition
- local filename = "lang-" .. definition .. ".lua"
- local fullname = resolvers.findfile(filename) or ""
- if fullname ~= "" then
- if trace_patterns then
- report_initialization("loading definition '%s' for language '%s' from '%s'",definition,tag,fullname)
- end
- local defs = dofile(fullname) -- use regular loader instead
- if defs then -- todo: version test
- ok, nofloaded = true, nofloaded + 1
- instance:patterns (defs.patterns and defs.patterns.data or "")
- instance:hyphenation(defs.exceptions and defs.exceptions.data or "")
- else
- report_initialization("invalid definition '%s' for language '%s' in '%s'",definition,tag,filename)
- end
- elseif trace_patterns then
- report_initialization("invalid definition '%s' for language '%s' in '%s'",definition,tag,filename)
+ local defs = dofile(fullname) -- use regular loader instead
+ if defs then -- todo: version test
+ ok, nofloaded = true, nofloaded + 1
+ instance:patterns (defs.patterns and defs.patterns .data or "")
+ instance:hyphenation(defs.exceptions and defs.exceptions.data or "")
+ else
+ report_initialization("invalid definition %a for language %a in %a",definition,tag,filename)
end
elseif trace_patterns then
- report_initialization("definition '%s' for language '%s' already loaded",definition,tag)
+ report_initialization("invalid definition %a for language %a in %a",definition,tag,filename)
end
+ elseif trace_patterns then
+ report_initialization("definition %a for language %a already loaded",definition,tag)
end
end
return ok
elseif trace_patterns then
- report_initialization("no definitions for language '%s'",tag)
+ report_initialization("no definitions for language %a",tag)
end
statistics.stoptiming(languages)
end
@@ -144,7 +146,7 @@ local noflanguages = storage.shared.noflanguages
function languages.define(tag,parent)
noflanguages = noflanguages + 1
if trace_patterns then
- report_initialization("assigning number %s to %s",noflanguages,tag)
+ report_initialization("assigning number %a to %a",noflanguages,tag)
end
numbers[noflanguages] = tag
registered[tag] = {
@@ -161,7 +163,7 @@ function languages.define(tag,parent)
storage.shared.noflanguages = noflanguages
end
-function languages.synonym(synonym,tag) -- convenience function
+function languages.setsynonym(synonym,tag) -- convenience function
local l = registered[tag]
if l then
l.synonyms[synonym] = true -- maybe some day more info
@@ -169,7 +171,7 @@ function languages.synonym(synonym,tag) -- convenience function
end
function languages.installed(separator)
- context(concat(sortedkeys(registered),separator or ","))
+ return concat(sortedkeys(registered),separator or ",")
end
function languages.current(n)
@@ -187,8 +189,6 @@ function languages.association(tag) -- not yet used
local lat = tag and associated[tag]
if lat then
return lat[1], lat[2]
- else
- return nil, nil
end
end
@@ -204,7 +204,7 @@ end
-- a bit messy, we will do all language setting in lua as we can now assign
-- and 'patterns' will go away here.
-function languages.setdirty(tag)
+function languages.unload(tag)
local l = registered[tag]
if l then
l.dirty = true
@@ -217,25 +217,21 @@ if environment.initex then
return 0
end
- function commands.languagenumber()
- context(0)
- end
-
else
- local function getnumber(tag,default,patterns)
+ function languages.getnumber(tag,default,patterns)
local l = registered[tag]
if l then
if l.dirty then
if trace_patterns then
- report_initialization("checking patterns for %s (%s)",tag,default)
+ report_initialization("checking patterns for %a with default %a",tag,default)
end
-- patterns is already resolved to parent patterns if applicable
if patterns and patterns ~= "" then
if l.patterns ~= patterns then
l.patterns = patterns
if trace_patterns then
- report_initialization("loading patterns for '%s' using specification '%s'",tag,patterns)
+ report_initialization("loading patterns for %a using specification %a",tag,patterns)
end
loaddefinitions(tag,l)
else
@@ -244,13 +240,13 @@ else
elseif l.patterns == "" then
l.patterns = tag
if trace_patterns then
- report_initialization("loading patterns for '%s' using tag",tag)
+ report_initialization("loading patterns for %a using tag",tag)
end
local ok = loaddefinitions(tag,l)
if not ok and tag ~= default then
l.patterns = default
if trace_patterns then
- report_initialization("loading patterns for '%s' using default",tag)
+ report_initialization("loading patterns for %a using default",tag)
end
loaddefinitions(tag,l)
end
@@ -264,12 +260,6 @@ else
end
end
- languages.getnumber = getnumber
-
- function commands.languagenumber(tag,default,patterns)
- context(getnumber(tag,default,patterns))
- end
-
end
-- not that usefull, global values
@@ -294,7 +284,7 @@ function languages.loadwords(tag,filename)
end
end
-function languages.exceptions(tag,str)
+function languages.setexceptions(tag,str)
local data, instance = resolve(tag)
if data then
instance:hyphenation(string.strip(str)) -- we need to strip leading spaces
@@ -311,9 +301,9 @@ function languages.hyphenate(tag,str)
end
end
---~ hyphenation.define ("zerolanguage")
---~ hyphenation.loadpatterns ("zerolanguage") -- else bug
---~ hyphenation.loadexceptions("zerolanguage") -- else bug
+-- hyphenation.define ("zerolanguage")
+-- hyphenation.loadpatterns ("zerolanguage") -- else bug
+-- hyphenation.loadexceptions("zerolanguage") -- else bug
languages.logger = languages.logger or { }
@@ -322,13 +312,13 @@ function languages.logger.report()
for tag, l in sortedpairs(registered) do
if l.loaded then
r = r + 1
- result[r] = format("%s:%s:%s", tag, l.parent, l.number)
+ result[r] = format("%s:%s:%s",tag,l.parent,l.number)
end
end
- return (r > 0 and concat(result," ")) or "none"
+ return r > 0 and concat(result," ") or "none"
end
--- must happen at the tex end
+-- must happen at the tex end .. will use lang-def.lua
languages.associate('en','latn','eng')
languages.associate('uk','latn','eng')
@@ -347,60 +337,19 @@ statistics.register("language load time", function()
return statistics.elapsedseconds(languages, format(", nofpatterns: %s",nofloaded))
end)
---~ -- obsolete
---~ --
---~ -- loading the 26 languages that we normally load in mkiv, the string based variant
---~ -- takes .84 seconds (probably due to the sub's) while the lpeg variant takes .78
---~ -- seconds
---~ --
---~ -- the following lpeg can probably be improved (it was one of the first I made)
-
---~ local leftbrace = lpeg.P("{")
---~ local rightbrace = lpeg.P("}")
---~ local spaces = lpeg.S(" \r\n\t\f")
---~ local spacing = spaces^0
---~ local validchar = 1-(spaces+rightbrace+leftbrace)
---~ local validword = validchar^1
---~ local content = spacing * leftbrace * spacing * lpeg.C((spacing * validword)^0) * spacing * rightbrace * lpeg.P(true)
---~
---~ local command = lpeg.P("\\patterns")
---~ local parser = (1-command)^0 * command * content
---~
---~ local function filterpatterns(filename)
---~ return lpegmatch(parser,io.loaddata(resolvers.findfile(filename)) or "")
---~ end
---~
---~ local command = lpeg.P("\\hyphenation")
---~ local parser = (1-command)^0 * command * content
---~
---~ local function filterexceptions(filename)
---~ return lpegmatch(parser,io.loaddata(resolvers.findfile(filename)) or "") -- "" ?
---~ end
---~
---~ local function loadthem(tag, filename, filter, target)
---~ statistics.starttiming(languages)
---~ local data, instance = resolve(tag)
---~ local fullname = (filename and filename ~= "" and resolvers.findfile(filename)) or ""
---~ local ok = fullname ~= ""
---~ if ok then
---~ if trace_patterns then
---~ report_initialization("filtering %s for language '%s' from '%s'",target,tag,fullname)
---~ end
---~ lang[target](data,filter(fullname) or "")
---~ else
---~ if trace_patterns then
---~ report_initialization("no %s for language '%s' in '%s'",target,tag,filename or "?")
---~ end
---~ lang[target](instance,"")
---~ end
---~ statistics.stoptiming(languages)
---~ return ok
---~ end
---~
---~ function hyphenation.loadpatterns(tag, patterns)
---~ return loadthem(tag, patterns, filterpatterns, "patterns")
---~ end
---~
---~ function hyphenation.loadexceptions(tag, exceptions)
---~ return loadthem(tag, exceptions, filterexceptions, "exceptions")
---~ end
+-- interface
+
+local getnumber = languages.getnumber
+
+function commands.languagenumber(tag,default,patterns)
+ context(getnumber(tag,default,patterns))
+end
+
+function commands.installedlanguages(separator)
+ context(languages.installed(separator))
+end
+
+commands.definelanguage = languages.define
+commands.setlanguagesynonym = languages.setsynonym
+commands.unloadlanguage = languages.unload
+commands.setlanguageexceptions = languages.setexceptions