Skip to content

Commit

Permalink
fix(packages): BibTeX types/tags are case-insensitive, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored and Didier Willis committed Jul 14, 2022
1 parent 2c4d3d5 commit de7d5ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
13 changes: 7 additions & 6 deletions packages/bibtex/bibliography.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
23 changes: 17 additions & 6 deletions packages/bibtex/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit de7d5ec

Please sign in to comment.