aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-11-06 01:15:18 +0300
committerZyX <kp-pav@yandex.ru>2017-11-06 01:17:39 +0300
commitebb59778371784ba28d37fc615ae02a5338f365d (patch)
tree6ca5657ce7fe93dbc81c3a7edc8201b6eedc6c18 /src/nvim/api/vim.c
parent7849070f998902bb6aae5d6f9147d4daf5421b36 (diff)
downloadrneovim-ebb59778371784ba28d37fc615ae02a5338f365d.tar.gz
rneovim-ebb59778371784ba28d37fc615ae02a5338f365d.tar.bz2
rneovim-ebb59778371784ba28d37fc615ae02a5338f365d.zip
api/vim: Add “len” dictionary key
This allows determining where parsing ended which may be needed for e.g. parsing `:echo` with that API function.
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r--src/nvim/api/vim.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index b12c595cb5..8de37e2cf3 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -922,6 +922,12 @@ typedef kvec_withinit_t(ExprASTConvStackItem, 16) ExprASTConvStack;
/// Must contain exactly one "%.*s".
/// "arg": String, error message argument.
///
+/// "len": Amount of bytes successfully parsed. With flags equal to ""
+/// that should be equal to the length of expr string.
+///
+/// @note: “Sucessfully parsed” here means “participated in AST
+/// creation”, not “till the first error”.
+///
/// "ast": actual AST, either nil or a dictionary with the following
/// keys:
///
@@ -1000,9 +1006,8 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight,
&pstate, parser_simple_get_line, &plines_p, colors_p);
ExprAST east = viml_pexpr_parse(&pstate, pflags);
- // FIXME add parse_length key
const size_t ret_size = (
- 1 // "ast"
+ 2 // "ast", "len"
+ (size_t)(east.err.msg != NULL) // "error"
+ (size_t)highlight // "highlight"
);
@@ -1015,6 +1020,12 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight,
.key = STATIC_CSTR_TO_STRING("ast"),
.value = NIL,
};
+ ret.items[ret.size++] = (KeyValuePair) {
+ .key = STATIC_CSTR_TO_STRING("len"),
+ .value = INTEGER_OBJ((Integer)(pstate.pos.line == 1
+ ? plines[0].size
+ : pstate.pos.col)),
+ };
if (east.err.msg != NULL) {
Dictionary err_dict = {
.items = xmalloc(2 * sizeof(err_dict.items[0])),