0
0
mirror of https://github.com/vim/vim.git synced 2025-09-04 21:33:48 -04:00

patch 8.2.0613: Vim9: no check for space before #comment

Problem:    Vim9: no check for space before #comment.
Solution:   Add space checks.
This commit is contained in:
Bram Moolenaar 2020-04-20 22:42:32 +02:00
parent 2c7f8c574f
commit 1966c24881
6 changed files with 210 additions and 32 deletions

View File

@ -188,7 +188,7 @@ menutrans Set\ '&filetype'\ too Auch\ '&filetype'\ setzen
menutrans &Off &Aus menutrans &Off &Aus
menutrans &Manual &Manuell menutrans &Manual &Manuell
menutrans A&utomatic A&utomatisch menutrans A&utomatic A&utomatisch
menutrans on/off\ for\ &This\ file An/Aus (diese\ &Datei) menutrans on/off\ for\ &This\ file An/Aus\ (diese\ &Datei)
menutrans Co&lor\ test Test\ der\ Farben menutrans Co&lor\ test Test\ der\ Farben
menutrans &Highlight\ test Test\ der\ Un&terstreichungen menutrans &Highlight\ test Test\ der\ Un&terstreichungen
menutrans &Convert\ to\ HTML Konvertieren\ nach\ &HTML menutrans &Convert\ to\ HTML Konvertieren\ nach\ &HTML

View File

