summaryrefslogtreecommitdiffstats
path: root/pairs.lua
diff options
context:
space:
mode:
authorGeorgi Kirilov <>2020-11-22 15:10:49 +0200
committerGeorgi Kirilov <>2023-10-04 18:24:58 +0800
commit994e892dfc3b9d500c6b436b624e629a920d7cbe (patch)
treec769abd2c6fb708a3356be5ef77bdb20f592a43f /pairs.lua
parentdd388021fea503b55b07651f83e56b7290525c80 (diff)
downloadvis-pairs-994e892dfc3b9d500c6b436b624e629a920d7cbe.tar.gz
Move LPeg-to-file offsets conversion outside nth()
Diffstat (limited to 'pairs.lua')
-rw-r--r--pairs.lua13
1 files changed, 10 insertions, 3 deletions
diff --git a/pairs.lua b/pairs.lua
index 3abb5a2..af1e2f4 100644
--- a/pairs.lua
+++ b/pairs.lua
@@ -60,8 +60,8 @@ local function nth(t)
if #t == 5 then
start, finish, c = nth(t[3])
end
- if c and c > 0 then
- return {t[1] - 1, t[2] - 1}, {t[#t - 1] - 1, t[#t] - 1}, c - 1
+ if c then
+ return {t[1], t[2]}, {t[#t - 1], t[#t]}, c > 1 and c - 1 or nil
end
return start, finish
end
@@ -81,7 +81,14 @@ local function get_range(key, file, pos)
end
local p = d[1] ~= d[2] and symmetric(d[1], d[2], at_pos) or asymmetric(d[1], at_pos)
local pattern = l.P{l.Cmt(p, any_captures) + 1 * l.V(1)}
- return nth(l.match(pattern, file:content(0, file.size)))
+ local offsets = {nth(l.match(pattern, file:content(0, file.size)))}
+ offsets[3] = nil
+ for _, o in ipairs(offsets) do
+ for i, v in ipairs(o) do
+ o[i] = v - 1
+ end
+ end
+ return unpack(offsets)
end
local function get_delimiters(key, pos)