Mercurial > vim
comparison src/eval.c @ 7611:9c420b8db435 v7.4.1105
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 16 16:49:28 2016 +0100
patch 7.4.1105
Problem: When using slices there is a mixup of variable name and namespace.
Solution: Recognize variables that can't be a namespace. (Hirohito Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 16 Jan 2016 17:00:05 +0100 |
parents | 8fc60af6dbf5 |
children | 228ff048db20 |
comparison
equal
deleted
inserted
replaced
7610:a49853dd0ccf | 7611:9c420b8db435 |
---|---|
112 static char *e_nofunc = N_("E130: Unknown function: %s"); | 112 static char *e_nofunc = N_("E130: Unknown function: %s"); |
113 static char *e_illvar = N_("E461: Illegal variable name: %s"); | 113 static char *e_illvar = N_("E461: Illegal variable name: %s"); |
114 #ifdef FEAT_FLOAT | 114 #ifdef FEAT_FLOAT |
115 static char *e_float_as_string = N_("E806: using Float as a String"); | 115 static char *e_float_as_string = N_("E806: using Float as a String"); |
116 #endif | 116 #endif |
117 | |
118 #define NAMESPACE_CHAR (char_u *)"abglstvw" | |
117 | 119 |
118 static dictitem_T globvars_var; /* variable used for g: */ | 120 static dictitem_T globvars_var; /* variable used for g: */ |
119 #define globvarht globvardict.dv_hashtab | 121 #define globvarht globvardict.dv_hashtab |
120 | 122 |
121 /* | 123 /* |
20664 char_u *p; | 20666 char_u *p; |
20665 int len; | 20667 int len; |
20666 | 20668 |
20667 /* Find the end of the name. */ | 20669 /* Find the end of the name. */ |
20668 for (p = *arg; eval_isnamec(*p); ++p) | 20670 for (p = *arg; eval_isnamec(*p); ++p) |
20669 ; | 20671 { |
20672 if (*p == ':') | |
20673 { | |
20674 /* "s:" is start of "s:var", but "n:" is not and can be used in | |
20675 * slice "[n:]". Also "xx:" is not a namespace. */ | |
20676 len = (int)(p - *arg); | |
20677 if ((len == 1 && vim_strchr(NAMESPACE_CHAR, **arg) == NULL) | |
20678 || len > 1) | |
20679 break; | |
20680 } | |
20681 } | |
20670 if (p == *arg) /* no name found */ | 20682 if (p == *arg) /* no name found */ |
20671 return 0; | 20683 return 0; |
20672 | 20684 |
20673 len = (int)(p - *arg); | 20685 len = (int)(p - *arg); |
20674 *arg = skipwhite(p); | 20686 *arg = skipwhite(p); |
20764 int flags; | 20776 int flags; |
20765 { | 20777 { |
20766 int mb_nest = 0; | 20778 int mb_nest = 0; |
20767 int br_nest = 0; | 20779 int br_nest = 0; |
20768 char_u *p; | 20780 char_u *p; |
20781 int len; | |
20769 | 20782 |
20770 if (expr_start != NULL) | 20783 if (expr_start != NULL) |
20771 { | 20784 { |
20772 *expr_start = NULL; | 20785 *expr_start = NULL; |
20773 *expr_end = NULL; | 20786 *expr_end = NULL; |
20797 /* skip over "str\"ing" to avoid counting [ and ] inside it. */ | 20810 /* skip over "str\"ing" to avoid counting [ and ] inside it. */ |
20798 for (p = p + 1; *p != NUL && *p != '"'; mb_ptr_adv(p)) | 20811 for (p = p + 1; *p != NUL && *p != '"'; mb_ptr_adv(p)) |
20799 if (*p == '\\' && p[1] != NUL) | 20812 if (*p == '\\' && p[1] != NUL) |
20800 ++p; | 20813 ++p; |
20801 if (*p == NUL) | 20814 if (*p == NUL) |
20815 break; | |
20816 } | |
20817 else if (br_nest == 0 && mb_nest == 0 && *p == ':') | |
20818 { | |
20819 /* "s:" is start of "s:var", but "n:" is not and can be used in | |
20820 * slice "[n:]". Also "xx:" is not a namespace. */ | |
20821 len = (int)(p - arg); | |
20822 if ((len == 1 && vim_strchr(NAMESPACE_CHAR, *arg) == NULL) | |
20823 || len > 1) | |
20802 break; | 20824 break; |
20803 } | 20825 } |
20804 | 20826 |
20805 if (mb_nest == 0) | 20827 if (mb_nest == 0) |
20806 { | 20828 { |