1

Compare commits

..

2 Commits

Author SHA1 Message Date
5de6deae99 Better wrapping on comma 2024-05-04 10:27:52 -07:00
50216e52a9 Keep track of parameter start and endpoints 2024-05-04 10:19:59 -07:00

View File

@ -234,6 +234,9 @@ function Param.new(pair, opt)
text = '',
literals = {},
offset = nil,
start = nil,
stop = nil,
terminator = nil,
}
return setmetatable(param, Param)
@ -248,6 +251,19 @@ function Param:append(char, cursor)
if cursor == Cursor.get_current() then
self.offset = #self.text
end
if not self.start then
self.start = cursor
end
self.stop = cursor
end
function Param:terminate(cursor)
self.terminator = cursor
if self.terminator == Cursor.get_current() then
self.offset = #self.text
end
end
function Param:is_active()
@ -280,7 +296,7 @@ function Param:trim()
self:slice(1, #self.text - #self.text:match('%s*$'))
self:slice(1 + #self.text:match('^%s*'), #self.text)
if #self.opt.line_prefix > 0 and self.text:match('^' .. self.opt.line_prefix) then
if self.text:match('^' .. self.opt.line_prefix) then
self:slice(1 + #self.opt.line_prefix, #self.text)
end
@ -290,7 +306,7 @@ function Param:trim()
local offset = self.offset
for i = 1, #self.text do
local char = self.text:sub(i, i)
local char = self.text:sub(i, i)
local literal = self.literals[i]
if literal or not char:match('%s') or not text:match('%s$') then
@ -326,11 +342,16 @@ function ParamList.new(range, opt)
return setmetatable(params, ParamList)
end
function ParamList:flush()
function ParamList:flush(cursor)
if self.current then
if cursor then
self.current:terminate(cursor)
end
if self.current:trim() then
table.insert(self.parsed, self.current)
end
self.current = nil
end
end
@ -339,7 +360,7 @@ function ParamList:update(char, brace_stack, cursor)
if not cursor:is_literal() then
brace_stack:update(char)
if brace_stack:empty() and char == ',' then
self:flush()
self:flush(cursor)
return
end
end