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:59 +0800
commit08420f8a29c9d53494d1d70154e96cb732658ba7 (patch)
tree17eab67a1cb2d19a9abe9a81864d13c5d399ad16 /pairs.lua
parent753087473758fc64e936450215f073413be0b15b (diff)
downloadvis-pairs-08420f8a29c9d53494d1d70154e96cb732658ba7.tar.gz
Use lpeg.Cc() instead of lpeg.Carg()
`pos` doesn't change across lpeg.match() invocations.
Diffstat (limited to 'pairs.lua')
-rw-r--r--pairs.lua22
1 files changed, 11 insertions, 11 deletions
diff --git a/pairs.lua b/pairs.lua
index 7bca6ed..81dd847 100644
--- a/pairs.lua
+++ b/pairs.lua
@@ -38,7 +38,11 @@ local function get_pair(key)
or not key:match("%w") and {key, key}
end
-local function asymmetric(d, at_pos)
+local function at_pos(t, pos)
+ if pos >= t[1] and pos < t[#t] then return t end
+end
+
+local function asymmetric(d, pos)
local p
local I = l.Cp()
if #d == 1 then
@@ -46,13 +50,13 @@ local function asymmetric(d, at_pos)
else
p = d * I * (l.P(1) - d)^0 * I * d
end
- return l.Ct(I * p * I) * l.Carg(1) / at_pos
+ return l.Ct(I * p * I) * l.Cc(pos) / at_pos
end
-local function symmetric(d1, d2, escaped, at_pos)
+local function symmetric(d1, d2, escaped, pos)
local I = l.Cp()
local skip = escaped and escaped + l.P(1) or l.P(1)
- return l.P{l.Ct(I * d1 * I * ((skip - d1 - d2) + l.V(1))^0 * I * d2 * I) * l.Carg(1) / at_pos}
+ return l.P{l.Ct(I * d1 * I * ((skip - d1 - d2) + l.V(1))^0 * I * d2 * I) * l.Cc(pos) / at_pos}
end
local function nth(t)
@@ -117,10 +121,6 @@ local function escaping_context(file, range, syntax)
end
end
-local function at_pos(t, pos)
- if pos >= t[1] and pos < t[#t] then return t end
-end
-
local function past(_, position, pos)
return position > pos
end
@@ -139,14 +139,14 @@ local function get_range(key, file, pos)
pos = pos - range.start
end
correction = range.start
- local p = d[1] ~= d[2] and symmetric(d[1], d[2], c.escape, at_pos) or asymmetric(d[1], at_pos)
+ local p = d[1] ~= d[2] and symmetric(d[1], d[2], c.escape, pos + 1) or asymmetric(d[1], pos + 1)
local skip = c.escape and c.escape + 1 or 1
local data = file:content(range)
- local pattern = l.P{p + skip * (l.V(1) - l.Cmt(l.Carg(1), past))}
+ local pattern = l.P{p + skip * (l.V(1) - l.Cmt(l.Cc(pos + 1), past))}
local result
local start = 1
repeat
- result = pattern:match(data, start, pos + 1)
+ result = pattern:match(data, start)
if not result then break end
start = result
until type(result) == "table"