1
This commit is contained in:
Alex Yatskov 2024-04-25 20:28:10 -07:00
parent ccc158103c
commit 72ac7e3dff

View File

@ -3,10 +3,11 @@
-- --
local Cursor = {} local Cursor = {}
Cursor.mt = {__index = Cursor}
function Cursor.new(row, col) function Cursor.new(row, col)
local cursor = {row = row, col = col} local cursor = {row = row, col = col}
return setmetatable(cursor, {__index = Cursor}) return setmetatable(cursor, Cursor.mt)
end end
function Cursor:is_valid() function Cursor:is_valid()
@ -30,15 +31,20 @@ function Cursor:set_current()
vim.fn.secursorcharpos({self.row, self.col}) vim.fn.secursorcharpos({self.row, self.col})
end end
function Cursor.mt.__eq(self, other)
return self.row == other.row and self.col == other.col
end
-- --
-- BracePair -- BracePair
-- --
local BracePair = {} local BracePair = {}
BracePair.mt = {__index = BracePair}
function BracePair.new(open, close) function BracePair.new(open, close)
local pair = {open = open, close = close} local pair = {open = open, close = close}
return setmetatable(pair, {__index = BracePair}) return setmetatable(pair, BracePair.mt)
end end
function BracePair.from_brace(brace) function BracePair.from_brace(brace)
@ -103,10 +109,11 @@ end
-- --
local BraceStack = {} local BraceStack = {}
BraceStack.mt = {__index = BraceStack}
function BraceStack.new() function BraceStack.new()
local stack = {stack = {}} local stack = {stack = {}}
return setmetatable(stack, {__index = BraceStack}) return setmetatable(stack, BraceStack.mt)
end end
function BraceStack:update(brace) function BraceStack:update(brace)
@ -142,6 +149,7 @@ end
-- --
local BraceRange = {} local BraceRange = {}
BraceRange.mt = {__index = BraceRange}
function BraceRange.new(start, stop, pair) function BraceRange.new(start, stop, pair)
local range = { local range = {
@ -150,7 +158,7 @@ function BraceRange.new(start, stop, pair)
pair = pair, pair = pair,
} }
return setmetatable(range, {__index = BraceRange}) return setmetatable(range, BraceRange.mt)
end end
function BraceRange.find_closest(pair) function BraceRange.find_closest(pair)
@ -158,7 +166,7 @@ function BraceRange.find_closest(pair)
if stop then if stop then
local start = pair:find_closest(true) local start = pair:find_closest(true)
if start then if start then
return BraceRange.new(start, stop, pair, {}) return BraceRange.new(start, stop, pair)
end end
end end
end end
@ -210,6 +218,7 @@ end
-- --
local Param = {} local Param = {}
Param.mt = {__index = Param}
function Param.new(text, pair) function Param.new(text, pair)
local param = { local param = {
@ -217,7 +226,7 @@ function Param.new(text, pair)
pair = pair, pair = pair,
} }
return setmetatable(param, {__index = Param}) return setmetatable(param, Param.mt)
end end
function Param:append(char) function Param:append(char)
@ -233,6 +242,7 @@ end
-- --
local ParamList = {} local ParamList = {}
ParamList.mt = {__index = ParamList}
function ParamList.new() function ParamList.new()
local params = { local params = {
@ -240,7 +250,7 @@ function ParamList.new()
parsed = {}, parsed = {},
} }
return setmetatable(params, {__index = ParamList}) return setmetatable(params, ParamList.mt)
end end
function ParamList:flush() function ParamList:flush()
@ -296,6 +306,7 @@ end
-- --
local WrapContext = {} local WrapContext = {}
WrapContext.mt = {__index = WrapContext}
function WrapContext.new(opt) function WrapContext.new(opt)
local wrap_context = { local wrap_context = {
@ -307,7 +318,7 @@ function WrapContext.new(opt)
params = nil, params = nil,
} }
return setmetatable(wrap_context, {__index = WrapContext}) return setmetatable(wrap_context, WrapContext.mt)
end end
function WrapContext:parse() function WrapContext:parse()