Skip to content

Commit

Permalink
translator/lua: Add support for :let+= operation with lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ZyX-I committed Apr 2, 2015
1 parent d93d7d3 commit 5d049ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/nvim/viml/executor/vim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ scalar = {
-- }}}3
}

scalar.mod_add = scalar.add

-- {{{2 Container type base
local numop = function(state, val1, val1_position, val2, val2_position)
-- One of the following calls must fail for container type
Expand All @@ -328,6 +330,8 @@ container = {
-- }}}3
}

container.mod_add = container.add

-- {{{2 Basic types
-- {{{3 Number
number = join_tables(scalar, {
Expand Down Expand Up @@ -595,7 +599,7 @@ list = join_tables(container, {
end
end,
num_op_priority = 3,
add = function(state, val1, val1_position, val2, val2_position)
do_add = function(state, copy_ret, val1, val1_position, val2, val2_position)
if not (is_list(val1) and is_list(val2)) then
-- Error out
if is_list(val1) then
Expand All @@ -606,12 +610,18 @@ list = join_tables(container, {
end
local length1 = list.length(val1)
local length2 = list.length(val2)
local ret = copy_table(val1)
local ret = copy_ret and copy_table(val1) or val1
for i, v in ipairs(val2) do
ret[length1 + i] = v
end
return ret
end,
add = function(state, ...)
return list.do_add(state, true, ...)
end,
mod_add = function(state, ...)
return list.do_add(state, false, ...)
end,
-- }}}4
})

Expand Down Expand Up @@ -1275,6 +1285,10 @@ op = {
return iterop(state, 'add', ...)
end,

mod_add = function(state, ...)
return iterop(state, 'mod_add', ...)
end,

subtract = function(state, ...)
return iterop(state, 'subtract', ...)
end,
Expand Down Expand Up @@ -1361,6 +1375,9 @@ op = {
end,
}

op.mod_concat = op.concat
op.mod_subtract = op.subtract

-- {{{1 Subscripting
local subscript = {
subscript = function(state, bind, val, idx)
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/viml/translator/translator.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ static FDEC(translate_modifying_assignment, const LetModAssArgs *args)
assert(false);
}
}
WS("vim.op.");
WS("vim.op.mod_");
W(op);
WS("(state, ");
F(translate_expr_node, TRANS_EXPR_ARGS(args->lval_expr), false);
Expand Down

0 comments on commit 5d049ad

Please sign in to comment.