From 7ca5dc2519018c33def6bd6361d26099df04e7e2 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 7 Oct 2020 00:03:12 -0400 Subject: vim-patch:8.1.1683: dictionary with string keys is longer than needed Problem: Dictionary with string keys is longer than needed. Solution: Use *{key: val} for literaly keys. https://github.com/vim/vim/commit/d5abb4c87727eecb71b0e8ffdda60fc9598272f3 Vim's popup,textprop features are N/A. Neovim has not polyfilled their APIs. Skip docs and tests for these features. --- src/nvim/eval.c | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 24192dfefa..70549b950d 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3905,6 +3905,7 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) // (expression) nested expression // [expr, expr] List // {key: val, key: val} Dictionary +// *{key: val, key: val} Dictionary with literal keys // // Also handle: // ! in front logical NOT @@ -4012,11 +4013,21 @@ static int eval7( case '[': ret = get_list_tv(arg, rettv, evaluate); break; + // Dictionary: *{key: val, key: val} + case '*': + if ((*arg)[1] == '{') { + (*arg)++; + ret = dict_get_tv(arg, rettv, evaluate, true); + } else { + ret = NOTDONE; + } + break; + // Lambda: {arg, arg -> expr} - // Dictionary: {key: val, key: val} + // Dictionary: {'key': val, 'key': val} case '{': ret = get_lambda_tv(arg, rettv, evaluate); if (ret == NOTDONE) { - ret = dict_get_tv(arg, rettv, evaluate); + ret = dict_get_tv(arg, rettv, evaluate, false); } break; @@ -5347,11 +5358,31 @@ static inline bool set_ref_dict(dict_T *dict, int copyID) return false; } -/* - * Allocate a variable for a Dictionary and fill it from "*arg". - * Return OK or FAIL. Returns NOTDONE for {expr}. - */ -static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate) + +// Get the key for *{key: val} into "tv" and advance "arg". +// Return FAIL when there is no valid key. +static int get_literal_key(char_u **arg, typval_T *tv) + FUNC_ATTR_NONNULL_ALL +{ + char_u *p; + + if (!ASCII_ISALNUM(**arg) && **arg != '_' && **arg != '-') { + return FAIL; + } + for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; p++) { + } + tv->v_type = VAR_STRING; + tv->vval.v_string = vim_strnsave(*arg, (int)(p - *arg)); + + *arg = skipwhite(p); + return OK; +} + +// Allocate a variable for a Dictionary and fill it from "*arg". +// "literal" is true for *{key: val} +// Return OK or FAIL. Returns NOTDONE for {expr}. +static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, + bool literal) { dict_T *d = NULL; typval_T tvkey; @@ -5385,7 +5416,9 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate) *arg = skipwhite(*arg + 1); while (**arg != '}' && **arg != NUL) { - if (eval1(arg, &tvkey, evaluate) == FAIL) { // recursive! + if ((literal + ? get_literal_key(arg, &tvkey) + : eval1(arg, &tvkey, evaluate)) == FAIL) { // recursive! goto failret; } if (**arg != ':') { -- cgit From d109a331446a998671bf54655df99238e2f1b093 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 7 Oct 2020 00:40:33 -0400 Subject: vim-patch:8.1.1686: "*" of "*{" is recognized as multipy operator Problem: "*" of "*{" is recognized as multipy operator. (Yasuhiro Matsumoto) Solution: Check for the "{". https://github.com/vim/vim/commit/2898ebb44cee62a70a11b44a97bdad8cc00157b1 --- src/nvim/eval.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 70549b950d..16d51d3a81 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3802,8 +3802,9 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) */ for (;; ) { op = **arg; - if (op != '*' && op != '/' && op != '%') + if ((op != '*' || (*arg)[1] == '{') && op != '/' && op != '%') { break; + } if (evaluate) { if (rettv->v_type == VAR_FLOAT) { -- cgit From 20fc7ef161f3c40b957ba81a751af4639cce7776 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 7 Oct 2020 00:45:05 -0400 Subject: vim-patch:8.1.1692: using *{} for literal dict is not backwards compatible Problem: Using *{} for literal dict is not backwards compatible. (Yasuhiro Matsumoto) Solution: Use ~{} instead. https://github.com/vim/vim/commit/b8be54dcc517c9d57b62409945b7d4b90b6c3071 --- src/nvim/eval.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 16d51d3a81..a4594d9ac8 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3802,7 +3802,7 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) */ for (;; ) { op = **arg; - if ((op != '*' || (*arg)[1] == '{') && op != '/' && op != '%') { + if (op != '*' && op != '/' && op != '%') { break; } @@ -3906,7 +3906,7 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) // (expression) nested expression // [expr, expr] List // {key: val, key: val} Dictionary -// *{key: val, key: val} Dictionary with literal keys +// ~{key: val, key: val} Dictionary with literal keys // // Also handle: // ! in front logical NOT @@ -4014,8 +4014,8 @@ static int eval7( case '[': ret = get_list_tv(arg, rettv, evaluate); break; - // Dictionary: *{key: val, key: val} - case '*': + // Dictionary: ~{key: val, key: val} + case '~': if ((*arg)[1] == '{') { (*arg)++; ret = dict_get_tv(arg, rettv, evaluate, true); -- cgit From 4a6e201e37a9b08860cb823c528ea062002b7ebc Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 7 Oct 2020 01:00:11 -0400 Subject: vim-patch:8.1.1705: using ~{} for a literal dict is not nice Problem: Using ~{} for a literal dict is not nice. Solution: Use #{} instead. https://github.com/vim/vim/commit/4c6d90458baae843463f930fdc3fe4a7a2191d27 --- src/nvim/eval.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a4594d9ac8..a2490be355 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3906,7 +3906,7 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) // (expression) nested expression // [expr, expr] List // {key: val, key: val} Dictionary -// ~{key: val, key: val} Dictionary with literal keys +// #{key: val, key: val} Dictionary with literal keys // // Also handle: // ! in front logical NOT @@ -4014,8 +4014,8 @@ static int eval7( case '[': ret = get_list_tv(arg, rettv, evaluate); break; - // Dictionary: ~{key: val, key: val} - case '~': + // Dictionary: #{key: val, key: val} + case '#': if ((*arg)[1] == '{') { (*arg)++; ret = dict_get_tv(arg, rettv, evaluate, true); -- cgit