diff options
author | Josh Rahm <rahm@google.com> | 2022-07-18 19:37:18 +0000 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2022-07-18 19:37:18 +0000 |
commit | 308e1940dcd64aa6c344c403d4f9e0dda58d9c5c (patch) | |
tree | 35fe43e01755e0f312650667004487a44d6b7941 /src/nvim/viml/parser/expressions.c | |
parent | 96a00c7c588b2f38a2424aeeb4ea3581d370bf2d (diff) | |
parent | e8c94697bcbe23a5c7b07c292b90a6b70aadfa87 (diff) | |
download | rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.gz rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.bz2 rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.zip |
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'src/nvim/viml/parser/expressions.c')
-rw-r--r-- | src/nvim/viml/parser/expressions.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 8a14710351..fd7dc17ee3 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -66,7 +66,7 @@ #include "nvim/viml/parser/expressions.h" #include "nvim/viml/parser/parser.h" -#define vim_str2nr(s, ...) vim_str2nr((const char_u *)(s), __VA_ARGS__) +#define VIM_STR2NR(s, ...) vim_str2nr((const char_u *)(s), __VA_ARGS__) typedef kvec_withinit_t(ExprASTNode **, 16) ExprASTStack; @@ -371,7 +371,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) significand_part = significand_part * 10 + (pline.data[i] - '0'); } if (exp_start) { - vim_str2nr(pline.data + exp_start, NULL, NULL, 0, NULL, &exp_part, + VIM_STR2NR(pline.data + exp_start, NULL, NULL, 0, NULL, &exp_part, (int)(ret.len - exp_start), false); } if (exp_negative) { @@ -389,7 +389,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) } else { int len; int prep; - vim_str2nr(pline.data, &prep, &len, STR2NR_ALL, NULL, + VIM_STR2NR(pline.data, &prep, &len, STR2NR_ALL, NULL, &ret.data.num.val.integer, (int)pline.size, false); ret.len = (size_t)len; const uint8_t bases[] = { @@ -541,8 +541,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) ret.data.opt.len = 4; ret.len += 4; } else { - for (; p < e && ASCII_ISALPHA(*p); p++) { - } + for (; p < e && ASCII_ISALPHA(*p); p++) {} ret.data.opt.len = (size_t)(p - ret.data.opt.name); if (ret.data.opt.len == 0) { OPTNAMEMISS(ret); @@ -1592,7 +1591,7 @@ typedef struct { /// string is a regex. /// @param[in] is_invalid Whether currently processed token is not valid. static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const node, - const LexExprToken token, const ExprASTStack ast_stack, + const LexExprToken token, const ExprASTStack *ast_stack, const bool is_invalid) FUNC_ATTR_NONNULL_ALL { @@ -1652,10 +1651,11 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no } switch (*p) { // A "\<x>" form occupies at least 4 characters, and produces up to - // 6 characters: reserve space for 2 extra, but do not compute actual - // length just now, it would be costy. + // to 9 characters (6 for the char and 3 for a modifier): + // reserve space for 5 extra, but do not compute actual length + // just now, it would be costly. case '<': - size += 2; + size += 5; break; // Hexadecimal, always single byte, but at least three bytes each. case 'x': @@ -1788,7 +1788,7 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no if (is_hex) { *v_p++ = (char)nr; } else { - v_p += utf_char2bytes(nr, (char_u *)v_p); + v_p += utf_char2bytes(nr, v_p); } } else { is_unknown = true; @@ -1817,9 +1817,13 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no } // Special key, e.g.: "\<C-W>" case '<': { - const size_t special_len = ( - trans_special((const char_u **)&p, (size_t)(e - p), - (char_u *)v_p, true, true)); + int flags = FSK_KEYCODE | FSK_IN_STRING; + + if (p[1] != '*') { + flags |= FSK_SIMPLIFY; + } + const size_t special_len = trans_special((const char_u **)&p, (size_t)(e - p), + (char_u *)v_p, flags, false, NULL); if (special_len != 0) { v_p += special_len; } else { @@ -2642,6 +2646,7 @@ viml_pexpr_parse_figure_brace_closing_error: kvi_push(pt_stack, kEPTLambdaArguments); lambda_node = cur_node; } else { + // uncrustify:off ADD_IDENT(do { NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeCurlyBracesIdentifier); @@ -2656,6 +2661,7 @@ viml_pexpr_parse_figure_brace_closing_error: want_node = kENodeValue; } while (0), Curly); + // uncrustify:on } if (pt_is_assignment(cur_pt) && !pt_is_assignment(kv_last(pt_stack))) { @@ -2733,6 +2739,7 @@ viml_pexpr_parse_figure_brace_closing_error: : HL(IdentifierName))); } else { if (scope == kExprVarScopeMissing) { + // uncrustify:off ADD_IDENT(do { NEW_NODE_WITH_CUR_POS(cur_node, kExprNodePlainIdentifier); cur_node->data.var.scope = scope; @@ -2741,6 +2748,7 @@ viml_pexpr_parse_figure_brace_closing_error: want_node = kENodeOperator; } while (0), IdentifierName); + // uncrustify:on } else { OP_MISSING; } @@ -2907,7 +2915,7 @@ viml_pexpr_parse_no_paren_closing_error: {} ? kExprNodeDoubleQuotedString : kExprNodeSingleQuotedString)); *top_node_p = cur_node; - parse_quoted_string(pstate, cur_node, cur_token, ast_stack, is_invalid); + parse_quoted_string(pstate, cur_node, cur_token, &ast_stack, is_invalid); want_node = kENodeOperator; break; } @@ -3063,7 +3071,7 @@ viml_pexpr_parse_end: } kvi_destroy(ast_stack); return ast; -} // NOLINT(readability/fn_size) +} #undef NEW_NODE #undef HL |