From 24c19e9dcac5d1ec7e6b26fb86d34f0756a8d98a Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Thu, 20 May 2010 20:00:00 +0200 Subject: beta 2010.05.20 20:00 --- scripts/context/lua/mtx-context.lua | 4 +- scripts/context/lua/mtxrun.lua | 61 +++++++- scripts/context/stubs/mswin/mtxrun.lua | 61 +++++++- scripts/context/stubs/unix/mtxrun | 61 +++++++- tex/context/base/buff-ver.mkiv | 1 + tex/context/base/bxml-apa.mkiv | 14 +- tex/context/base/cont-new.tex | 2 +- tex/context/base/context.mkiv | 1 + tex/context/base/context.tex | 2 +- tex/context/base/l-table.lua | 55 ++++++- tex/context/base/lang-sla.tex | 10 +- tex/context/base/lang-wrd.lua | 138 +++++++++++------- tex/context/base/lang-wrd.mkiv | 17 ++- tex/context/base/lxml-sor.lua | 13 +- tex/context/base/lxml-xml.lua | 6 +- tex/context/base/node-tsk.lua | 1 + tex/context/base/sort-ini.lua | 216 ++++++++++++++++------------ tex/context/base/sort-lan.lua | 48 +++++-- tex/context/base/sort-lan.mkii | 50 +++---- tex/context/base/strc-reg.lua | 31 ++-- tex/context/base/strc-reg.mkiv | 3 +- tex/context/base/strc-syn.lua | 8 +- tex/generic/context/luatex-fonts-merged.lua | 57 +++++++- 23 files changed, 601 insertions(+), 259 deletions(-) diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua index df1ff3b85..79e74e407 100644 --- a/scripts/context/lua/mtx-context.lua +++ b/scripts/context/lua/mtx-context.lua @@ -237,8 +237,8 @@ do commands[e.at and e.at['name'] or "unknown"] = e end - local suffix = xml.filter(ctxdata.xmldata,"/ctx:job/ctx:preprocess/attribute(suffix)") or ctxdata.suffix - local runlocal = xml.filter(ctxdata.xmldata,"/ctx:job/ctx:preprocess/ctx:processors/attribute(local)") + local suffix = xml.filter(ctxdata.xmldata,"/ctx:job/ctx:preprocess/attribute('suffix')") or ctxdata.suffix + local runlocal = xml.filter(ctxdata.xmldata,"/ctx:job/ctx:preprocess/ctx:processors/attribute('local')") runlocal = toboolean(runlocal) diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index d3e50e00e..ae0ee162f 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -525,7 +525,55 @@ local concat, sort, insert, remove = table.concat, table.sort, table.insert, tab local format, find, gsub, lower, dump, match = string.format, string.find, string.gsub, string.lower, string.dump, string.match local getmetatable, setmetatable = getmetatable, setmetatable local type, next, tostring, tonumber, ipairs = type, next, tostring, tonumber, ipairs -local unpack = unpack or table.unpack + +-- Starting with version 5.2 Lua no longer provide ipairs, which makes +-- sense. As we already used the for loop and # in most places the +-- impact on ConTeXt was not that large; the remaining ipairs already +-- have been replaced. In a similar fashio we also hardly used pairs. +-- +-- Just in case, we provide the fallbacks as discussed in Programming +-- in Lua (http://www.lua.org/pil/7.3.html): + +if not ipairs then + + -- for k, v in ipairs(t) do ... end + -- for k=1,#t do local v = t[k] ... end + + local function iterate(a,i) + i = i + 1 + local v = a[i] + if v ~= nil then + return i, v --, nil + end + end + + function ipairs(a) + return iterate, a, 0 + end + +end + +if not pairs then + + -- for k, v in pairs(t) do ... end + -- for k, v in next, t do ... end + + function pairs(t) + return next, t -- , nil + end + +end + +-- Also, unpack has been moved to the table table, and for compatiility +-- reasons we provide both now. + +if not table.unpack then + table.unpack = _G.unpack +elseif not unpack then + _G.unpack = table.unpack +end + +-- extra functions, some might go (when not used) function table.strip(tab) local lst = { } @@ -712,7 +760,7 @@ end table.fastcopy = fastcopy table.copy = copy --- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) +-- roughly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) function table.sub(t,i,j) return { unpack(t,i,j) } @@ -735,7 +783,7 @@ function table.one_entry(t) -- obolete, use inline code instead return n and not next(t,n) end ---~ function table.starts_at(t) -- obsolete, not nice +--~ function table.starts_at(t) -- obsolete, not nice anyway --~ return ipairs(t,1)(t,0) --~ end @@ -1374,6 +1422,7 @@ function table.insert_after_value(t,value,extra) end + end -- of closure do -- create closure to overcome 200 locals limit @@ -6974,8 +7023,10 @@ local function reverse(collected) end local function attribute(collected,name) - local at = collected and collected[1].at - return at and at[name] + if collected and #collected > 0 then + local at = collected[1].at + return at and at[name] + end end local function att(id,name) diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index d3e50e00e..ae0ee162f 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -525,7 +525,55 @@ local concat, sort, insert, remove = table.concat, table.sort, table.insert, tab local format, find, gsub, lower, dump, match = string.format, string.find, string.gsub, string.lower, string.dump, string.match local getmetatable, setmetatable = getmetatable, setmetatable local type, next, tostring, tonumber, ipairs = type, next, tostring, tonumber, ipairs -local unpack = unpack or table.unpack + +-- Starting with version 5.2 Lua no longer provide ipairs, which makes +-- sense. As we already used the for loop and # in most places the +-- impact on ConTeXt was not that large; the remaining ipairs already +-- have been replaced. In a similar fashio we also hardly used pairs. +-- +-- Just in case, we provide the fallbacks as discussed in Programming +-- in Lua (http://www.lua.org/pil/7.3.html): + +if not ipairs then + + -- for k, v in ipairs(t) do ... end + -- for k=1,#t do local v = t[k] ... end + + local function iterate(a,i) + i = i + 1 + local v = a[i] + if v ~= nil then + return i, v --, nil + end + end + + function ipairs(a) + return iterate, a, 0 + end + +end + +if not pairs then + + -- for k, v in pairs(t) do ... end + -- for k, v in next, t do ... end + + function pairs(t) + return next, t -- , nil + end + +end + +-- Also, unpack has been moved to the table table, and for compatiility +-- reasons we provide both now. + +if not table.unpack then + table.unpack = _G.unpack +elseif not unpack then + _G.unpack = table.unpack +end + +-- extra functions, some might go (when not used) function table.strip(tab) local lst = { } @@ -712,7 +760,7 @@ end table.fastcopy = fastcopy table.copy = copy --- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) +-- roughly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) function table.sub(t,i,j) return { unpack(t,i,j) } @@ -735,7 +783,7 @@ function table.one_entry(t) -- obolete, use inline code instead return n and not next(t,n) end ---~ function table.starts_at(t) -- obsolete, not nice +--~ function table.starts_at(t) -- obsolete, not nice anyway --~ return ipairs(t,1)(t,0) --~ end @@ -1374,6 +1422,7 @@ function table.insert_after_value(t,value,extra) end + end -- of closure do -- create closure to overcome 200 locals limit @@ -6974,8 +7023,10 @@ local function reverse(collected) end local function attribute(collected,name) - local at = collected and collected[1].at - return at and at[name] + if collected and #collected > 0 then + local at = collected[1].at + return at and at[name] + end end local function att(id,name) diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index d3e50e00e..ae0ee162f 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -525,7 +525,55 @@ local concat, sort, insert, remove = table.concat, table.sort, table.insert, tab local format, find, gsub, lower, dump, match = string.format, string.find, string.gsub, string.lower, string.dump, string.match local getmetatable, setmetatable = getmetatable, setmetatable local type, next, tostring, tonumber, ipairs = type, next, tostring, tonumber, ipairs -local unpack = unpack or table.unpack + +-- Starting with version 5.2 Lua no longer provide ipairs, which makes +-- sense. As we already used the for loop and # in most places the +-- impact on ConTeXt was not that large; the remaining ipairs already +-- have been replaced. In a similar fashio we also hardly used pairs. +-- +-- Just in case, we provide the fallbacks as discussed in Programming +-- in Lua (http://www.lua.org/pil/7.3.html): + +if not ipairs then + + -- for k, v in ipairs(t) do ... end + -- for k=1,#t do local v = t[k] ... end + + local function iterate(a,i) + i = i + 1 + local v = a[i] + if v ~= nil then + return i, v --, nil + end + end + + function ipairs(a) + return iterate, a, 0 + end + +end + +if not pairs then + + -- for k, v in pairs(t) do ... end + -- for k, v in next, t do ... end + + function pairs(t) + return next, t -- , nil + end + +end + +-- Also, unpack has been moved to the table table, and for compatiility +-- reasons we provide both now. + +if not table.unpack then + table.unpack = _G.unpack +elseif not unpack then + _G.unpack = table.unpack +end + +-- extra functions, some might go (when not used) function table.strip(tab) local lst = { } @@ -712,7 +760,7 @@ end table.fastcopy = fastcopy table.copy = copy --- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) +-- roughly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) function table.sub(t,i,j) return { unpack(t,i,j) } @@ -735,7 +783,7 @@ function table.one_entry(t) -- obolete, use inline code instead return n and not next(t,n) end ---~ function table.starts_at(t) -- obsolete, not nice +--~ function table.starts_at(t) -- obsolete, not nice anyway --~ return ipairs(t,1)(t,0) --~ end @@ -1374,6 +1422,7 @@ function table.insert_after_value(t,value,extra) end + end -- of closure do -- create closure to overcome 200 locals limit @@ -6974,8 +7023,10 @@ local function reverse(collected) end local function attribute(collected,name) - local at = collected and collected[1].at - return at and at[name] + if collected and #collected > 0 then + local at = collected[1].at + return at and at[name] + end end local function att(id,name) diff --git a/tex/context/base/buff-ver.mkiv b/tex/context/base/buff-ver.mkiv index e547e6f77..e80d2e773 100644 --- a/tex/context/base/buff-ver.mkiv +++ b/tex/context/base/buff-ver.mkiv @@ -566,6 +566,7 @@ \else \doadaptleftskip{\typingparameter\c!margin}% \fi + % no symbolic blanks ! \edef\!!stringa{\executeifdefined{\??bo\typingparameter\c!blank}{\typingparameter\c!blank}}% \scratchskip\executeifdefined{\??tp:\c!blank:\!!stringa}\!!stringa\relax \ifgridsnapping diff --git a/tex/context/base/bxml-apa.mkiv b/tex/context/base/bxml-apa.mkiv index 6ff21f59a..5fc87e5ef 100644 --- a/tex/context/base/bxml-apa.mkiv +++ b/tex/context/base/bxml-apa.mkiv @@ -188,7 +188,7 @@ \startxmlsetups bibtex:apa:common:title-it-and-series \bibxmldoif {title} { - \bgroup\it\bibxmlflush{title}\egroup + \bgroup\it\bibxmlflush{title}\/\egroup \bibxmldoif {series} { \bibtexlparent\bibxmlflush{series}\bibtexrparent } @@ -314,7 +314,7 @@ \bibxmlflush{title}\bibtexperiod } \bibxmldoifelse {journal} { - \bgroup\it\bibxmlflush{journal}\egroup + \bgroup\it\bibxmlflush{journal}\/\egroup } { \bibxmldoif {crossref} { In\bibtexspace\bibxmlflush{crossref} @@ -372,7 +372,7 @@ \bibxmldoif {volume} { \bibtexcomma volume\nonbreakablespace\bibxmlflush{volume} \bibxmldoif {series} { - \bibtexspace of\nonbreakablespace\bgroup\it\bibxmlflush{series}\egroup + \bibtexspace of\nonbreakablespace\bgroup\it\bibxmlflush{series}\/\egroup } \bibxmldoif {chapter} { \bibtexcomma\bibxmlflush{chapter} @@ -427,7 +427,7 @@ \bibxmldoif {volume} { \bibtexcomma volume\nonbreakablespace\bibxmlflush{volume} \bibxmldoif {series} { - \bibtexspace of\nonbreakablespace\bgroup\it\bibxmlflush{series}\egroup + \bibtexspace of\nonbreakablespace\bgroup\it\bibxmlflush{series}\/\egroup } \bibxmldoif {chapter} { \bibtexcomma\bibxmlflush{chapter} @@ -470,7 +470,7 @@ In\bibtexspace \bibxmldoifelse {title} { \bibxmlsetup{bibtex:format:editors}\bibtexcomma - \bgroup\it\bibxmlflush{title}\egroup + \bgroup\it\bibxmlflush{title}\/\egroup \bibxmldoif {series} { \bibxmldoif {volume} { \bibtexcomma number\bibtexspace\bibxmlflush{volume}\bibtexspace in @@ -509,7 +509,7 @@ \bibxmlflush{bibtex:apa:format:editors} \bibtexcomma\bibtexsingularplural{editor}{editors}\bibtexcomma } - \bgroup\it\bibxmlflush{title}\egroup + \bgroup\it\bibxmlflush{title}\/\egroup \bibxmldoif {series} { \bibxmldoif {volume} { \bibtexcomma number~\bibxmlflush{volume} in @@ -539,7 +539,7 @@ \startxmlsetups bibtex:apa:proceedings \bibxmlsetup{bibtex:apa:common:editor-or-key-and-year} \bibxmldoif {title} { - \bgroup\it\bibxmlflush{title}\egroup + \bgroup\it\bibxmlflush{title}\/\egroup \bibxmldoif {volume} { \bibtexcomma number\bibtexspace\bibxmlflush{volume}\bibtexspace in\bibtexspace } diff --git a/tex/context/base/cont-new.tex b/tex/context/base/cont-new.tex index 8b86a64bf..8ef09e1a0 100644 --- a/tex/context/base/cont-new.tex +++ b/tex/context/base/cont-new.tex @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2010.05.19 16:24} +\newcontextversion{2010.05.20 20:00} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 861b329d8..ce3d7c684 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -117,6 +117,7 @@ \loadmarkfile{lang-ini} \loadmarkfile{lang-lab} +\loadmarkfile{lang-wrd} \loadmarkfile{unic-ini} diff --git a/tex/context/base/context.tex b/tex/context/base/context.tex index 6b3441616..ec96c88cb 100644 --- a/tex/context/base/context.tex +++ b/tex/context/base/context.tex @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2010.05.19 16:24} +\edef\contextversion{2010.05.20 20:00} %D For those who want to use this: diff --git a/tex/context/base/l-table.lua b/tex/context/base/l-table.lua index 97929c973..ee395d0f1 100644 --- a/tex/context/base/l-table.lua +++ b/tex/context/base/l-table.lua @@ -12,7 +12,55 @@ local concat, sort, insert, remove = table.concat, table.sort, table.insert, tab local format, find, gsub, lower, dump, match = string.format, string.find, string.gsub, string.lower, string.dump, string.match local getmetatable, setmetatable = getmetatable, setmetatable local type, next, tostring, tonumber, ipairs = type, next, tostring, tonumber, ipairs -local unpack = unpack or table.unpack + +-- Starting with version 5.2 Lua no longer provide ipairs, which makes +-- sense. As we already used the for loop and # in most places the +-- impact on ConTeXt was not that large; the remaining ipairs already +-- have been replaced. In a similar fashio we also hardly used pairs. +-- +-- Just in case, we provide the fallbacks as discussed in Programming +-- in Lua (http://www.lua.org/pil/7.3.html): + +if not ipairs then + + -- for k, v in ipairs(t) do ... end + -- for k=1,#t do local v = t[k] ... end + + local function iterate(a,i) + i = i + 1 + local v = a[i] + if v ~= nil then + return i, v --, nil + end + end + + function ipairs(a) + return iterate, a, 0 + end + +end + +if not pairs then + + -- for k, v in pairs(t) do ... end + -- for k, v in next, t do ... end + + function pairs(t) + return next, t -- , nil + end + +end + +-- Also, unpack has been moved to the table table, and for compatiility +-- reasons we provide both now. + +if not table.unpack then + table.unpack = _G.unpack +elseif not unpack then + _G.unpack = table.unpack +end + +-- extra functions, some might go (when not used) function table.strip(tab) local lst = { } @@ -199,7 +247,7 @@ end table.fastcopy = fastcopy table.copy = copy --- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) +-- roughly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) function table.sub(t,i,j) return { unpack(t,i,j) } @@ -222,7 +270,7 @@ function table.one_entry(t) -- obolete, use inline code instead return n and not next(t,n) end ---~ function table.starts_at(t) -- obsolete, not nice +--~ function table.starts_at(t) -- obsolete, not nice anyway --~ return ipairs(t,1)(t,0) --~ end @@ -859,3 +907,4 @@ function table.insert_after_value(t,value,extra) end insert(t,#t+1,extra) end + diff --git a/tex/context/base/lang-sla.tex b/tex/context/base/lang-sla.tex index dbed4e10a..2c645af5a 100644 --- a/tex/context/base/lang-sla.tex +++ b/tex/context/base/lang-sla.tex @@ -82,7 +82,7 @@ \installlanguage [\s!cs] - [\c!spacing=\v!packed, + [\c!spacing=\v!packed, \c!leftsentence=\thickglue--\thickglue\penalty-20\relax, % hh, \relax added \c!rightsentence=\thickglue--\thickglue\penalty-20\relax, \c!leftsubsentence=~---~\penalty-20\relax, @@ -193,19 +193,19 @@ \setupheadtext [\s!sl] [\v!content=Kazalo] \setupheadtext [\s!pl] [\v!tables=Tabele] -\setupheadtext [\s!cs] [\v!tables=Tabulek] +\setupheadtext [\s!cs] [\v!tables=Tabulky] \setupheadtext [\s!sk] [\v!tables=Tabuliek] \setupheadtext [\s!hr] [\v!tables=Tablice] \setupheadtext [\s!sl] [\v!tables=Tabele] \setupheadtext [\s!pl] [\v!figures=Ilustracje] -\setupheadtext [\s!cs] [\v!figures=Obr\aacute zk\uring] +\setupheadtext [\s!cs] [\v!figures=Obr\aacute zky] \setupheadtext [\s!sk] [\v!figures=Obr\aacute zkov] \setupheadtext [\s!hr] [\v!figures=Slike] \setupheadtext [\s!sl] [\v!figures=Slike] \setupheadtext [\s!pl] [\v!graphics=Grafika] -\setupheadtext [\s!cs] [\v!graphics=Graf] +\setupheadtext [\s!cs] [\v!graphics=Grafy] \setupheadtext [\s!sk] [\v!graphics=Graf] \setupheadtext [\s!hr] [\v!graphics=Slike] \setupheadtext [\s!sl] [\v!graphics=Slike] @@ -241,7 +241,7 @@ \setupheadtext [\s!sl] [\v!units=Enote] %setupheadtext [\s!pl] [pubs=?] -%setupheadtext [\s!cs] [pubs=?] +\setupheadtext [\s!cs] [pubs=Literatura] %setupheadtext [\s!sk] [pubs=?] %setupheadtext [\s!hr] [pubs=?] \setupheadtext [\s!sl] [pubs=Literatura] diff --git a/tex/context/base/lang-wrd.lua b/tex/context/base/lang-wrd.lua index 1452d5279..095e44443 100644 --- a/tex/context/base/lang-wrd.lua +++ b/tex/context/base/lang-wrd.lua @@ -10,12 +10,26 @@ local utf = unicode.utf8 local lower, utfchar = string.lower, utf.char local lpegmatch = lpeg.match -languages.words = languages.words or {} -languages.words.data = languages.words.data or {} -languages.words.enables = false -languages.words.threshold = 4 +languages.words = languages.words or { } -languages.words.colors = { +local words = languages.words + +words.data = words.data or { } +words.enables = false +words.threshold = 4 + +local set_attribute = node.set_attribute +local unset_attribute = node.unset_attribute +local traverse_nodes = node.traverse +local node_id = node.id +local wordsdata = words.data +local chardata = characters.data + +local glyph_node = node_id('glyph') +local disc_node = node_id('disc') +local kern_node = node_id('kern') + +words.colors = { ["known"] = "green", ["unknown"] = "red", } @@ -27,23 +41,30 @@ local rbrace = lpeg.P("}") local disc = (lbrace * (1-rbrace)^0 * rbrace)^1 -- or just 3 times, time this local word = lpeg.Cs((markup/"" + disc/"" + (1-spacing))^1) -function languages.words.load(tag, filename) - local filename = resolvers.find_file(filename,'other text file') or "" - if filename ~= "" then +local loaded = { } -- we share lists + +function words.load(tag,filename) + local fullname = resolvers.find_file(filename,'other text file') or "" + if fullname ~= "" then statistics.starttiming(languages) - local data = io.loaddata(filename) or "" - local words = languages.words.data[tag] or {} - parser = (spacing + word/function(s) words[s] = true end)^0 - lpegmatch(parser,data) - languages.words.data[tag] = words + local list = loaded[fullname] + if not list then + list = wordsdata[tag] or { } + local parser = (spacing + word/function(s) list[s] = true end)^0 + lpegmatch(parser,io.loaddata(fullname) or "") + loaded[fullname] = list + end + wordsdata[tag] = list statistics.stoptiming(languages) + else + logs.report("languages","missing words file '%s'",filename) end end -function languages.words.found(id, str) - local tag = numbers[id] +function words.found(id, str) + local tag = languages.numbers[id] if tag then - local data = languages.words.data[tag] + local data = wordsdata[tag] return data and (data[str] or data[lower(str)]) else return false @@ -53,16 +74,11 @@ end -- The following code is an adaption of experimental code for -- hyphenating and spell checking. -local glyph, disc, kern = node.id('glyph'), node.id('disc'), node.id('kern') - -local bynode = node.traverse -local chardata = characters.data - -local function mark_words(head,found) -- can be optimized +local function mark_words(head,whenfound) -- can be optimized local current, start, str, language, n = head, nil, "", nil, 0 local function action() if #str > 0 then - local f = found(language,str) + local f = whenfound(language,str) if f then for i=1,n do f(start) @@ -74,7 +90,7 @@ local function mark_words(head,found) -- can be optimized end while current do local id = current.id - if id == glyph then + if id == glyph_node then local a = current.lang if a then if a ~= language then @@ -91,7 +107,7 @@ local function mark_words(head,found) -- can be optimized if components then start = start or current n = n + 1 - for g in bynode(components) do + for g in traverse_nodes(components) do str = str .. utfchar(g.char) end else @@ -104,10 +120,11 @@ local function mark_words(head,found) -- can be optimized action() end end - elseif id == disc then - if n > 0 then n = n + 1 end - -- ok - elseif id == kern and current.subtype == 0 and start then + elseif id == disc_node then + if n > 0 then + n = n + 1 + end + elseif id == kern_node and current.subtype == 0 and start then -- ok elseif start then action() @@ -120,23 +137,21 @@ local function mark_words(head,found) -- can be optimized return head end -languages.words.methods = { } -languages.words.method = 1 +words.methods = { } +words.method = 1 -local lw = languages.words +local methods = words.methods -languages.words.methods[1] = function(head, attribute, yes, nop) - local set = node.set_attribute - local unset = node.unset_attribute +methods[1] = function(head, attribute, yes, nop) local right, wrong = false, false - if yes then right = function(n) set(n,attribute,yes) end end - if nop then wrong = function(n) set(n,attribute,nop) end end - for n in node.traverse(head) do - unset(n,attribute) -- hm + if yes then right = function(n) set_attribute(n,attribute,yes) end end + if nop then wrong = function(n) set_attribute(n,attribute,nop) end end + for n in traverse_nodes(head) do + unset_attribute(n,attribute) -- hm, not that selective (reset color) end - local found, done = languages.words.found, false + local found, done = words.found, false mark_words(head, function(language,str) - if #str < lw.threshold then + if #str < words.threshold then return false elseif found(language,str) then done = true @@ -149,25 +164,50 @@ languages.words.methods[1] = function(head, attribute, yes, nop) return head, done end +local list, dump = { }, false -- todo: per language + +local lower = characters.lower + +methods[2] = function(head, attribute) + dump = true + mark_words(head, function(language,str) + if #str >= words.threshold then + str = lower(str) + list[str] = (list[str] or 0) + 1 + end + end) + return head, true +end + +words.used = list + +function words.dump_used_words(name) + if dump then + logs.report("languages","saving list of used words in '%s'",name) + io.savedata(name,table.serialize(list)) + end +end + local color = attributes.private('color') -function languages.words.check(head) - if lw.enabled and head.next then - local colors = lw.colors +function words.check(head) + if words.enabled and head.next then + local colors = words.colors local alc = attributes.list[color] - return lw.methods[lw.method](head, color, alc[colors.known], alc[colors.unknown]) + return methods[words.method](head, color, alc[colors.known], alc[colors.unknown]) else return head, false end end -function languages.words.enable() +function words.enable(method) tasks.enableaction("processors","languages.words.check") - languages.words.enabled = true + words.method = method or words.method or 1 + words.enabled = true end -function languages.words.disable() - languages.words.enabled = false +function words.disable() + words.enabled = false end -- for the moment we hook it into the attribute handler diff --git a/tex/context/base/lang-wrd.mkiv b/tex/context/base/lang-wrd.mkiv index e517ab5ae..774c2d335 100644 --- a/tex/context/base/lang-wrd.mkiv +++ b/tex/context/base/lang-wrd.mkiv @@ -19,12 +19,14 @@ \unprotect -% mkiv only -- todo: internationalize command names - % \loadspellchecklist[en][words-en.txt] % \loadspellchecklist[us][words-en.txt] % \loadspellchecklist[nl][words-nl.txt] -% \setupspellchecking[state=start] +% \setupspellchecking[state=start,method=1] +% +% \setupspellchecking[state=start,method=2] +% ... +% \typefile{\jobname.words} \def\loadspellchecklist {\dodoubleempty\doloadspellchecklist} @@ -38,10 +40,15 @@ \def\setupspellchecking[#1]% todo colors {\getparameters[\??wl][#1]% \doifelse\@@wlstate\v!start - {\ctxlua{languages.words.enable()}} + {\ctxlua{languages.words.enable(\@@wlmethod)}} {\ctxlua{languages.words.disable()}}} \setupspellchecking - [\c!state=\v!stop] + [\c!state=\v!stop, + \c!method=1] + +\appendtoks + \ctxlua{languages.words.dump_used_words("\jobname.words")}% +\to \everybye \protect \endinput diff --git a/tex/context/base/lxml-sor.lua b/tex/context/base/lxml-sor.lua index 7aebef79d..e220bfad6 100644 --- a/tex/context/base/lxml-sor.lua +++ b/tex/context/base/lxml-sor.lua @@ -91,9 +91,7 @@ function lxml.sorters.show(name) end end -function lxml.sorters.compare(a,b) - return sorters.comparers.basic(a.split,b.split) -end +lxml.sorters.compare = sorters.comparers.basic -- (a,b) function lxml.sorters.sort(name) local list = lists[name] @@ -112,6 +110,7 @@ function lxml.sorters.sort(name) -- preparation local strip = sorters.strip local splitter = sorters.splitters.utf + local firstofsplit = sorters.firstofsplit for i=1, #results do local r = results[i] r.split = splitter(strip(r.key)) @@ -123,7 +122,7 @@ function lxml.sorters.sort(name) local split = { } for k=1,#results do -- rather generic so maybe we need a function local v = results[k] - local entry, tag = sorters.firstofsplit(v.split) + local entry, tag = firstofsplit(v) local s = split[entry] -- keeps track of change if not s then s = { tag = tag, data = { } } @@ -140,19 +139,19 @@ end function lxml.sorters.flush(name,setup) local list = lists[name] local results = list and list.results + local xmlw = context.xmlw if results and next(results) then for key, result in next, results do local tag, data = result.tag, result.data for d=1,#data do - local dr = data[d] - texsprint(ctxcatcodes,"\\xmlw{",setup,"}{",dr.entry,"}") + xmlw(setup,data[d].entry) end end else local entries = list and list.entries if entries then for i=1,#entries do - texsprint(ctxcatcodes,"\\xmlw{",setup,"}{",entries[i][1],"}") + xmlw(setup,entries[i][1]) end end end diff --git a/tex/context/base/lxml-xml.lua b/tex/context/base/lxml-xml.lua index bde11cd53..f791ec0f8 100644 --- a/tex/context/base/lxml-xml.lua +++ b/tex/context/base/lxml-xml.lua @@ -34,8 +34,10 @@ local function reverse(collected) end local function attribute(collected,name) - local at = collected and collected[1].at - return at and at[name] + if collected and #collected > 0 then + local at = collected[1].at + return at and at[name] + end end local function att(id,name) diff --git a/tex/context/base/node-tsk.lua b/tex/context/base/node-tsk.lua index 84001f5bc..206b4a266 100644 --- a/tex/context/base/node-tsk.lua +++ b/tex/context/base/node-tsk.lua @@ -241,6 +241,7 @@ function tasks.table(name) --maybe move this to task-deb.lua end end end + tasks.new ( "processors", { diff --git a/tex/context/base/sort-ini.lua b/tex/context/base/sort-ini.lua index 0aa997632..a2d65f28d 100644 --- a/tex/context/base/sort-ini.lua +++ b/tex/context/base/sort-ini.lua @@ -6,12 +6,10 @@ if not modules then modules = { } end modules ['sort-ini'] = { license = "see context related readme files" } --- todo: --- --- out of range --- uppercase --- texutil compatible --- always expand to utf +-- It took a while to get there, but with Fleetwood Mac's "Don't Stop" +-- playing in the background we sort of got it done. + +-- todo: cleanup splits (in other modules) local utf = unicode.utf8 local gsub, rep, sort, concat = string.gsub, string.rep, table.sort, table.concat @@ -27,34 +25,38 @@ sorters.splitters = { } sorters.entries = { } sorters.mappings = { } sorters.replacements = { } -sorters.language = 'en' local mappings = sorters.mappings local entries = sorters.entries local replacements = sorters.replacements -function sorters.comparers.basic(sort_a,sort_b,map) - -- sm assignment is slow, will become sorters.initialize - local sm = map or mappings[sorters.language or sorters.defaultlanguage] or mappings.en +local language, defaultlanguage, dummy = 'en', 'en', { } + +local currentreplacements, currentmappings, currententries + +function sorters.setlanguage(lang) + language = lang or language or defaultlanguage + currentreplacements = replacements[language] or replacements[defaultlanguage] or dummy + currentmappings = mappings [language] or mappings [defaultlanguage] or dummy + currententries = entries [language] or entries [defaultlanguage] or dummy + return currentreplacements, currentmappings, currententries +end + +sorters.setlanguage() + +-- maybe inline code if it's too slow + +local function basicsort(sort_a,sort_b) if #sort_a > #sort_b then if #sort_b == 0 then return 1 else for i=1,#sort_b do local ai, bi = sort_a[i], sort_b[i] - local am, bm = sm[ai], sm[bi] - if am and bm then - if am > bm then - return 1 - elseif am < bm then - return -1 - end - else - if ai > bi then - return 1 - elseif ai < bi then - return -1 - end + if ai > bi then + return 1 + elseif ai < bi then + return -1 end end return 1 @@ -65,19 +67,10 @@ function sorters.comparers.basic(sort_a,sort_b,map) else for i=1,#sort_a do local ai, bi = sort_a[i], sort_b[i] - local am, bm = sm[ai], sm[bi] - if am and bm then - if am > bm then - return 1 - elseif am < bm then - return -1 - end - else - if ai > bi then - return 1 - elseif ai < bi then - return -1 - end + if ai > bi then + return 1 + elseif ai < bi then + return -1 end end return -1 @@ -87,25 +80,48 @@ function sorters.comparers.basic(sort_a,sort_b,map) else for i=1,#sort_a do local ai, bi = sort_a[i], sort_b[i] - local am, bm = sm[ai], sm[bi] - if am and bm then - if am > bm then - return 1 - elseif am < bm then - return -1 - end - else - if ai > bi then - return 1 - elseif ai < bi then - return -1 - end + if ai > bi then + return 1 + elseif ai < bi then + return -1 end end return 0 end end +function sorters.comparers.basic(a,b) + local ea, eb = a.split, b.split + local na, nb = #ea, #eb + if na == 0 and nb == 0 then + -- simple variant (single word) + local result = basicsort(ea.e,eb.e) + return result == 0 and result or basicsort(ea.m,eb.m) + else + -- complex variant, used in register (multiple words) + local result = 0 + for i=1,nb < na and nb or na do + local eai, ebi = ea[i], eb[i] + result = basicsort(eai.e,ebi.e) + if result == 0 then + result = basicsort(eai.m,ebi.m) + end + if result ~= 0 then + break + end + end + if result ~= 0 then + return result + elseif na > nb then + return 1 + elseif nb > na then + return -1 + else + return 0 + end + end +end + local function padd(s) return rep(" ",10-#s) .. s end -- or format with padd function sorters.strip(str) -- todo: only letters and such utf.gsub("([^%w%d])","") @@ -119,30 +135,38 @@ function sorters.strip(str) -- todo: only letters and such utf.gsub("([^%w%d])", end end -function sorters.firstofsplit(split) +local function firstofsplit(entry) -- numbers are left padded by spaces - local se = entries[sorters.language or sorters.defaultlanguage] or entries.en -- slow, will become sorters.initialize - local vs = split[1] - local entry = vs and vs[1] or "" - return entry, (se and se[entry]) or "\000" + local split = entry.split + if #split > 0 then + split = split[1].s + else + split = split.s + end + local entry = split and split[1] or "" + return entry, currententries[entry] or "\000" end -sorters.defaultlanguage = 'en' +sorters.firstofsplit = firstofsplit -- beware, numbers get spaces in front -function sorters.splitters.utf(str) -- brrr, todo: language - local r = sorters.replacements[sorters.language] or sorters.replacements[sorters.defaultlanguage] or { } - -- local m = mappings [sorters.language] or mappings [sorters.defaultlanguage] or { } - local u = characters.uncompose - local t = { } - for _,v in next, r do - str = gsub(str,v[1],v[2]) +function sorters.splitters.utf(str) + if #currentreplacements > 0 then + for k=1,#currentreplacements do + local v = currentreplacements[k] + str = gsub(str,v[1],v[2]) + end end - for c in utfcharacters(str) do -- maybe an lpeg - t[#t+1] = c + local s, m, e, n = { }, { }, { }, 0 + for sc in utfcharacters(str) do -- maybe an lpeg + n = n + 1 + local mc, ec = currentmappings[sc] or utfbyte(sc), currententries[sc] + s[n] = sc + m[n] = mc + e[n] = currentmappings[ec] or mc end - return t + return { s = s, m = m, e = e } end function table.remap(t) @@ -153,49 +177,51 @@ function table.remap(t) return tt end -function sorters.sort(entries,cmp) - local language = sorters.language or sorters.defaultlanguage - local map = mappings[language] or mappings.en - if trace_tests then - local function pack(l) - local t = { } - for i=1,#l do - local tt, li = { }, l[i] - for j=1,#li do - local lij = li[j] - if utfbyte(lij) > 0xFF00 then - tt[j] = "[]" - else - tt[j] = li[j] - end - end - t[i] = concat(tt) +local function pack(entry) + local t = { } + local split = entry.split + if #split > 0 then + for i=1,#split do + local tt, li = { }, split[i].s + for j=1,#li do + local lij = li[j] + tt[j] = utfbyte(lij) > 0xFF00 and "[]" or lij end - return concat(t," + ") + t[i] = concat(tt) end - sort(entries, function(a,b) - local r = cmp(a,b,map) - local as, bs = a.split, b.split - if as and bs then - logs.report("sorter","%s %s %s",pack(as),(not r and "?") or (r<0 and "<") or (r>0 and ">") or "=",pack(bs)) - end + return concat(t," + ") + else + local t, li = { }, split.s + for j=1,#li do + local lij = li[j] + t[j] = utfbyte(lij) > 0xFF00 and "[]" or lij + end + return concat(t) + end +end + +function sorters.sort(entries,cmp) + if trace_tests then + sort(entries,function(a,b) + local r = cmp(a,b) + logs.report("sorter","%s %s %s",pack(a),(not r and "?") or (r<0 and "<") or (r>0 and ">") or "=",pack(b)) return r == -1 end) local s for i=1,#entries do - local split = entries[i].split - local entry, first = sorters.firstofsplit(split) + local entry = entries[i] + local letter, first = firstofsplit(entry) if first == s then first = " " else s = first - logs.report("sorter",">> %s 0x%05X (%s 0x%05X)",first,utfbyte(first),entry,utfbyte(entry)) + logs.report("sorter",">> %s 0x%05X (%s 0x%05X)",first,utfbyte(first),letter,utfbyte(letter)) end - logs.report("sorter"," %s",pack(split)) + logs.report("sorter"," %s",pack(entry)) end else - sort(entries, function(a,b) - return cmp(a,b,map) == -1 + sort(entries,function(a,b) + return cmp(a,b) == -1 end) end end diff --git a/tex/context/base/sort-lan.lua b/tex/context/base/sort-lan.lua index e6466043a..56af2d16c 100644 --- a/tex/context/base/sort-lan.lua +++ b/tex/context/base/sort-lan.lua @@ -81,7 +81,7 @@ sorters.entries['cz'] = { ['c'] = "c", -- c [uc(0x010D)] = uc(0x010D), -- ccaron ['d'] = "d", -- d - [uc(0x010F)] = uc(0x010F), -- dcaron + [uc(0x010F)] = "d", -- dcaron ['e'] = "e", -- e [uc(0x00E9)] = "e", -- eacute [uc(0x011B)] = "e", -- ecaron @@ -96,16 +96,16 @@ sorters.entries['cz'] = { ['l'] = "l", -- l ['m'] = "m", -- m ['n'] = "n", -- n - [uc(0x0147)] = uc(0x0147), -- ncaron + ['ň'] = "n", -- ncaron ['o'] = "o", -- o ['p'] = "p", -- p ['q'] = "q", -- q ['r'] = "r", -- r - [uc(0x0147)] = uc(0x0147), -- rcaron + ['ř'] = "ř", -- rcaron ['s'] = "s", -- s [uc(0x0161)] = uc(0x0161), -- scaron ['t'] = "t", -- t - [uc(0x0165)] = uc(0x0165), -- tcaron + [uc(0x0165)] = "t", -- tcaron ['u'] = "u", -- u [uc(0x00FA)] = "u", -- uacute [uc(0x016F)] = "u", -- uring @@ -113,7 +113,7 @@ sorters.entries['cz'] = { ['w'] = "w", -- w ['x'] = "x", -- x ['y'] = "y", -- y - [uc(0x00FD)] = uc(0x00FD), -- yacute + [uc(0x00FD)] = "y", -- yacute ['z'] = "z", -- z [uc(0x017E)] = uc(0x017E), -- zcaron } @@ -140,12 +140,12 @@ sorters.mappings['cz'] = { ['l'] = 37, -- l ['m'] = 39, -- m ['n'] = 41, -- n - [uc(0x0147)] = 43, -- ncaron + ['ň'] = 43, -- ncaron ['o'] = 45, -- o ['p'] = 47, -- p ['q'] = 49, -- q ['r'] = 51, -- r - [uc(0x0147)] = 53, -- rcaron + ['ř'] = 53, -- rcaron ['s'] = 55, -- s [uc(0x0161)] = 57, -- scaron ['t'] = 59, -- t @@ -162,13 +162,13 @@ sorters.mappings['cz'] = { [uc(0x017E)] = 81, -- zcaron } +sorters.add_uppercase_entries (sorters.entries.cz) +sorters.add_uppercase_mappings(sorters.mappings.cz,0) -- 1 can be option (but then we need a runtime variant) + sorters.replacements['cs'] = sorters.replacements['cz'] sorters.entries ['cs'] = sorters.entries ['cz'] sorters.mappings ['cs'] = sorters.mappings ['cz'] -sorters.add_uppercase_entries (sorters.entries.cs) -sorters.add_uppercase_mappings(sorters.mappings.cs,1) - --~ print(table.serialize(sorters.mappings.cs)) -- French @@ -191,7 +191,7 @@ sorters.replacements['DIN 5007-2'] = { { "ü", 'ue' }, { "Ä", 'Ae' }, { "Ö", 'Oe' }, - { "Ü", 'Ue' } + { "Ü", 'Ue' }, } sorters.entries ['DIN 5007-2'] = sorters.entries ['en'] @@ -287,6 +287,32 @@ sorters.entries['fi'] = { ["Z"] = "z", ["Å"] = "å", ["Ä"] = "ä", ["Ö"] = "ö", } +-- slovenian +-- +-- MM: this will change since we need to add accented vowels + +sorters.entries['sl'] = { + ["a"] = "a", ["b"] = "b", ["c"] = "c", ["č"] = "č", ["ć"] = "ć", ["d"] = "d", + ["đ"] = "đ", ["e"] = "e", ["f"] = "f", ["g"] = "g", ["h"] = "h", ["i"] = "i", + ["j"] = "j", ["k"] = "k", ["l"] = "l", ["m"] = "m", ["n"] = "n", ["o"] = "o", + ["p"] = "p", ["q"] = "q", ["r"] = "r", ["s"] = "s", ["š"] = "š", ["t"] = "t", + ["u"] = "u", ["v"] = "v", ["w"] = "w", ["x"] = "x", ["y"] = "y", ["z"] = "z", + ["ž"] = "ž", +} + + +sorters.mappings['sl'] = { + ["a"] = 1, ["b"] = 3, ["c"] = 5, ["č"] = 7, ["ć"] = 9, ["d"] = 11, + ["đ"] = 13, ["e"] = 15, ["f"] = 17, ["g"] = 19, ["h"] = 21, ["i"] = 23, + ["j"] = 25, ["k"] = 27, ["l"] = 29, ["m"] = 31, ["n"] = 33, ["o"] = 35, + ["p"] = 37, ["q"] = 39, ["r"] = 41, ["s"] = 43, ["š"] = 45, ["t"] = 47, + ["u"] = 49, ["v"] = 51, ["w"] = 53, ["x"] = 55, ["y"] = 57, ["z"] = 59, + ["ž"] = 61, +} + +sorters.add_uppercase_entries (sorters.entries.sl) +sorters.add_uppercase_mappings(sorters.mappings.sl,0) -- cf. MM + --~ sorters.test = '' --~ sorters.test = 'nl' --~ sorters.test = 'cz' diff --git a/tex/context/base/sort-lan.mkii b/tex/context/base/sort-lan.mkii index 97df559bf..db52c63fb 100644 --- a/tex/context/base/sort-lan.mkii +++ b/tex/context/base/sort-lan.mkii @@ -156,45 +156,45 @@ \gdef\czsortdivisionCh{Ch} \startmode[sortorder-cz] - \exportsortexpansion {aacute} {a+1} - \exportsortexpansion {Aacute} {A+1} + \exportsortexpansion {aacute} {a} + \exportsortexpansion {Aacute} {A} \exportsortexpansion {ccaron} {c+1} \exportsortexpansion {Ccaron} {C+1} \exportsortdivision {c+1} {ccaron} - \exportsortexpansion {dcaron} {d+1} - \exportsortexpansion {Dcaron} {D+1} - \exportsortdivision {d+1} {dcaron} - \exportsortexpansion {eacute} {e+1} - \exportsortexpansion {Eacute} {E+1} - \exportsortexpansion {ecaron} {e+2} - \exportsortexpansion {Ecaron} {E+2} + \exportsortexpansion {dcaron} {d} + \exportsortexpansion {Dcaron} {D} + %\exportsortdivision {d+1} {dcaron} + \exportsortexpansion {eacute} {e} + \exportsortexpansion {Eacute} {E} + \exportsortexpansion {ecaron} {e} + \exportsortexpansion {Ecaron} {E} \exportsortreduction {ch} {h+1} \exportsortexpansion {ch} {h+1} \exportsortreduction {Ch} {H+1} \exportsortexpansion {Ch} {H+1} \exportsortdivision {h+1} {czsortdivisionch} - \exportsortexpansion {iacute} {i+1} - \exportsortexpansion {Iacute} {I+1} - \exportsortexpansion {ncaron} {n+1} - \exportsortexpansion {Ncaron} {N+1} - \exportsortdivision {n+1} {ncaron} - \exportsortexpansion {oacute} {o+1} - \exportsortexpansion {Oacute} {O+1} + \exportsortexpansion {iacute} {i} + \exportsortexpansion {Iacute} {I} + \exportsortexpansion {ncaron} {n} + \exportsortexpansion {Ncaron} {N} + %\exportsortdivision {n+1} {ncaron} + \exportsortexpansion {oacute} {o} + \exportsortexpansion {Oacute} {O} \exportsortexpansion {rcaron} {r+1} \exportsortexpansion {Rcaron} {R+1} \exportsortdivision {r+1} {rcaron} \exportsortexpansion {scaron} {s+1} \exportsortexpansion {Scaron} {S+1} \exportsortdivision {s+1} {scaron} - \exportsortexpansion {tcaron} {t+1} - \exportsortexpansion {Tcaron} {T+1} - \exportsortdivision {t+1} {tcaron} - \exportsortexpansion {uacute} {u+1} - \exportsortexpansion {Uacute} {U+1} - \exportsortexpansion {uring} {u+2} - \exportsortexpansion {Uring} {U+2} - \exportsortexpansion {yacute} {y+1} - \exportsortexpansion {Yacute} {Y+1} + \exportsortexpansion {tcaron} {t} + \exportsortexpansion {Tcaron} {T} + %\exportsortdivision {t+1} {tcaron} + \exportsortexpansion {uacute} {u} + \exportsortexpansion {Uacute} {U} + \exportsortexpansion {uring} {u} + \exportsortexpansion {Uring} {U} + \exportsortexpansion {yacute} {y} + \exportsortexpansion {Yacute} {Y} \exportsortexpansion {zcaron} {z+1} \exportsortexpansion {Zcaron} {Z+1} \exportsortdivision {z+1} {zcaron} diff --git a/tex/context/base/strc-reg.lua b/tex/context/base/strc-reg.lua index 0bdbcf2a8..519396276 100644 --- a/tex/context/base/strc-reg.lua +++ b/tex/context/base/strc-reg.lua @@ -24,6 +24,10 @@ local documents = structure.documents local pages = structure.pages local processors = structure.processors +local mappings = sorters.mappings +local entries = sorters.entries +local replacements = sorters.replacements + local processor_split = processors.split local matching_till_depth, number_at_depth = sections.matching_till_depth, sections.number_at_depth @@ -302,26 +306,12 @@ end -- sorting and rendering +local compare = sorters.comparers.basic + function jobregisters.compare(a,b) - local result = 0 - local compare = sorters.comparers.basic - local ea, eb = a.split, b.split - local na, nb = #ea, #eb - local max = na - if nb < max then max = nb end - for i=1,max do - if result == 0 then - result = compare(ea[i],eb[i]) - else - break - end - end + local result = compare(a,b) if result ~= 0 then return result - elseif na > nb then - return 1 - elseif nb > na then - return -1 elseif a.metadata.kind == 'entry' then -- e/f/t local page_a, page_b = a.references.realpage, b.references.realpage if not page_a or not page_b then @@ -331,9 +321,8 @@ function jobregisters.compare(a,b) elseif page_a > page_b then return 1 end - else - return 0 end + return 0 end function jobregisters.filter(data,options) @@ -405,7 +394,7 @@ function jobregisters.finalize(data,options) -- maps character to index (order) for k=1,#result do local v = result[k] - local entry, tag = sorters.firstofsplit(v.split) + local entry, tag = sorters.firstofsplit(v) if tag ~= lasttag then if trace_registers then logs.report("registers","splitting at %s",tag) @@ -424,7 +413,7 @@ function jobregisters.analysed(class,options) local data = collected[class] if data and data.entries then options = options or { } - sorters.language = options.language or sorters.defaultlanguage + sorters.setlanguage(options.language) jobregisters.filter(data,options) -- filter entries into results (criteria) jobregisters.prepare(data,options) -- adds split table parallel to list table jobregisters.sort(data,options) -- sorts results diff --git a/tex/context/base/strc-reg.mkiv b/tex/context/base/strc-reg.mkiv index 09c65b64b..0e690edcc 100644 --- a/tex/context/base/strc-reg.mkiv +++ b/tex/context/base/strc-reg.mkiv @@ -658,8 +658,7 @@ \def\withregisterpagecommand#1#2#3% {\def\currentregisterpageindex{#1}% \iflocation - % \goto{\registerparameter\c!pagecommand{#3}}[internal(#1)]% - \goto{\registerparameter\c!pagecommand{#3}}[page(#3)]% + \goto{\registerparameter\c!pagecommand{#3}}[internal(#1)]% \else \registerparameter\c!pagecommand{#3}% \fi} diff --git a/tex/context/base/strc-syn.lua b/tex/context/base/strc-syn.lua index 9c5a9392c..d6f38c2c7 100644 --- a/tex/context/base/strc-syn.lua +++ b/tex/context/base/strc-syn.lua @@ -92,9 +92,7 @@ function joblists.meaning(class,tag) end end -function joblists.compare(a,b) - return sorters.comparers.basic(a.split,b.split) -end +joblists.compare = sorters.comparers.basic -- (a,b) function joblists.filter(data,options) local result = { } @@ -136,7 +134,7 @@ function joblists.finalize(data,options) local split = { } for k=1,#result do local v = result[k] - local entry, tag = sorters.firstofsplit(v.split) + local entry, tag = sorters.firstofsplit(v) local s = split[entry] -- keeps track of change if not s then s = { tag = tag, data = { } } @@ -172,6 +170,8 @@ end function joblists.analysed(class,options) local data = joblists.collected[class] if data and data.entries then + options = options or { } + sorters.setlanguage(options.language) joblists.filter(data,options) -- filters entries to result joblists.prepare(data,options) -- adds split table parallel to list table joblists.sort(data,options) -- sorts entries in result diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index 655f83fe8..8891356ed 100644 --- a/tex/generic/context/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 05/19/10 16:24:38 +-- merge date : 05/20/10 20:00:41 do -- begin closure to overcome local limits and interference @@ -587,7 +587,55 @@ local concat, sort, insert, remove = table.concat, table.sort, table.insert, tab local format, find, gsub, lower, dump, match = string.format, string.find, string.gsub, string.lower, string.dump, string.match local getmetatable, setmetatable = getmetatable, setmetatable local type, next, tostring, tonumber, ipairs = type, next, tostring, tonumber, ipairs -local unpack = unpack or table.unpack + +-- Starting with version 5.2 Lua no longer provide ipairs, which makes +-- sense. As we already used the for loop and # in most places the +-- impact on ConTeXt was not that large; the remaining ipairs already +-- have been replaced. In a similar fashio we also hardly used pairs. +-- +-- Just in case, we provide the fallbacks as discussed in Programming +-- in Lua (http://www.lua.org/pil/7.3.html): + +if not ipairs then + + -- for k, v in ipairs(t) do ... end + -- for k=1,#t do local v = t[k] ... end + + local function iterate(a,i) + i = i + 1 + local v = a[i] + if v ~= nil then + return i, v --, nil + end + end + + function ipairs(a) + return iterate, a, 0 + end + +end + +if not pairs then + + -- for k, v in pairs(t) do ... end + -- for k, v in next, t do ... end + + function pairs(t) + return next, t -- , nil + end + +end + +-- Also, unpack has been moved to the table table, and for compatiility +-- reasons we provide both now. + +if not table.unpack then + table.unpack = _G.unpack +elseif not unpack then + _G.unpack = table.unpack +end + +-- extra functions, some might go (when not used) function table.strip(tab) local lst = { } @@ -774,7 +822,7 @@ end table.fastcopy = fastcopy table.copy = copy --- rougly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) +-- roughly: copy-loop : unpack : sub == 0.9 : 0.4 : 0.45 (so in critical apps, use unpack) function table.sub(t,i,j) return { unpack(t,i,j) } @@ -797,7 +845,7 @@ function table.one_entry(t) -- obolete, use inline code instead return n and not next(t,n) end ---~ function table.starts_at(t) -- obsolete, not nice +--~ function table.starts_at(t) -- obsolete, not nice anyway --~ return ipairs(t,1)(t,0) --~ end @@ -1435,6 +1483,7 @@ function table.insert_after_value(t,value,extra) insert(t,#t+1,extra) end + end -- closure do -- begin closure to overcome local limits and interference -- cgit v1.2.3