Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lervag committed Oct 24, 2023
1 parent 71fed6d commit 0c4875c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lua/vimtex/bibparser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

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

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

Expand All @@ -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 = ""
Expand All @@ -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
Expand Down

0 comments on commit 0c4875c

Please sign in to comment.