From 2e0731c0e1b16577a3cc394aad3e0734560d60c6 Mon Sep 17 00:00:00 2001 From: Context Git Mirror Bot Date: Wed, 31 Dec 2014 21:15:05 +0100 Subject: 2014-12-31 20:44:00 --- tex/context/base/cont-new.mkiv | 2 +- tex/context/base/context-version.pdf | Bin 4385 -> 4385 bytes tex/context/base/context.mkiv | 2 +- tex/context/base/publ-aut.lua | 201 +++++++++++++++++---- tex/context/base/publ-dat.lua | 17 ++ tex/context/base/publ-ini.lua | 43 ++++- tex/context/base/status-files.pdf | Bin 24873 -> 24868 bytes tex/context/base/status-lua.pdf | Bin 345975 -> 356725 bytes tex/generic/context/luatex/luatex-fonts-merged.lua | 2 +- 9 files changed, 228 insertions(+), 39 deletions(-) (limited to 'tex') diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index ed1b174c8..e642b5be1 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2014.12.31 16:52} +\newcontextversion{2014.12.31 20:42} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf index c9fef1602..5b1834d62 100644 Binary files a/tex/context/base/context-version.pdf and b/tex/context/base/context-version.pdf differ diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index f8c1bd0be..abac94514 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -28,7 +28,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2014.12.31 16:52} +\edef\contextversion{2014.12.31 20:42} \edef\contextkind {beta} %D For those who want to use this: diff --git a/tex/context/base/publ-aut.lua b/tex/context/base/publ-aut.lua index ea86e702a..01b41c167 100644 --- a/tex/context/base/publ-aut.lua +++ b/tex/context/base/publ-aut.lua @@ -458,14 +458,97 @@ end -- first : key author editor publisher title journal volume number pages -- second: year suffix title month day journal volume number -local function indexer(dataset,list,method) - local current = datasets[dataset] - local luadata = current.luadata - local details = current.details - local result = { } - local splitted = newsplitter(splitter) -- saves mem - local snippets = { } -- saves mem - local field = "author" -- todo +-- local function indexer(dataset,list,method) +-- local current = datasets[dataset] +-- local luadata = current.luadata +-- local details = current.details +-- local result = { } +-- local splitted = newsplitter(splitter) -- saves mem +-- local snippets = { } -- saves mem +-- local field = "author" -- todo +-- for i=1,#list do +-- -- either { tag, tag, ... } or { { tag, index }, { tag, index } } +-- local li = list[i] +-- local tag = type(li) == "string" and li or li[1] +-- local index = tostring(i) +-- local entry = luadata[tag] +-- if entry then +-- local value = getcasted(current,tag,field) or "" +-- local mainkey = writer(value,snippets) +-- local detail = details[tag] +-- result[i] = { +-- index = i, +-- split = { +-- splitted[entry.key or "" ], +-- splitted[strip(mainkey) ], +-- splitted[entry.year or "9998"], +-- splitted[detail.suffix or " " ], +-- splitted[entry.month or "13" ], +-- splitted[entry.day or "32" ], +-- splitted[strip(entry.journal or "" )], +-- splitted[strip(entry.volume or "" )], +-- splitted[strip(entry.number or "" )], +-- splitted[strip(entry.title or "" )], +-- splitted[entry.pages or "" ], +-- splitted[index], +-- }, +-- } +-- else +-- result[i] = { +-- index = i, +-- split = { +-- splitted[""], -- key +-- splitted[""], -- mainkey +-- splitted["9999"], -- year +-- splitted[" "], -- suffix +-- splitted["14"], -- month +-- splitted["33"], -- day +-- splitted[""], -- journal +-- splitted[""], -- volume +-- splitted[""], -- number +-- splitted[""], -- title +-- splitted[""], -- pages +-- splitted[index], -- index +-- }, +-- } +-- end +-- end +-- return result +-- end + +-- if needed we can optimize this one: chekc if it's detail or something else +-- and use direct access, but in practice it's fast enough + +local template = [[ +local type, tostring = type, tostring + +local writers = publications.writers +local datasets = publications.datasets +local getter = publications.getfaster -- (current,data,details,field,categories,types) +local strip = sorters.strip +local splitter = sorters.splitters.utf + +local function newsplitter(splitter) + return table.setmetatableindex({},function(t,k) -- could be done in the sorter but seldom that many shared + local v = splitter(k,true) -- in other cases + t[k] = v + return v + end) +end + +return function(dataset,list,method) -- indexer + local current = datasets[dataset] + local luadata = current.luadata + local details = current.details + local specification = publications.currentspecification + local categories = specification.categories + local types = specification.types + local splitted = newsplitter(splitter) -- saves mem + local snippets = { } -- saves mem + local result = { } + +%helpers% + for i=1,#list do -- either { tag, tag, ... } or { { tag, index }, { tag, index } } local li = list[i] @@ -473,23 +556,14 @@ local function indexer(dataset,list,method) local index = tostring(i) local entry = luadata[tag] if entry then - local value = getcasted(current,tag,field) or "" - local mainkey = writer(value,snippets) local detail = details[tag] result[i] = { index = i, split = { - splitted[entry.key or "" ], - splitted[strip(mainkey) ], - splitted[entry.year or "9998"], - splitted[detail.suffix or " " ], - splitted[entry.month or "13" ], - splitted[entry.day or "32" ], - splitted[strip(entry.journal or "" )], - splitted[strip(entry.volume or "" )], - splitted[strip(entry.number or "" )], - splitted[strip(entry.title or "" )], - splitted[entry.pages or "" ], + splitted[entry.key or ""], + +%getters% + splitted[index], }, } @@ -497,24 +571,85 @@ local function indexer(dataset,list,method) result[i] = { index = i, split = { - splitted[""], -- key - splitted[""], -- mainkey - splitted["9999"], -- year - splitted[" "], -- suffix - splitted["14"], -- month - splitted["33"], -- day - splitted[""], -- journal - splitted[""], -- volume - splitted[""], -- number - splitted[""], -- title - splitted[""], -- pages - splitted[index], -- index + splitted[""], + +%unknowns% + + splitted[index], }, } end end return result end +]] + +local f_getter = formatters["splitted[strip(getter(current,entry,detail,%q,categories,types) or %q)], -- %s"] +local f_writer = formatters["splitted[strip(writer_%s(getter(current,entry,detail,%q,categories,types) or %q,snippets))], -- %s"] +local f_helper = formatters["local writer_%s = writers[%q] -- %s: %s"] +local f_value = formatters["splitted[%q], -- %s"] + +local function indexer(dataset,list,method) + local writers = publications.writers + local specification = publications.currentspecification + ----- categories = specification.categories + local types = specification.types + + local getters = { } + local unknowns = { } + local helpers = { } + + local sequence = { + -- always key first (or should that be made explicit) + { field = "author", default = "", unknown = "" }, + { field = "year", default = "9998", unknown = "9999" }, + { field = "suffix", default = " ", unknown = " " }, + { field = "month", default = "13", unknown = "14" }, + { field = "day", default = "32", unknown = "33" }, + { field = "journal", default = "", unknown = "" }, + { field = "volume", default = "", unknown = "" }, + { field = "number", default = "", unknown = "" }, + { field = "title", default = "", unknown = "" }, + { field = "pages", default = "", unknown = "" }, + -- always index last (to catch duplicates) + } + + for i=1,#sequence do + local step = sequence[i] + local field = step.field or "?" + local default = step.default or "" + local unknown = step.unknown or "" + local fldtype = types[field] + local writer = fldtype and writers[fldtype] + if writer then + local h = #helpers + 1 + getters[i] = f_writer(h,field,default,field) + helpers[h] = f_helper(h,fldtype,field,fldtype) + else + getters[i] = f_getter(field,default,field) + end + unknowns[i] = f_value(unknown,field) + end + + local code = utilities.templates.replace(template, { + helpers = concat(helpers, "\n"), + getters = concat(getters, "\n"), + unknowns = concat(unknowns,"\n"), + }) + + -- print(code) + + local action, error = loadstring(code) + if type(action) == "function" then + action = action() + end + if type(action) == "function" then + return action(dataset,list,method) or { } + else + return { } + end + +end -- local function sorted(dataset,list) -- experimental -- local valid = indexer(dataset,list,sorttype) diff --git a/tex/context/base/publ-dat.lua b/tex/context/base/publ-dat.lua index f022f6ade..dcaabb015 100644 --- a/tex/context/base/publ-dat.lua +++ b/tex/context/base/publ-dat.lua @@ -1040,6 +1040,15 @@ do return lpegmatch(keywordsplitter,str) end + + writers.keyword = function(k) + if type(k) == "table" then + return concat(p,";") + else + return k + end + end + local pagessplitter = lpeg.splitat(P("-")^1) casters.pagenumber = function(str) @@ -1047,4 +1056,12 @@ do return first and last and { first, last } or str end + writers.pagenumber = function(p) + if type(p) == "table" then + return concat(p,"-") + else + return p + end + end + end diff --git a/tex/context/base/publ-ini.lua b/tex/context/base/publ-ini.lua index 43cc37fc2..120957034 100644 --- a/tex/context/base/publ-ini.lua +++ b/tex/context/base/publ-ini.lua @@ -174,15 +174,17 @@ function commands.registerbtxlistvariant(name,parent) registeredlistvariants[name] = parent or "" end -local specifications = publications.specifications -local currentspecification = specifications[false] -local ignoredfields = { } +local specifications = publications.specifications +local currentspecification = specifications[false] +local ignoredfields = { } +publications.currentspecification = currentspecification local function setspecification(name) currentspecification = specifications[name] if trace then report("setting specification %a",type(name) == "string" and name or "anything") end + publications.currentspecification = currentspecification end publications.setspecification = setspecification @@ -695,6 +697,40 @@ local function getcasted(dataset,tag,field,specification) end end +local function getfaster(current,data,details,field,categories,types) + local category = data.category + local catspec = categories[category] + if not catspec then + return false + end + local fields = catspec.fields + if fields then + local sets = catspec.sets + if sets then + local set = sets[field] + if set then + for i=1,#set do + local field = set[i] + local value = fields[field] and data[field] -- redundant check + if value then + local kind = types[field] + return detailed[kind][value], field, kind + end + end + end + end + local value = fields[field] and data[field] -- redundant check + if value then + local kind = types[field] + return detailed[kind][value] + end + end + if details then + local kind = types[field] + return details[field] + end +end + local function getdirect(dataset,data,field,catspec) -- no field check, no dataset check local catspec = (catspec or currentspecification).categories[data.category] if not catspec then @@ -720,6 +756,7 @@ local function getdirect(dataset,data,field,catspec) -- no field check, no datas end publications.getcasted = getcasted +publications.getfaster = getfaster publications.getdirect = getdirect function commands.btxsingularorplural(dataset,tag,name) diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf index 85959a730..6ded1f9a4 100644 Binary files a/tex/context/base/status-files.pdf and b/tex/context/base/status-files.pdf differ diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf index a62ccd5b5..bb67d0ed5 100644 Binary files a/tex/context/base/status-lua.pdf and b/tex/context/base/status-lua.pdf differ diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 6500989cc..3d5443875 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 12/31/14 16:52:11 +-- merge date : 12/31/14 20:42:33 do -- begin closure to overcome local limits and interference -- cgit v1.2.3