comparison src/syntax.c @ 10618:4ee16e5e2e26 v8.0.0198

patch 8.0.0198: some syntax arguments take effect even after "if 0" commit https://github.com/vim/vim/commit/de318c5c35ed0d65fd2a07196cb8acd5ee6d9bf8 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jan 17 16:27:10 2017 +0100 patch 8.0.0198: some syntax arguments take effect even after "if 0" Problem: Some syntax arguments take effect even after "if 0". (Taylor Venable) Solution: Properly skip the syntax statements. Make "syn case" and "syn conceal" report the current state. Fix that "syn clear" didn't reset the conceal flag. Add tests for :syntax skipping properly.
author Christian Brabandt <cb@256bit.org>
date Tue, 17 Jan 2017 16:30:05 +0100
parents 1c6db35e3527
children 5ac9d7920f11
comparison
equal deleted inserted replaced
10617:9a75c8a1b8b1 10618:4ee16e5e2e26
460 static int syn_list_keywords(int id, hashtab_T *ht, int did_header, int attr); 460 static int syn_list_keywords(int id, hashtab_T *ht, int did_header, int attr);
461 static void syn_clear_keyword(int id, hashtab_T *ht); 461 static void syn_clear_keyword(int id, hashtab_T *ht);
462 static void clear_keywtab(hashtab_T *ht); 462 static void clear_keywtab(hashtab_T *ht);
463 static void add_keyword(char_u *name, int id, int flags, short *cont_in_list, short *next_list, int conceal_char); 463 static void add_keyword(char_u *name, int id, int flags, short *cont_in_list, short *next_list, int conceal_char);
464 static char_u *get_group_name(char_u *arg, char_u **name_end); 464 static char_u *get_group_name(char_u *arg, char_u **name_end);
465 static char_u *get_syn_options(char_u *arg, syn_opt_arg_T *opt, int *conceal_char); 465 static char_u *get_syn_options(char_u *arg, syn_opt_arg_T *opt, int *conceal_char, int skip);
466 static void syn_cmd_include(exarg_T *eap, int syncing); 466 static void syn_cmd_include(exarg_T *eap, int syncing);
467 static void syn_cmd_iskeyword(exarg_T *eap, int syncing); 467 static void syn_cmd_iskeyword(exarg_T *eap, int syncing);
468 static void syn_cmd_keyword(exarg_T *eap, int syncing); 468 static void syn_cmd_keyword(exarg_T *eap, int syncing);
469 static void syn_cmd_match(exarg_T *eap, int syncing); 469 static void syn_cmd_match(exarg_T *eap, int syncing);
470 static void syn_cmd_region(exarg_T *eap, int syncing); 470 static void syn_cmd_region(exarg_T *eap, int syncing);
479 static int syn_check_cluster(char_u *pp, int len); 479 static int syn_check_cluster(char_u *pp, int len);
480 static int syn_add_cluster(char_u *name); 480 static int syn_add_cluster(char_u *name);
481 static void init_syn_patterns(void); 481 static void init_syn_patterns(void);
482 static char_u *get_syn_pattern(char_u *arg, synpat_T *ci); 482 static char_u *get_syn_pattern(char_u *arg, synpat_T *ci);
483 static void syn_cmd_sync(exarg_T *eap, int syncing); 483 static void syn_cmd_sync(exarg_T *eap, int syncing);
484 static int get_id_list(char_u **arg, int keylen, short **list); 484 static int get_id_list(char_u **arg, int keylen, short **list, int skip);
485 static void syn_combine_list(short **clstr1, short **clstr2, int list_op); 485 static void syn_combine_list(short **clstr1, short **clstr2, int list_op);
486 static void syn_incl_toplevel(int id, int *flagsp); 486 static void syn_incl_toplevel(int id, int *flagsp);
487 487
488 /* 488 /*
489 * Start the syntax recognition for a line. This function is normally called 489 * Start the syntax recognition for a line. This function is normally called
3432 eap->nextcmd = find_nextcmd(arg); 3432 eap->nextcmd = find_nextcmd(arg);
3433 if (eap->skip) 3433 if (eap->skip)
3434 return; 3434 return;
3435 3435
3436 next = skiptowhite(arg); 3436 next = skiptowhite(arg);
3437 if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2) 3437 if (*arg == NUL)
3438 {
3439 if (curwin->w_s->b_syn_conceal)
3440 MSG(_("syn conceal on"));
3441 else
3442 MSG(_("syn conceal off"));
3443 }
3444 else if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2)
3438 curwin->w_s->b_syn_conceal = TRUE; 3445 curwin->w_s->b_syn_conceal = TRUE;
3439 else if (STRNICMP(arg, "off", 3) == 0 && next - arg == 3) 3446 else if (STRNICMP(arg, "off", 3) == 0 && next - arg == 3)
3440 curwin->w_s->b_syn_conceal = FALSE; 3447 curwin->w_s->b_syn_conceal = FALSE;
3441 else 3448 else
3442 EMSG2(_("E390: Illegal argument: %s"), arg); 3449 EMSG2(_("E390: Illegal argument: %s"), arg);
3455 eap->nextcmd = find_nextcmd(arg); 3462 eap->nextcmd = find_nextcmd(arg);
3456 if (eap->skip) 3463 if (eap->skip)
3457 return; 3464 return;
3458 3465
3459 next = skiptowhite(arg); 3466 next = skiptowhite(arg);
3460 if (STRNICMP(arg, "match", 5) == 0 && next - arg == 5) 3467 if (*arg == NUL)
3468 {
3469 if (curwin->w_s->b_syn_ic)
3470 MSG(_("syntax case ignore"));
3471 else
3472 MSG(_("syntax case match"));
3473 }
3474 else if (STRNICMP(arg, "match", 5) == 0 && next - arg == 5)
3461 curwin->w_s->b_syn_ic = FALSE; 3475 curwin->w_s->b_syn_ic = FALSE;
3462 else if (STRNICMP(arg, "ignore", 6) == 0 && next - arg == 6) 3476 else if (STRNICMP(arg, "ignore", 6) == 0 && next - arg == 6)
3463 curwin->w_s->b_syn_ic = TRUE; 3477 curwin->w_s->b_syn_ic = TRUE;
3464 else 3478 else
3465 EMSG2(_("E390: Illegal argument: %s"), arg); 3479 EMSG2(_("E390: Illegal argument: %s"), arg);
3477 eap->nextcmd = find_nextcmd(arg); 3491 eap->nextcmd = find_nextcmd(arg);
3478 if (eap->skip) 3492 if (eap->skip)
3479 return; 3493 return;
3480 3494
3481 next = skiptowhite(arg); 3495 next = skiptowhite(arg);
3482 if (STRNICMP(arg, "toplevel", 8) == 0 && next - arg == 8) 3496 if (*arg == NUL)
3497 {
3498 if (curwin->w_s->b_syn_spell == SYNSPL_TOP)
3499 MSG(_("syntax spell toplevel"));
3500 else if (curwin->w_s->b_syn_spell == SYNSPL_NOTOP)
3501 MSG(_("syntax spell notoplevel"));
3502 else
3503 MSG(_("syntax spell default"));
3504 }
3505 else if (STRNICMP(arg, "toplevel", 8) == 0 && next - arg == 8)
3483 curwin->w_s->b_syn_spell = SYNSPL_TOP; 3506 curwin->w_s->b_syn_spell = SYNSPL_TOP;
3484 else if (STRNICMP(arg, "notoplevel", 10) == 0 && next - arg == 10) 3507 else if (STRNICMP(arg, "notoplevel", 10) == 0 && next - arg == 10)
3485 curwin->w_s->b_syn_spell = SYNSPL_NOTOP; 3508 curwin->w_s->b_syn_spell = SYNSPL_NOTOP;
3486 else if (STRNICMP(arg, "default", 7) == 0 && next - arg == 7) 3509 else if (STRNICMP(arg, "default", 7) == 0 && next - arg == 7)
3487 curwin->w_s->b_syn_spell = SYNSPL_DEFAULT; 3510 curwin->w_s->b_syn_spell = SYNSPL_DEFAULT;
3554 3577
3555 block->b_syn_error = FALSE; /* clear previous error */ 3578 block->b_syn_error = FALSE; /* clear previous error */
3556 block->b_syn_ic = FALSE; /* Use case, by default */ 3579 block->b_syn_ic = FALSE; /* Use case, by default */
3557 block->b_syn_spell = SYNSPL_DEFAULT; /* default spell checking */ 3580 block->b_syn_spell = SYNSPL_DEFAULT; /* default spell checking */
3558 block->b_syn_containedin = FALSE; 3581 block->b_syn_containedin = FALSE;
3582 #ifdef FEAT_CONCEAL
3583 block->b_syn_conceal = FALSE;
3584 #endif
3559 3585
3560 /* free the keywords */ 3586 /* free the keywords */
3561 clear_keywtab(&block->b_keywtab); 3587 clear_keywtab(&block->b_keywtab);
3562 clear_keywtab(&block->b_keywtab_ic); 3588 clear_keywtab(&block->b_keywtab_ic);
3563 3589
4541 */ 4567 */
4542 static char_u * 4568 static char_u *
4543 get_syn_options( 4569 get_syn_options(
4544 char_u *arg, /* next argument to be checked */ 4570 char_u *arg, /* next argument to be checked */
4545 syn_opt_arg_T *opt, /* various things */ 4571 syn_opt_arg_T *opt, /* various things */
4546 int *conceal_char UNUSED) 4572 int *conceal_char UNUSED,
4573 int skip) /* TRUE if skipping over command */
4547 { 4574 {
4548 char_u *gname_start, *gname; 4575 char_u *gname_start, *gname;
4549 int syn_id; 4576 int syn_id;
4550 int len; 4577 int len;
4551 char *p; 4578 char *p;
4624 if (!opt->has_cont_list) 4651 if (!opt->has_cont_list)
4625 { 4652 {
4626 EMSG(_("E395: contains argument not accepted here")); 4653 EMSG(_("E395: contains argument not accepted here"));
4627 return NULL; 4654 return NULL;
4628 } 4655 }
4629 if (get_id_list(&arg, 8, &opt->cont_list) == FAIL) 4656 if (get_id_list(&arg, 8, &opt->cont_list, skip) == FAIL)
4630 return NULL; 4657 return NULL;
4631 } 4658 }
4632 else if (flagtab[fidx].argtype == 2) 4659 else if (flagtab[fidx].argtype == 2)
4633 { 4660 {
4634 if (get_id_list(&arg, 11, &opt->cont_in_list) == FAIL) 4661 if (get_id_list(&arg, 11, &opt->cont_in_list, skip) == FAIL)
4635 return NULL; 4662 return NULL;
4636 } 4663 }
4637 else if (flagtab[fidx].argtype == 3) 4664 else if (flagtab[fidx].argtype == 3)
4638 { 4665 {
4639 if (get_id_list(&arg, 9, &opt->next_list) == FAIL) 4666 if (get_id_list(&arg, 9, &opt->next_list, skip) == FAIL)
4640 return NULL; 4667 return NULL;
4641 } 4668 }
4642 else if (flagtab[fidx].argtype == 11 && arg[5] == '=') 4669 else if (flagtab[fidx].argtype == 11 && arg[5] == '=')
4643 { 4670 {
4644 #ifdef FEAT_MBYTE 4671 #ifdef FEAT_MBYTE
4844 4871
4845 rest = get_group_name(arg, &group_name_end); 4872 rest = get_group_name(arg, &group_name_end);
4846 4873
4847 if (rest != NULL) 4874 if (rest != NULL)
4848 { 4875 {
4849 syn_id = syn_check_group(arg, (int)(group_name_end - arg)); 4876 if (eap->skip)
4877 syn_id = -1;
4878 else
4879 syn_id = syn_check_group(arg, (int)(group_name_end - arg));
4850 if (syn_id != 0) 4880 if (syn_id != 0)
4851 /* allocate a buffer, for removing backslashes in the keyword */ 4881 /* allocate a buffer, for removing backslashes in the keyword */
4852 keyword_copy = alloc((unsigned)STRLEN(rest) + 1); 4882 keyword_copy = alloc((unsigned)STRLEN(rest) + 1);
4853 if (keyword_copy != NULL) 4883 if (keyword_copy != NULL)
4854 { 4884 {
4866 */ 4896 */
4867 cnt = 0; 4897 cnt = 0;
4868 p = keyword_copy; 4898 p = keyword_copy;
4869 for ( ; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) 4899 for ( ; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest))
4870 { 4900 {
4871 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); 4901 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char,
4902 eap->skip);
4872 if (rest == NULL || ends_excmd(*rest)) 4903 if (rest == NULL || ends_excmd(*rest))
4873 break; 4904 break;
4874 /* Copy the keyword, removing backslashes, and add a NUL. */ 4905 /* Copy the keyword, removing backslashes, and add a NUL. */
4875 while (*rest != NUL && !vim_iswhite(*rest)) 4906 while (*rest != NUL && !vim_iswhite(*rest))
4876 { 4907 {
4979 syn_opt_arg.sync_idx = syncing ? &sync_idx : NULL; 5010 syn_opt_arg.sync_idx = syncing ? &sync_idx : NULL;
4980 syn_opt_arg.has_cont_list = TRUE; 5011 syn_opt_arg.has_cont_list = TRUE;
4981 syn_opt_arg.cont_list = NULL; 5012 syn_opt_arg.cont_list = NULL;
4982 syn_opt_arg.cont_in_list = NULL; 5013 syn_opt_arg.cont_in_list = NULL;
4983 syn_opt_arg.next_list = NULL; 5014 syn_opt_arg.next_list = NULL;
4984 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); 5015 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
4985 5016
4986 /* get the pattern. */ 5017 /* get the pattern. */
4987 init_syn_patterns(); 5018 init_syn_patterns();
4988 vim_memset(&item, 0, sizeof(item)); 5019 vim_memset(&item, 0, sizeof(item));
4989 rest = get_syn_pattern(rest, &item); 5020 rest = get_syn_pattern(rest, &item);
4990 if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) 5021 if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL))
4991 syn_opt_arg.flags |= HL_HAS_EOL; 5022 syn_opt_arg.flags |= HL_HAS_EOL;
4992 5023
4993 /* Get options after the pattern */ 5024 /* Get options after the pattern */
4994 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); 5025 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
4995 5026
4996 if (rest != NULL) /* all arguments are valid */ 5027 if (rest != NULL) /* all arguments are valid */
4997 { 5028 {
4998 /* 5029 /*
4999 * Check for trailing command and illegal trailing arguments. 5030 * Check for trailing command and illegal trailing arguments.
5115 * get the options, patterns and matchgroup. 5146 * get the options, patterns and matchgroup.
5116 */ 5147 */
5117 while (rest != NULL && !ends_excmd(*rest)) 5148 while (rest != NULL && !ends_excmd(*rest))
5118 { 5149 {
5119 /* Check for option arguments */ 5150 /* Check for option arguments */
5120 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); 5151 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
5121 if (rest == NULL || ends_excmd(*rest)) 5152 if (rest == NULL || ends_excmd(*rest))
5122 break; 5153 break;
5123 5154
5124 /* must be a pattern or matchgroup then */ 5155 /* must be a pattern or matchgroup then */
5125 key_end = rest; 5156 key_end = rest;
5626 } 5657 }
5627 else 5658 else
5628 break; 5659 break;
5629 5660
5630 clstr_list = NULL; 5661 clstr_list = NULL;
5631 if (get_id_list(&rest, opt_len, &clstr_list) == FAIL) 5662 if (get_id_list(&rest, opt_len, &clstr_list, eap->skip) == FAIL)
5632 { 5663 {
5633 EMSG2(_(e_invarg2), rest); 5664 EMSG2(_(e_invarg2), rest);
5634 break; 5665 break;
5635 } 5666 }
5636 syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list, 5667 if (scl_id >= 0)
5668 syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list,
5637 &clstr_list, list_op); 5669 &clstr_list, list_op);
5638 got_clstr = TRUE; 5670 got_clstr = TRUE;
5639 } 5671 }
5640 5672
5641 if (got_clstr) 5673 if (got_clstr)
5929 */ 5961 */
5930 static int 5962 static int
5931 get_id_list( 5963 get_id_list(
5932 char_u **arg, 5964 char_u **arg,
5933 int keylen, /* length of keyword */ 5965 int keylen, /* length of keyword */
5934 short **list) /* where to store the resulting list, if not 5966 short **list, /* where to store the resulting list, if not
5935 NULL, the list is silently skipped! */ 5967 NULL, the list is silently skipped! */
5968 int skip)
5936 { 5969 {
5937 char_u *p = NULL; 5970 char_u *p = NULL;
5938 char_u *end; 5971 char_u *end;
5939 int round; 5972 int round;
5940 int count; 5973 int count;
6013 id = SYNID_CONTAINED; 6046 id = SYNID_CONTAINED;
6014 id += current_syn_inc_tag; 6047 id += current_syn_inc_tag;
6015 } 6048 }
6016 else if (name[1] == '@') 6049 else if (name[1] == '@')
6017 { 6050 {
6018 id = syn_check_cluster(name + 2, (int)(end - p - 1)); 6051 if (!skip)
6052 id = syn_check_cluster(name + 2, (int)(end - p - 1));
6019 } 6053 }
6020 else 6054 else
6021 { 6055 {
6022 /* 6056 /*
6023 * Handle full group name. 6057 * Handle full group name.