diff --git a/lua/vimtex/bibparser.lua b/lua/vimtex/bibparser.lua index ffb552e354..abf05b72b8 100644 --- a/lua/vimtex/bibparser.lua +++ b/lua/vimtex/bibparser.lua @@ -10,12 +10,12 @@ ---@return table current Current entry with updated body local function parse_tail(current, line) current.level = current.level - + vim.fn.count(line, "{") - - vim.fn.count(line, "}") + + line:gsub("[^{]", ""):len() + - line:gsub("[^}]", ""):len() if current.level > 0 then current.body = current.body .. line else - current.body = current.body .. vim.fn.matchstr(line, [[.*\ze}]]) + current.body = current.body .. line:match(".*}()") current.parsed = true end @@ -29,7 +29,7 @@ end ---@return table current Current entry with updated body local function parse_head(file, lnum, line) local matches = vim.fn.matchlist(line, [[\v^\@(\w+)\s*\{\s*(.*)]]) - if vim.tbl_isempty(matches) then + if #matches == 0 then return {} end @@ -93,7 +93,8 @@ local function get_tag_value(body, head, strings) -- First check if the value is simply a number if vim.regex([[\d]]):match_str(body:sub(head + 1, head + 1)) then local value = vim.fn.matchstr(body, [[^\d\+]], head) - local new_head = vim.fn.matchend(body, [[^\s*,\s*]], head + vim.fn.len(value)) + local new_head = + vim.fn.matchend(body, [[^\s*,\s*]], head + vim.fn.len(value)) return value, new_head end @@ -131,7 +132,7 @@ end ---@return integer head New head position local function get_tag_name(body, head) local matches = vim.fn.matchlist(body, [[^\v([-_:0-9a-zA-Z]+)\s*\=\s*]], head) - if vim.tbl_isempty(matches) then + if #matches == 0 then return "", -1 end @@ -146,21 +147,22 @@ local function parse_item(item, strings) local parts = vim.fn.matchlist(item.body, [[\v^([^, ]*)\s*,\s*(.*)]]) item.level = nil + item.parsed = nil item.body = nil item.key = parts[2] local body = parts[3] - if vim.fn.empty(body) == 1 then + if body == nil or body == "" then return nil end local tag = "" + local value local head = 0 while head >= 0 do - if vim.fn.empty(tag) == 1 then + if tag == "" then tag, head = get_tag_name(body, head) else - local value value, head = get_tag_value(body, head, strings) item[tag] = value tag = "" @@ -175,7 +177,8 @@ end ---@return string? key ---@return string? value local function parse_string(raw_string) - local matches = vim.fn.matchlist(raw_string, [[\v^\s*(\S+)\s*\=\s*"(.*)"\s*$]]) + local matches = + vim.fn.matchlist(raw_string, [[\v^\s*(\S+)\s*\=\s*"(.*)"\s*$]]) if vim.fn.empty(matches[3]) == 0 then return matches[2], matches[3] end