diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lang-wrd.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/lang-wrd.lua | 115 |
1 files changed, 24 insertions, 91 deletions
diff --git a/Master/texmf-dist/tex/context/base/lang-wrd.lua b/Master/texmf-dist/tex/context/base/lang-wrd.lua index 3d3cb6aec99..06a2311a63e 100644 --- a/Master/texmf-dist/tex/context/base/lang-wrd.lua +++ b/Master/texmf-dist/tex/context/base/lang-wrd.lua @@ -1,4 +1,4 @@ -if not modules then modules = { } end modules ['lang-ini'] = { +if not modules then modules = { } end modules ['lang-wrd'] = { version = 1.001, comment = "companion to lang-ini.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", @@ -6,8 +6,8 @@ if not modules then modules = { } end modules ['lang-ini'] = { license = "see context related readme files" } -local utf = unicode.utf8 -local lower, utfchar = string.lower, utf.char +local lower = string.lower +local utfchar = utf.char local concat = table.concat local lpegmatch = lpeg.match local P, S, Cs = lpeg.P, lpeg.S, lpeg.Cs @@ -26,13 +26,13 @@ words.threshold = 4 local numbers = languages.numbers local registered = languages.registered -local set_attribute = node.set_attribute -local unset_attribute = node.unset_attribute local traverse_nodes = node.traverse local wordsdata = words.data local chardata = characters.data local tasks = nodes.tasks +local unsetvalue = attributes.unsetvalue + local nodecodes = nodes.nodecodes local kerncodes = nodes.kerncodes @@ -60,7 +60,7 @@ local loaded = { } -- we share lists function words.load(tag,filename) local fullname = resolvers.findfile(filename,'other text file') or "" if fullname ~= "" then - report_words("loading word file '%s'",fullname) + report_words("loading word file %a",fullname) statistics.starttiming(languages) local list = loaded[fullname] if not list then @@ -72,7 +72,7 @@ function words.load(tag,filename) wordsdata[tag] = list statistics.stoptiming(languages) else - report_words("missing word file '%s'",filename) + report_words("missing word file %a",filename) end end @@ -90,76 +90,11 @@ function words.found(id, str) end end --- The following code is an adaption of experimental code for --- hyphenating and spell checking. +-- The following code is an adaption of experimental code for hyphenating and +-- spell checking. -- there is an n=1 problem somewhere in nested boxes ---~ local function mark_words(head,whenfound) -- can be optimized and shared ---~ local current, start, str, language, n, done = head, nil, "", nil, 0, false ---~ local function action() ---~ if #str > 0 then ---~ local f = whenfound(language,str) ---~ if f then ---~ done = true ---~ for i=1,n do ---~ f(start) ---~ start = start.next ---~ end ---~ end ---~ end ---~ str, start, n = "", nil, 0 ---~ end ---~ while current do ---~ local id = current.id ---~ if id == glyph_code then ---~ local a = current.lang ---~ if a then ---~ if a ~= language then ---~ if start then ---~ action() ---~ end ---~ language = a ---~ end ---~ elseif start then ---~ action() ---~ language = a ---~ end ---~ local components = current.components ---~ if components then ---~ start = start or current ---~ n = n + 1 ---~ for g in traverse_nodes(components) do ---~ str = str .. utfchar(g.char) ---~ end ---~ else ---~ local code = current.char ---~ local data = chardata[code] ---~ if is_letter[data.category] then ---~ start = start or current ---~ n = n + 1 ---~ str = str .. utfchar(code) -- slow, maybe str should be a table (and given max) ---~ elseif start then ---~ action() ---~ end ---~ end ---~ elseif id == disc_code then ---~ if n > 0 then ---~ n = n + 1 ---~ end ---~ elseif id == kern_code and current.subtype == kerning_code and start then ---~ -- ok ---~ elseif start then ---~ action() ---~ end ---~ current = current.next ---~ end ---~ if start then ---~ action() ---~ end ---~ return head, done ---~ end - local function mark_words(head,whenfound) -- can be optimized and shared local current, language, done = head, nil, nil, 0, false local str, s, nds, n = { }, 0, { }, 0 -- n could also be a table, saves calls @@ -263,21 +198,19 @@ end local cache = { } -- can also be done with method 1 -- frozen colors once used -setmetatable(cache, { - __index = function(t,k) -- k == language, numbers[k] == tag - local c - if type(k) == "string" then - c = colist[k] - elseif k < 0 then - c = colist["word:unset"] - else - c = colist["word:" .. (numbers[k] or "unset")] or colist["word:unknown"] - end - local v = c and function(n) set_attribute(n,a_color,c) end or false - t[k] = v - return v +table.setmetatableindex(cache, function(t,k) -- k == language, numbers[k] == tag + local c + if type(k) == "string" then + c = colist[k] + elseif k < 0 then + c = colist["word:unset"] + else + c = colist["word:" .. (numbers[k] or "unset")] or colist["word:unknown"] end -} ) + local v = c and function(n) n[a_color] = c end or false + t[k] = v + return v +end) -- method 1 @@ -293,7 +226,7 @@ end methods[1] = function(head) for n in traverse_nodes(head) do - unset_attribute(n,a_color) -- hm, not that selective (reset color) + n[a_color] = unsetvalue -- hm, not that selective (reset color) end return mark_words(head,sweep) end @@ -374,7 +307,7 @@ local function dumpusedwords() if dumpthem then collected.threshold = words.threshold dumpname = dumpname or file.addsuffix(tex.jobname,"words") - report_words("saving list of used words in '%s'",dumpname) + report_words("saving list of used words in %a",dumpname) io.savedata(dumpname,table.serialize(collected,true)) -- table.tofile(dumpname,list,true) end @@ -394,7 +327,7 @@ end methods[3] = function(head) for n in traverse_nodes(head) do - unset_attribute(n,a_color) + n[a_color] = unsetvalue end return mark_words(head,sweep) end |