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 = '', text = '',
literals = {}, literals = {},
offset = nil, offset = nil,
start = nil,
stop = nil,
terminator = nil,
} }
return setmetatable(param, Param) return setmetatable(param, Param)
@ -248,6 +251,19 @@ function Param:append(char, cursor)
if cursor == Cursor.get_current() then if cursor == Cursor.get_current() then
self.offset = #self.text self.offset = #self.text
end 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 end
function Param:is_active() 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 - #self.text:match('%s*$'))
self:slice(1 + #self.text:match('^%s*'), #self.text) 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) self:slice(1 + #self.opt.line_prefix, #self.text)
end end
@ -326,11 +342,16 @@ function ParamList.new(range, opt)
return setmetatable(params, ParamList) return setmetatable(params, ParamList)
end end
function ParamList:flush() function ParamList:flush(cursor)
if self.current then if self.current then
if cursor then
self.current:terminate(cursor)
end
if self.current:trim() then if self.current:trim() then
table.insert(self.parsed, self.current) table.insert(self.parsed, self.current)
end end
self.current = nil self.current = nil
end end
end end
@ -339,7 +360,7 @@ function ParamList:update(char, brace_stack, cursor)
if not cursor:is_literal() then if not cursor:is_literal() then
brace_stack:update(char) brace_stack:update(char)
if brace_stack:empty() and char == ',' then if brace_stack:empty() and char == ',' then
self:flush() self:flush(cursor)
return return
end end
end end