comparison src/eval.c @ 21512:81c47a694479 v8.2.1306

patch 8.2.1306: checking for first character of dict key is inconsistent Commit: https://github.com/vim/vim/commit/b13ab99908097d54e21ab5adad22f4ad2a8ec688 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 27 21:43:28 2020 +0200 patch 8.2.1306: checking for first character of dict key is inconsistent Problem: Checking for first character of dict key is inconsistent. Solution: Add eval_isdictc(). (closes https://github.com/vim/vim/issues/6546)
author Bram Moolenaar <Bram@vim.org>
date Mon, 27 Jul 2020 21:45:04 +0200
parents 4dfd00f481fb
children 4d3e983313dc
comparison
equal deleted inserted replaced
21511:90cfeda0e1c8 21512:81c47a694479
3462 { 3462 {
3463 /* 3463 /*
3464 * dict.name 3464 * dict.name
3465 */ 3465 */
3466 key = *arg + 1; 3466 key = *arg + 1;
3467 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) 3467 for (len = 0; eval_isdictc(key[len]); ++len)
3468 ; 3468 ;
3469 if (len == 0) 3469 if (len == 0)
3470 return FAIL; 3470 return FAIL;
3471 *arg = skipwhite(key + len); 3471 *arg = skipwhite(key + len);
3472 } 3472 }
4995 4995
4996 for (p = arg; *p != NUL 4996 for (p = arg; *p != NUL
4997 && (eval_isnamec(*p) 4997 && (eval_isnamec(*p)
4998 || (*p == '{' && !vim9script) 4998 || (*p == '{' && !vim9script)
4999 || ((flags & FNE_INCL_BR) && (*p == '[' 4999 || ((flags & FNE_INCL_BR) && (*p == '['
5000 || (*p == '.' && eval_isnamec1(p[1])))) 5000 || (*p == '.' && eval_isdictc(p[1]))))
5001 || mb_nest != 0 5001 || mb_nest != 0
5002 || br_nest != 0); MB_PTR_ADV(p)) 5002 || br_nest != 0); MB_PTR_ADV(p))
5003 { 5003 {
5004 if (*p == '\'') 5004 if (*p == '\'')
5005 { 5005 {
5126 * Does not include '{' or '}' for magic braces. 5126 * Does not include '{' or '}' for magic braces.
5127 */ 5127 */
5128 int 5128 int
5129 eval_isnamec(int c) 5129 eval_isnamec(int c)
5130 { 5130 {
5131 return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR); 5131 return ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR;
5132 } 5132 }
5133 5133
5134 /* 5134 /*
5135 * Return TRUE if character "c" can be used as the first character in a 5135 * Return TRUE if character "c" can be used as the first character in a
5136 * variable or function name (excluding '{' and '}'). 5136 * variable or function name (excluding '{' and '}').
5137 */ 5137 */
5138 int 5138 int
5139 eval_isnamec1(int c) 5139 eval_isnamec1(int c)
5140 { 5140 {
5141 return (ASCII_ISALPHA(c) || c == '_'); 5141 return ASCII_ISALPHA(c) || c == '_';
5142 }
5143
5144 /*
5145 * Return TRUE if character "c" can be used as the first character of a
5146 * dictionary key.
5147 */
5148 int
5149 eval_isdictc(int c)
5150 {
5151 return ASCII_ISALNUM(c) || c == '_';
5142 } 5152 }
5143 5153
5144 /* 5154 /*
5145 * Handle: 5155 * Handle:
5146 * - expr[expr], expr[expr:expr] subscript 5156 * - expr[expr], expr[expr:expr] subscript
5169 { 5179 {
5170 // When at the end of the line and ".name" or "->{" or "->X" follows in 5180 // When at the end of the line and ".name" or "->{" or "->X" follows in
5171 // the next line then consume the line break. 5181 // the next line then consume the line break.
5172 p = eval_next_non_blank(*arg, evalarg, &getnext); 5182 p = eval_next_non_blank(*arg, evalarg, &getnext);
5173 if (getnext 5183 if (getnext
5174 && ((rettv->v_type == VAR_DICT && *p == '.' 5184 && ((rettv->v_type == VAR_DICT && *p == '.' && eval_isdictc(p[1]))
5175 && ASCII_ISALPHA(p[1]))
5176 || (*p == '-' && p[1] == '>' 5185 || (*p == '-' && p[1] == '>'
5177 && (p[2] == '{' || ASCII_ISALPHA(p[2]))))) 5186 && (p[2] == '{' || ASCII_ISALPHA(p[2])))))
5178 { 5187 {
5179 *arg = eval_next_line(evalarg); 5188 *arg = eval_next_line(evalarg);
5180 check_white = FALSE; 5189 check_white = FALSE;