From de7d5ec89c8bf4634bb44a6a9e0d66f93b3139cf Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Thu, 14 Jul 2022 05:47:36 +0200 Subject: [PATCH] fix(packages): BibTeX types/tags are case-insensitive, etc --- packages/bibtex/bibliography.lua | 13 +++++++------ packages/bibtex/init.lua | 23 +++++++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/bibtex/bibliography.lua b/packages/bibtex/bibliography.lua index 06f3b8d62b..3d46e06e21 100644 --- a/packages/bibtex/bibliography.lua +++ b/packages/bibtex/bibliography.lua @@ -319,11 +319,12 @@ Bibliography = { Errors = { UNKNOWN_REFERENCE = 1, + UNKNOWN_TYPE = 2, }, Style = { andAuthors = function(item) - local authors = namesplit(item.Author) + local authors = namesplit(item.author) if #authors == 1 then return parse_name(authors[1]).ll else @@ -337,7 +338,7 @@ Bibliography = { andSurnames = function (max) return function(item) - local authors = namesplit(item.Author) + local authors = namesplit(item.author) if #authors > max then return parse_name(authors[1]).ll .. SILE.fluent:get_message("bibliography-et-al") else @@ -349,11 +350,11 @@ Bibliography = { transEditor = function(item) local r = {} - if item.Editor then - r[#r+1] = SILE.fluent:get_message("bibliography-edited-by")({ name = item.Editor }) + if item.editor then + r[#r+1] = SILE.fluent:get_message("bibliography-edited-by")({ name = item.editor }) end - if item.Translator then - r[#r+1] = SILE.fluent:get_message("bibliography-translated-by")({ name = item.Translator }) + if item.translator then + r[#r+1] = SILE.fluent:get_message("bibliography-translated-by")({ name = item.translator }) end if #r then return table.concat(r, ", ") end return nil diff --git a/packages/bibtex/init.lua b/packages/bibtex/init.lua index f24952b42d..8c5f75ca44 100644 --- a/packages/bibtex/init.lua +++ b/packages/bibtex/init.lua @@ -13,16 +13,23 @@ local bibtexparser = epnf.define(function (_ENV) local _ = WS^0 local sep = lpeg.S(",;") * _ local myID = C(identifier + lpeg.P(1)) / function (t) return t end + local myTag = C(identifier + lpeg.P(1)) / function (t) return t:lower() end local value = balanced + doubleq + myID - local pair = lpeg.Cg(myID * _ * "=" * _ * C(value)) * _ * sep^-1 / function (...) local t= {...}; return t[1], t[#t] end + local pair = lpeg.Cg(myTag * _ * "=" * _ * C(value)) * _ * sep^-1 / function (...) local t= {...}; return t[1], t[#t] end local list = lpeg.Cf(lpeg.Ct("") * pair^0, rawset) + local commentKey = lpeg.Cmt(R("az", "AZ")^1, function(s, i, a, b) + if a:lower() == "comment" then + return true -- DIDIER I am not sure, shouldn't we return a position? + end + return nil + end) START "document" - document = (V"entry" + V"comment")^1 * (-1 + E("Unexpected character at end of input")) + document = (V"entry" + V"comment")^1 * (-1 + E("Unexpected character at end of input")) -- DIDIER should we give priority to comment? comment = WS + ( V"blockcomment" + (P("%") * (1-lpeg.S("\r\n"))^0 * lpeg.S("\r\n")) /function () return "" end) -- Don't bother telling me about comments - blockcomment = P("@comment")+ balanced/function () return "" end -- Don't bother telling me about comments - entry = Ct( P("@") * Cg(myID, "type") * _ * P("{") * _ * Cg(myID, "label") * _ * sep * list * P("}") * _ ) + blockcomment = P("@") + commentKey + balanced/function () return "" end -- Don't bother telling me about comments + entry = Ct( P("@") * Cg(myTag, "type") * _ * P("{") * _ * Cg(myID, "label") * _ * sep * list * P("}") * _ ) end) -- luacheck: pop @@ -76,7 +83,7 @@ local function registerCommands (_) local bibstyle = require("packages.bibtex.styles." .. style) local cite = Bibliography.produceCitation(options, SILE.scratch.bibtex.bib, bibstyle) if cite == Bibliography.Errors.UNKNOWN_REFERENCE then - SU.warn("Unknown reference in citation "..options) + SU.warn("Unknown reference in citation "..options.key) return end SILE.doTexlike(cite) @@ -88,7 +95,11 @@ local function registerCommands (_) local bibstyle = require("packages.bibtex.styles." .. style) local cite = Bibliography.produceReference(options, SILE.scratch.bibtex.bib, bibstyle) if cite == Bibliography.Errors.UNKNOWN_REFERENCE then - SU.warn("Unknown reference in citation "..options) + SU.warn("Unknown reference in citation "..options.key) + return + end + if cite == Bibliography.Errors.UNKNOWN_TYPE then + SU.warn("Unknown type for citation reference "..options.key) return end SILE.doTexlike(cite)