comparison src/syntax.c @ 20116:513c62184ed8 v8.2.0613

patch 8.2.0613: Vim9: no check for space before #comment Commit: https://github.com/vim/vim/commit/1966c248814d5195edcd1208ed0e51e664a61283 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 20 22:42:32 2020 +0200 patch 8.2.0613: Vim9: no check for space before #comment Problem: Vim9: no check for space before #comment. Solution: Add space checks.
author Bram Moolenaar <Bram@vim.org>
date Mon, 20 Apr 2020 22:45:04 +0200
parents aadd1cae2ff5
children 99b6e6bf48bf
comparison
equal deleted inserted replaced
20115:bd021eb62e73 20116:513c62184ed8
3630 * clear". 3630 * clear".
3631 */ 3631 */
3632 if (curwin->w_s->b_syn_topgrp != 0) 3632 if (curwin->w_s->b_syn_topgrp != 0)
3633 return; 3633 return;
3634 3634
3635 if (ends_excmd(*arg)) 3635 if (ends_excmd2(eap->cmd, arg))
3636 { 3636 {
3637 /* 3637 /*
3638 * No argument: Clear all syntax items. 3638 * No argument: Clear all syntax items.
3639 */ 3639 */
3640 if (syncing) 3640 if (syncing)
3650 else 3650 else
3651 { 3651 {
3652 /* 3652 /*
3653 * Clear the group IDs that are in the argument. 3653 * Clear the group IDs that are in the argument.
3654 */ 3654 */
3655 while (!ends_excmd(*arg)) 3655 while (!ends_excmd2(eap->cmd, arg))
3656 { 3656 {
3657 arg_end = skiptowhite(arg); 3657 arg_end = skiptowhite(arg);
3658 if (*arg == '@') 3658 if (*arg == '@')
3659 { 3659 {
3660 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); 3660 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1));
3841 syn_match_msg(); 3841 syn_match_msg();
3842 } 3842 }
3843 } 3843 }
3844 else 3844 else
3845 msg_puts_title(_("\n--- Syntax items ---")); 3845 msg_puts_title(_("\n--- Syntax items ---"));
3846 if (ends_excmd(*arg)) 3846 if (ends_excmd2(eap->cmd, arg))
3847 { 3847 {
3848 /* 3848 /*
3849 * No argument: List all group IDs and all syntax clusters. 3849 * No argument: List all group IDs and all syntax clusters.
3850 */ 3850 */
3851 for (id = 1; id <= highlight_num_groups() && !got_int; ++id) 3851 for (id = 1; id <= highlight_num_groups() && !got_int; ++id)
3856 else 3856 else
3857 { 3857 {
3858 /* 3858 /*
3859 * List the group IDs and syntax clusters that are in the argument. 3859 * List the group IDs and syntax clusters that are in the argument.
3860 */ 3860 */
3861 while (!ends_excmd(*arg) && !got_int) 3861 while (!ends_excmd2(eap->cmd, arg) && !got_int)
3862 { 3862 {
3863 arg_end = skiptowhite(arg); 3863 arg_end = skiptowhite(arg);
3864 if (*arg == '@') 3864 if (*arg == '@')
3865 { 3865 {
3866 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); 3866 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1));
4461 * Return a pointer to the next argument (which isn't an option). 4461 * Return a pointer to the next argument (which isn't an option).
4462 * Return NULL for any error; 4462 * Return NULL for any error;
4463 */ 4463 */
4464 static char_u * 4464 static char_u *
4465 get_syn_options( 4465 get_syn_options(
4466 char_u *arg, // next argument to be checked 4466 char_u *start, // next argument to be checked
4467 syn_opt_arg_T *opt, // various things 4467 syn_opt_arg_T *opt, // various things
4468 int *conceal_char UNUSED, 4468 int *conceal_char UNUSED,
4469 int skip) // TRUE if skipping over command 4469 int skip) // TRUE if skipping over command
4470 { 4470 {
4471 char_u *arg = start;
4471 char_u *gname_start, *gname; 4472 char_u *gname_start, *gname;
4472 int syn_id; 4473 int syn_id;
4473 int len; 4474 int len;
4474 char *p; 4475 char *p;
4475 int i; 4476 int i;
4526 if (arg[len] != p[i] && arg[len] != p[i + 1]) 4527 if (arg[len] != p[i] && arg[len] != p[i + 1])
4527 break; 4528 break;
4528 if (p[i] == NUL && (VIM_ISWHITE(arg[len]) 4529 if (p[i] == NUL && (VIM_ISWHITE(arg[len])
4529 || (flagtab[fidx].argtype > 0 4530 || (flagtab[fidx].argtype > 0
4530 ? arg[len] == '=' 4531 ? arg[len] == '='
4531 : ends_excmd(arg[len])))) 4532 : ends_excmd2(start, arg + len))))
4532 { 4533 {
4533 if (opt->keyword 4534 if (opt->keyword
4534 && (flagtab[fidx].flags == HL_DISPLAY 4535 && (flagtab[fidx].flags == HL_DISPLAY
4535 || flagtab[fidx].flags == HL_FOLD 4536 || flagtab[fidx].flags == HL_FOLD
4536 || flagtab[fidx].flags == HL_EXTEND)) 4537 || flagtab[fidx].flags == HL_EXTEND))
4788 * found before keywords can be created. 4789 * found before keywords can be created.
4789 * 1: collect the options and copy the keywords to keyword_copy. 4790 * 1: collect the options and copy the keywords to keyword_copy.
4790 */ 4791 */
4791 cnt = 0; 4792 cnt = 0;
4792 p = keyword_copy; 4793 p = keyword_copy;
4793 for ( ; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) 4794 for ( ; rest != NULL && !ends_excmd2(eap->arg, rest);
4795 rest = skipwhite(rest))
4794 { 4796 {
4795 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, 4797 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char,
4796 eap->skip); 4798 eap->skip);
4797 if (rest == NULL || ends_excmd(*rest)) 4799 if (rest == NULL || ends_excmd2(eap->arg, rest))
4798 break; 4800 break;
4799 // Copy the keyword, removing backslashes, and add a NUL. 4801 // Copy the keyword, removing backslashes, and add a NUL.
4800 while (*rest != NUL && !VIM_ISWHITE(*rest)) 4802 while (*rest != NUL && !VIM_ISWHITE(*rest))
4801 { 4803 {
4802 if (*rest == '\\' && rest[1] != NUL) 4804 if (*rest == '\\' && rest[1] != NUL)
4890 int syn_id; 4892 int syn_id;
4891 int idx; 4893 int idx;
4892 syn_opt_arg_T syn_opt_arg; 4894 syn_opt_arg_T syn_opt_arg;
4893 int sync_idx = 0; 4895 int sync_idx = 0;
4894 int conceal_char = NUL; 4896 int conceal_char = NUL;
4897 int orig_called_emsg = called_emsg;
4895 4898
4896 // Isolate the group name, check for validity 4899 // Isolate the group name, check for validity
4897 rest = get_group_name(arg, &group_name_end); 4900 rest = get_group_name(arg, &group_name_end);
4898 4901
4899 // Get options before the pattern 4902 // Get options before the pattern
4920 { 4923 {
4921 /* 4924 /*
4922 * Check for trailing command and illegal trailing arguments. 4925 * Check for trailing command and illegal trailing arguments.
4923 */ 4926 */
4924 eap->nextcmd = check_nextcmd(rest); 4927 eap->nextcmd = check_nextcmd(rest);
4925 if (!ends_excmd(*rest) || eap->skip) 4928 if (!ends_excmd2(eap->cmd, rest) || eap->skip)
4926 rest = NULL; 4929 rest = NULL;
4927 else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL 4930 else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL
4928 && (syn_id = syn_check_group(arg, 4931 && (syn_id = syn_check_group(arg,
4929 (int)(group_name_end - arg))) != 0) 4932 (int)(group_name_end - arg))) != 0)
4930 { 4933 {
4972 vim_free(item.sp_pattern); 4975 vim_free(item.sp_pattern);
4973 vim_free(syn_opt_arg.cont_list); 4976 vim_free(syn_opt_arg.cont_list);
4974 vim_free(syn_opt_arg.cont_in_list); 4977 vim_free(syn_opt_arg.cont_in_list);
4975 vim_free(syn_opt_arg.next_list); 4978 vim_free(syn_opt_arg.next_list);
4976 4979
4977 if (rest == NULL) 4980 if (rest == NULL && called_emsg == orig_called_emsg)
4978 semsg(_(e_invarg2), arg); 4981 semsg(_(e_invarg2), arg);
4979 } 4982 }
4980 4983
4981 /* 4984 /*
4982 * Handle ":syntax region {group-name} [matchgroup={group-name}] 4985 * Handle ":syntax region {group-name} [matchgroup={group-name}]
5035 syn_opt_arg.next_list = NULL; 5038 syn_opt_arg.next_list = NULL;
5036 5039
5037 /* 5040 /*
5038 * get the options, patterns and matchgroup. 5041 * get the options, patterns and matchgroup.
5039 */ 5042 */
5040 while (rest != NULL && !ends_excmd(*rest)) 5043 while (rest != NULL && !ends_excmd2(eap->cmd, rest))
5041 { 5044 {
5042 // Check for option arguments 5045 // Check for option arguments
5043 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); 5046 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
5044 if (rest == NULL || ends_excmd(*rest)) 5047 if (rest == NULL || ends_excmd2(eap->cmd, rest))
5045 break; 5048 break;
5046 5049
5047 // must be a pattern or matchgroup then 5050 // must be a pattern or matchgroup then
5048 key_end = rest; 5051 key_end = rest;
5049 while (*key_end && !VIM_ISWHITE(*key_end) && *key_end != '=') 5052 while (*key_end && !VIM_ISWHITE(*key_end) && *key_end != '=')
5568 } 5571 }
5569 } 5572 }
5570 5573
5571 if (!got_clstr) 5574 if (!got_clstr)
5572 emsg(_("E400: No cluster specified")); 5575 emsg(_("E400: No cluster specified"));
5573 if (rest == NULL || !ends_excmd(*rest)) 5576 if (rest == NULL || !ends_excmd2(eap->cmd, rest))
5574 semsg(_(e_invarg2), arg); 5577 semsg(_(e_invarg2), arg);
5575 } 5578 }
5576 5579
5577 /* 5580 /*
5578 * On first call for current buffer: Init growing array. 5581 * On first call for current buffer: Init growing array.
5678 ++end; 5681 ++end;
5679 } 5682 }
5680 } 5683 }
5681 } while (idx >= 0); 5684 } while (idx >= 0);
5682 5685
5683 if (!ends_excmd(*end) && !VIM_ISWHITE(*end)) 5686 if (!ends_excmd2(arg, end) && !VIM_ISWHITE(*end))
5684 { 5687 {
5685 semsg(_("E402: Garbage after pattern: %s"), arg); 5688 semsg(_("E402: Garbage after pattern: %s"), arg);
5686 return NULL; 5689 return NULL;
5687 } 5690 }
5688 return skipwhite(end); 5691 return skipwhite(end);
5701 int illegal = FALSE; 5704 int illegal = FALSE;
5702 int finished = FALSE; 5705 int finished = FALSE;
5703 long n; 5706 long n;
5704 char_u *cpo_save; 5707 char_u *cpo_save;
5705 5708
5706 if (ends_excmd(*arg_start)) 5709 if (ends_excmd2(eap->cmd, arg_start))
5707 { 5710 {
5708 syn_cmd_list(eap, TRUE); 5711 syn_cmd_list(eap, TRUE);
5709 return; 5712 return;
5710 } 5713 }
5711 5714
5712 while (!ends_excmd(*arg_start)) 5715 while (!ends_excmd2(eap->cmd, arg_start))
5713 { 5716 {
5714 arg_end = skiptowhite(arg_start); 5717 arg_end = skiptowhite(arg_start);
5715 next_arg = skipwhite(arg_end); 5718 next_arg = skipwhite(arg_end);
5716 vim_free(key); 5719 vim_free(key);
5717 key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start)); 5720 key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start));
5718 if (STRCMP(key, "CCOMMENT") == 0) 5721 if (STRCMP(key, "CCOMMENT") == 0)
5719 { 5722 {
5720 if (!eap->skip) 5723 if (!eap->skip)
5721 curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; 5724 curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT;
5722 if (!ends_excmd(*next_arg)) 5725 if (!ends_excmd2(eap->cmd, next_arg))
5723 { 5726 {
5724 arg_end = skiptowhite(next_arg); 5727 arg_end = skiptowhite(next_arg);
5725 if (!eap->skip) 5728 if (!eap->skip)
5726 curwin->w_s->b_syn_sync_id = syn_check_group(next_arg, 5729 curwin->w_s->b_syn_sync_id = syn_check_group(next_arg,
5727 (int)(arg_end - next_arg)); 5730 (int)(arg_end - next_arg));
5886 { 5889 {
5887 semsg(_("E405: Missing equal sign: %s"), *arg); 5890 semsg(_("E405: Missing equal sign: %s"), *arg);
5888 break; 5891 break;
5889 } 5892 }
5890 p = skipwhite(p + 1); 5893 p = skipwhite(p + 1);
5891 if (ends_excmd(*p)) 5894 if (ends_excmd2(*arg, p))
5892 { 5895 {
5893 semsg(_("E406: Empty argument: %s"), *arg); 5896 semsg(_("E406: Empty argument: %s"), *arg);
5894 break; 5897 break;
5895 } 5898 }
5896 5899
5897 /* 5900 /*
5898 * parse the arguments after "contains" 5901 * parse the arguments after "contains"
5899 */ 5902 */
5900 count = 0; 5903 count = 0;
5901 while (!ends_excmd(*p)) 5904 while (!ends_excmd2(*arg, p))
5902 { 5905 {
5903 for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end) 5906 for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end)
5904 ; 5907 ;
5905 name = alloc(end - p + 3); // leave room for "^$" 5908 name = alloc(end - p + 3); // leave room for "^$"
5906 if (name == NULL) 5909 if (name == NULL)