@ -694,7 +694,7 @@ do_highlight(
/* /*
* ":highlight {group-name}": list highlighting for one group. * ":highlight {group-name}": list highlighting for one group.
*/ */
if (!doclear && !dolink && ends_excmd(*linep)) if (!doclear && !dolink && ends_excmd2(line, linep))
{ {
id = syn_namen2id(line, (int)(name_end - line)); id = syn_namen2id(line, (int)(name_end - line));
if (id == 0) if (id == 0)
@ -720,14 +720,14 @@ do_highlight(
to_start = skipwhite(from_end); to_start = skipwhite(from_end);
to_end = skiptowhite(to_start); to_end = skiptowhite(to_start);
if (ends_excmd(*from_start) || ends_excmd(*to_start)) if (ends_excmd2(line, from_start) || ends_excmd2(line, to_start))
{ {
semsg(_("E412: Not enough arguments: \":highlight link %s\""), semsg(_("E412: Not enough arguments: \":highlight link %s\""),
from_start); from_start);
return; return;
} }
if (!ends_excmd(*skipwhite(to_end))) if (!ends_excmd2(line, skipwhite(to_end)))
{ {
semsg(_("E413: Too many arguments: \":highlight link %s\""), from_start); semsg(_("E413: Too many arguments: \":highlight link %s\""), from_start);
return; return;
@ -781,8 +781,7 @@ do_highlight(
/* /*
* ":highlight clear [group]" command. * ":highlight clear [group]" command.
*/ */
line = linep; if (ends_excmd2(line, linep))
if (ends_excmd(*line))
{ {
#ifdef FEAT_GUI #ifdef FEAT_GUI
// First, we do not destroy the old values, but allocate the new // First, we do not destroy the old values, but allocate the new
@ -826,7 +825,7 @@ do_highlight(
// It is now Ok to clear out the old data. // It is now Ok to clear out the old data.
#endif #endif
#ifdef FEAT_EVAL #ifdef FEAT_EVAL
do_unlet((char_u *)"colors_name", TRUE); do_unlet((char_u *)"g:colors_name", TRUE);
#endif #endif
restore_cterm_colors(); restore_cterm_colors();
@ -845,6 +844,7 @@ do_highlight(
redraw_later_clear(); redraw_later_clear();
return; return;
} }
line = linep;
name_end = skiptowhite(line); name_end = skiptowhite(line);
linep = skipwhite(name_end); linep = skipwhite(name_end);
} }
@ -888,7 +888,7 @@ do_highlight(
} }
if (!doclear) if (!doclear)
while (!ends_excmd(*linep)) while (!ends_excmd2(line, linep))
{ {
key_start = linep; key_start = linep;
if (*linep == '=') if (*linep == '=')
@ -4946,10 +4946,11 @@ ex_match(exarg_T *eap)
if (!eap->skip) if (!eap->skip)
match_delete(curwin, id, FALSE); match_delete(curwin, id, FALSE);
if (ends_excmd(*eap->arg)) if (ends_excmd2(eap->cmd, eap->arg))
end = eap->arg; end = eap->arg;
else if ((STRNICMP(eap->arg, "none", 4) == 0 else if ((STRNICMP(eap->arg, "none", 4) == 0
&& (VIM_ISWHITE(eap->arg[4]) || ends_excmd(eap->arg[4])))) && (VIM_ISWHITE(eap->arg[4])
|| ends_excmd2(eap->arg, eap->arg + 4))))
end = eap->arg + 4; end = eap->arg + 4;
else else
{ {
@ -4967,7 +4968,7 @@ ex_match(exarg_T *eap)
end = skip_regexp(p + 1, *p, TRUE); end = skip_regexp(p + 1, *p, TRUE);
if (!eap->skip) if (!eap->skip)
{ {
if (*end != NUL && !ends_excmd(*skipwhite(end + 1))) if (*end != NUL && !ends_excmd2(end, skipwhite(end + 1)))
{ {
vim_free(g); vim_free(g);
eap->errmsg = e_trailing; eap->errmsg = e_trailing;

View File

@ -2680,7 +2680,7 @@ ex_menutranslate(exarg_T *eap UNUSED)
/* /*
* ":menutrans clear": clear all translations. * ":menutrans clear": clear all translations.
*/ */
if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd2(arg, skipwhite(arg + 5)))
{ {
tp = (menutrans_T *)menutrans_ga.ga_data; tp = (menutrans_T *)menutrans_ga.ga_data;
for (i = 0; i < menutrans_ga.ga_len; ++i) for (i = 0; i < menutrans_ga.ga_len; ++i)
@ -2703,7 +2703,9 @@ ex_menutranslate(exarg_T *eap UNUSED)
to = skipwhite(arg); to = skipwhite(arg);
*arg = NUL; *arg = NUL;
arg = menu_skip_part(to); arg = menu_skip_part(to);
if (arg == to) if (arg == to || ends_excmd2(eap->arg, from)
|| ends_excmd2(eap->arg, to)
|| !ends_excmd2(eap->arg, skipwhite(arg)))
emsg(_(e_invarg)); emsg(_(e_invarg));
else else
{ {

View File

@ -3632,7 +3632,7 @@ syn_cmd_clear(exarg_T *eap, int syncing)
if (curwin->w_s->b_syn_topgrp != 0) if (curwin->w_s->b_syn_topgrp != 0)
return; return;
if (ends_excmd(*arg)) if (ends_excmd2(eap->cmd, arg))
{ {
/* /*
* No argument: Clear all syntax items. * No argument: Clear all syntax items.
@ -3652,7 +3652,7 @@ syn_cmd_clear(exarg_T *eap, int syncing)
/* /*
* Clear the group IDs that are in the argument. * Clear the group IDs that are in the argument.
*/ */
while (!ends_excmd(*arg)) while (!ends_excmd2(eap->cmd, arg))
{ {
arg_end = skiptowhite(arg); arg_end = skiptowhite(arg);
if (*arg == '@') if (*arg == '@')
@ -3843,7 +3843,7 @@ syn_cmd_list(
} }
else else
msg_puts_title(_("\n--- Syntax items ---")); msg_puts_title(_("\n--- Syntax items ---"));
if (ends_excmd(*arg)) if (ends_excmd2(eap->cmd, arg))
{ {
/* /*
* No argument: List all group IDs and all syntax clusters. * No argument: List all group IDs and all syntax clusters.
@ -3858,7 +3858,7 @@ syn_cmd_list(
/* /*
* List the group IDs and syntax clusters that are in the argument. * List the group IDs and syntax clusters that are in the argument.
*/ */
while (!ends_excmd(*arg) && !got_int) while (!ends_excmd2(eap->cmd, arg) && !got_int)
{ {
arg_end = skiptowhite(arg); arg_end = skiptowhite(arg);
if (*arg == '@') if (*arg == '@')
@ -4463,11 +4463,12 @@ get_group_name(
*/ */
static char_u * static char_u *
get_syn_options( get_syn_options(
char_u *arg, // next argument to be checked char_u *start, // next argument to be checked
syn_opt_arg_T *opt, // various things syn_opt_arg_T *opt, // various things
int *conceal_char UNUSED, int *conceal_char UNUSED,
int skip) // TRUE if skipping over command int skip) // TRUE if skipping over command
{ {
char_u *arg = start;
char_u *gname_start, *gname; char_u *gname_start, *gname;
int syn_id; int syn_id;
int len; int len;
@ -4528,7 +4529,7 @@ get_syn_options(
if (p[i] == NUL && (VIM_ISWHITE(arg[len]) if (p[i] == NUL && (VIM_ISWHITE(arg[len])
|| (flagtab[fidx].argtype > 0 || (flagtab[fidx].argtype > 0
? arg[len] == '=' ? arg[len] == '='
: ends_excmd(arg[len])))) : ends_excmd2(start, arg + len))))
{ {
if (opt->keyword if (opt->keyword
&& (flagtab[fidx].flags == HL_DISPLAY && (flagtab[fidx].flags == HL_DISPLAY
@ -4790,11 +4791,12 @@ syn_cmd_keyword(exarg_T *eap, int syncing UNUSED)
*/ */
cnt = 0; cnt = 0;
p = keyword_copy; p = keyword_copy;
for ( ; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) for ( ; rest != NULL && !ends_excmd2(eap->arg, rest);
rest = skipwhite(rest))
{ {
rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, rest = get_syn_options(rest, &syn_opt_arg, &conceal_char,
eap->skip); eap->skip);
if (rest == NULL || ends_excmd(*rest)) if (rest == NULL || ends_excmd2(eap->arg, rest))
break; break;
// Copy the keyword, removing backslashes, and add a NUL. // Copy the keyword, removing backslashes, and add a NUL.
while (*rest != NUL && !VIM_ISWHITE(*rest)) while (*rest != NUL && !VIM_ISWHITE(*rest))
@ -4892,6 +4894,7 @@ syn_cmd_match(
syn_opt_arg_T syn_opt_arg; syn_opt_arg_T syn_opt_arg;
int sync_idx = 0; int sync_idx = 0;
int conceal_char = NUL; int conceal_char = NUL;
int orig_called_emsg = called_emsg;
// Isolate the group name, check for validity // Isolate the group name, check for validity
rest = get_group_name(arg, &group_name_end); rest = get_group_name(arg, &group_name_end);
@ -4922,7 +4925,7 @@ syn_cmd_match(
* Check for trailing command and illegal trailing arguments. * Check for trailing command and illegal trailing arguments.
*/ */
eap->nextcmd = check_nextcmd(rest); eap->nextcmd = check_nextcmd(rest);
if (!ends_excmd(*rest) || eap->skip) if (!ends_excmd2(eap->cmd, rest) || eap->skip)
rest = NULL; rest = NULL;
else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL
&& (syn_id = syn_check_group(arg, && (syn_id = syn_check_group(arg,
@ -4974,7 +4977,7 @@ syn_cmd_match(
vim_free(syn_opt_arg.cont_in_list); vim_free(syn_opt_arg.cont_in_list);
vim_free(syn_opt_arg.next_list); vim_free(syn_opt_arg.next_list);
if (rest == NULL) if (rest == NULL && called_emsg == orig_called_emsg)
semsg(_(e_invarg2), arg); semsg(_(e_invarg2), arg);
} }
@ -5037,11 +5040,11 @@ syn_cmd_region(
/* /*
* get the options, patterns and matchgroup. * get the options, patterns and matchgroup.
*/ */
while (rest != NULL && !ends_excmd(*rest)) while (rest != NULL && !ends_excmd2(eap->cmd, rest))
{ {
// Check for option arguments // Check for option arguments
rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
if (rest == NULL || ends_excmd(*rest)) if (rest == NULL || ends_excmd2(eap->cmd, rest))
break; break;
// must be a pattern or matchgroup then // must be a pattern or matchgroup then
@ -5570,7 +5573,7 @@ syn_cmd_cluster(exarg_T *eap, int syncing UNUSED)
if (!got_clstr) if (!got_clstr)
emsg(_("E400: No cluster specified")); emsg(_("E400: No cluster specified"));
if (rest == NULL || !ends_excmd(*rest)) if (rest == NULL || !ends_excmd2(eap->cmd, rest))
semsg(_(e_invarg2), arg); semsg(_(e_invarg2), arg);
} }
@ -5680,7 +5683,7 @@ get_syn_pattern(char_u *arg, synpat_T *ci)
} }
} while (idx >= 0); } while (idx >= 0);
if (!ends_excmd(*end) && !VIM_ISWHITE(*end)) if (!ends_excmd2(arg, end) && !VIM_ISWHITE(*end))
{ {
semsg(_("E402: Garbage after pattern: %s"), arg); semsg(_("E402: Garbage after pattern: %s"), arg);
return NULL; return NULL;
@ -5703,13 +5706,13 @@ syn_cmd_sync(exarg_T *eap, int syncing UNUSED)
long n; long n;
char_u *cpo_save; char_u *cpo_save;
if (ends_excmd(*arg_start)) if (ends_excmd2(eap->cmd, arg_start))
{ {
syn_cmd_list(eap, TRUE); syn_cmd_list(eap, TRUE);
return; return;
} }
while (!ends_excmd(*arg_start)) while (!ends_excmd2(eap->cmd, arg_start))
{ {
arg_end = skiptowhite(arg_start); arg_end = skiptowhite(arg_start);
next_arg = skipwhite(arg_end); next_arg = skipwhite(arg_end);
@ -5719,7 +5722,7 @@ syn_cmd_sync(exarg_T *eap, int syncing UNUSED)
{ {
if (!eap->skip) if (!eap->skip)
curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT;
if (!ends_excmd(*next_arg)) if (!ends_excmd2(eap->cmd, next_arg))
{ {
arg_end = skiptowhite(next_arg); arg_end = skiptowhite(next_arg);
if (!eap->skip) if (!eap->skip)
@ -5888,7 +5891,7 @@ get_id_list(
break; break;
} }
p = skipwhite(p + 1); p = skipwhite(p + 1);
if (ends_excmd(*p)) if (ends_excmd2(*arg, p))
{ {
semsg(_("E406: Empty argument: %s"), *arg); semsg(_("E406: Empty argument: %s"), *arg);
break; break;
@ -5898,7 +5901,7 @@ get_id_list(
* parse the arguments after "contains" * parse the arguments after "contains"
*/ */
count = 0; count = 0;
while (!ends_excmd(*p)) while (!ends_excmd2(*arg, p))
{ {
for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end) for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end)
; ;

View File

@ -1210,6 +1210,176 @@ def Test_vim9_comment()
'vim9script', 'vim9script',
'hi# comment', 'hi# comment',
], 'E416:') ], 'E416:')
CheckScriptSuccess([
'vim9script',
'hi Search # comment',
])
CheckScriptFailure([
'vim9script',
'hi Search# comment',
], 'E416:')
CheckScriptSuccess([
'vim9script',
'hi link This Search # comment',
])
CheckScriptFailure([
'vim9script',
'hi link This That# comment',
], 'E413:')
CheckScriptSuccess([
'vim9script',
'hi clear This # comment',
'hi clear # comment',
])
" not tested, because it doesn't give an error but a warning:
" hi clear This# comment',
CheckScriptFailure([
'vim9script',
'hi clear# comment',
], 'E416:')
CheckScriptSuccess([
'vim9script',
'hi Group term=bold',
'match Group /todo/ # comment',
])
CheckScriptFailure([
'vim9script',
'hi Group term=bold',
'match Group /todo/# comment',
], 'E488:')
CheckScriptSuccess([
'vim9script',
'match # comment',
])
CheckScriptFailure([
'vim9script',
'match# comment',
], 'E475:')
CheckScriptSuccess([
'vim9script',
'match none # comment',
])
CheckScriptFailure([
'vim9script',
'match none# comment',
], 'E475:')
CheckScriptSuccess([
'vim9script',
'menutrans clear # comment',
])
CheckScriptFailure([
'vim9script',
'menutrans clear# comment text',
], 'E474:')
CheckScriptSuccess([
'vim9script',
'syntax clear # comment',
])
CheckScriptFailure([
'vim9script',
'syntax clear# comment text',
], 'E28:')
CheckScriptSuccess([
'vim9script',
'syntax keyword Word some',
'syntax clear Word # comment',
])
CheckScriptFailure([
'vim9script',
'syntax keyword Word some',
'syntax clear Word# comment text',
], 'E28:')
CheckScriptSuccess([
'vim9script',
'syntax list # comment',
])
CheckScriptFailure([
'vim9script',
'syntax list# comment text',
], 'E28:')
CheckScriptSuccess([
'vim9script',
'syntax match Word /pat/ oneline # comment',
])
CheckScriptFailure([
'vim9script',
'syntax match Word /pat/ oneline# comment',
], 'E475:')
CheckScriptSuccess([
'vim9script',
'syntax keyword Word word # comm[ent',
])
CheckScriptFailure([
'vim9script',
'syntax keyword Word word# comm[ent',
], 'E789:')
CheckScriptSuccess([
'vim9script',
'syntax match Word /pat/ # comment',
])
CheckScriptFailure([
'vim9script',
'syntax match Word /pat/# comment',
], 'E402:')
CheckScriptSuccess([
'vim9script',
'syntax match Word /pat/ contains=Something # comment',
])
CheckScriptFailure([
'vim9script',
'syntax match Word /pat/ contains=Something# comment',
], 'E475:')
CheckScriptFailure([
'vim9script',
'syntax match Word /pat/ contains= # comment',
], 'E406:')
CheckScriptFailure([
'vim9script',
'syntax match Word /pat/ contains=# comment',
], 'E475:')
CheckScriptSuccess([
'vim9script',
'syntax region Word start=/pat/ end=/pat/ # comment',
])
CheckScriptFailure([
'vim9script',
'syntax region Word start=/pat/ end=/pat/# comment',
], 'E475:')
CheckScriptSuccess([
'vim9script',
'syntax sync # comment',
])
CheckScriptFailure([
'vim9script',
'syntax sync# comment',
], 'E404:')
CheckScriptSuccess([
'vim9script',
'syntax sync ccomment # comment',
])
CheckScriptFailure([
'vim9script',
'syntax sync ccomment# comment',
], 'E404:')
CheckScriptSuccess([
'vim9script',
'syntax cluster Some contains=Word # comment',
])
CheckScriptFailure([
'vim9script',
'syntax cluster Some contains=Word# comment',
], 'E475:')
enddef enddef
def Test_vim9_comment_gui() def Test_vim9_comment_gui()

View File

@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
613,
/**/ /**/
612, 612,
/**/ /**/