Loading ...
Sorry, an error occurred while loading the content.

Re: another syntax issue

Expand Messages
  • Scott Bigham
    ... [...] ... Oops. This is one I hadn t anticipated. :-} xml.vim :syn include s dtd.vim itself, and c.vim is ending up at the same depth in the include
    Message 1 of 2 , May 21, 2000
    • 0 Attachment
      On May 19, 2000, Stephen P. Wall wrote:

      > > From: Johannes Zellner <johannes@...>

      > > source $VIMRUNTIME/syntax/xml.vim
      > >
      > > syntax include @cCode $VIMRUNTIME/syntax/c.vim"
      > > syn region cRegion start=§<c-code>§ end=§</c-code>§ contains=@cCode
      [...]
      > > The c.vim contains statements like contains=ALLBUT which apparently
      > > allow also xml (top level syntax) items to be contained, which is
      > > not what I want.

      > This appears to be a bug. Looking at the source for syntax processing,
      > it looks like it's attempting to keep track of include files and only
      > allow items from the current file to apply to ALL and ALLBUT. Could
      > someone who is more familiar with that code take a look?

      Oops. This is one I hadn't anticipated. :-} xml.vim :syn include's
      dtd.vim itself, and c.vim is ending up at the same "depth" in the
      include stack when you include it manually (since they're both happening
      at the xml.vim "level"), which means that the ALLBUT-handling code can't
      tell them apart. It's DTD syntax highlighting that's leaking into
      cRegion, not XML syntax highlighting.

      I guess the appropriate thing to do here is simply to give each
      :syn-include'd file a unique "tag" instead of trying to track its depth.
      Attached is a patch that should (crosses fingers) fix the problem.

      -sbigham

      --- src/syntax.c.orig Sun May 21 17:45:19 2000
      +++ src/syntax.c Sun May 21 17:46:27 2000
      @@ -125,7 +125,7 @@
      char sp_type; /* see SPTYPE_ defines below */
      char sp_syncing; /* this item used for syncing */
      short sp_flags; /* see HL_ defines below */
      - int sp_syn_inc_lvl; /* ":syn include" level of item */
      + int sp_syn_inc_tag; /* ":syn include" unique tag */
      short sp_syn_id; /* highlight group ID of item */
      short sp_syn_match_id; /* highlight group ID of pattern */
      char_u *sp_pattern; /* regexp to match, pattern */
      @@ -236,11 +236,12 @@
      static char_u **syn_cmdlinep;

      /*
      - * Another Annoying Hack(TM): To prevent rules from higher or lower in the
      - * ":syn include" stack from from leaking into ALLBUT lists, we track the
      - * current stack "level".
      + * Another Annoying Hack(TM): To prevent rules from other ":syn include"'d
      + * files from from leaking into ALLBUT lists, we assign a unique ID to the
      + * rules in each ":syn include"'d file.
      */
      -static int current_syn_inc_lvl = 0;
      +static int current_syn_inc_tag = 0;
      +static int running_syn_inc_tag = 0;

      /*
      * To reduce the time spent in keepend(), remember at which level in the state
      @@ -1444,14 +1445,14 @@
      && ((current_next_list != 0
      && in_id_list(current_next_list,
      spp->sp_syn_id,
      - spp->sp_syn_inc_lvl, 0))
      + spp->sp_syn_inc_tag, 0))
      || (current_next_list == 0
      && ((cur_si == NULL
      && !(spp->sp_flags & HL_CONTAINED))
      || (cur_si != NULL
      && in_id_list(cur_si->si_cont_list,
      spp->sp_syn_id,
      - spp->sp_syn_inc_lvl,
      + spp->sp_syn_inc_tag,
      spp->sp_flags & HL_CONTAINED))))))
      {
      int lc_col;
      @@ -2314,13 +2315,13 @@
      if ( STRCMP(keyword, ktab->keyword) == 0
      && ( (current_next_list != 0
      && in_id_list(current_next_list, ktab->syn_id,
      - ktab->syn_inc_lvl, 0))
      + ktab->syn_inc_tag, 0))
      || (current_next_list == 0
      && ((cur_si == NULL && !(ktab->flags & HL_CONTAINED))
      || (cur_si != NULL
      && in_id_list(cur_si->si_cont_list,
      ktab->syn_id,
      - ktab->syn_inc_lvl,
      + ktab->syn_inc_tag,
      ktab->flags & HL_CONTAINED))))))
      {
      *endcol = startcol + len - 1;
      @@ -3170,7 +3171,7 @@
      return;
      STRCPY(ktab->keyword, name);
      ktab->syn_id = id;
      - ktab->syn_inc_lvl = current_syn_inc_lvl;
      + ktab->syn_inc_tag = current_syn_inc_tag;
      ktab->flags = flags;
      ktab->next_list = copy_id_list(next_list);

      @@ -3395,6 +3396,7 @@
      char_u *rest;
      char_u *errormsg = NULL;
      int prev_toplvl_grp;
      + int prev_syn_inc_tag;

      eap->nextcmd = find_nextcmd(arg);
      if (eap->skip)
      @@ -3429,15 +3431,16 @@

      /*
      * Save and restore the existing top-level grouplist id and ":syn
      - * include" level around the actual inclusion.
      + * include" tag around the actual inclusion.
      */
      - current_syn_inc_lvl++;
      + prev_syn_inc_tag = current_syn_inc_tag;
      + current_syn_inc_tag = ++running_syn_inc_tag;
      prev_toplvl_grp = curbuf->b_syn_topgrp;
      curbuf->b_syn_topgrp = sgl_id;
      if (do_source(eap->arg, FALSE, FALSE) == FAIL)
      emsg2(e_notopen, eap->arg);
      curbuf->b_syn_topgrp = prev_toplvl_grp;
      - current_syn_inc_lvl--;
      + current_syn_inc_tag = prev_syn_inc_tag;
      }

      /*
      @@ -3586,7 +3589,7 @@
      SYN_ITEMS(curbuf)[idx].sp_syncing = syncing;
      SYN_ITEMS(curbuf)[idx].sp_type = SPTYPE_MATCH;
      SYN_ITEMS(curbuf)[idx].sp_syn_id = syn_id;
      - SYN_ITEMS(curbuf)[idx].sp_syn_inc_lvl = current_syn_inc_lvl;
      + SYN_ITEMS(curbuf)[idx].sp_syn_inc_tag = current_syn_inc_tag;
      SYN_ITEMS(curbuf)[idx].sp_flags = flags;
      SYN_ITEMS(curbuf)[idx].sp_sync_idx = sync_idx;
      SYN_ITEMS(curbuf)[idx].sp_cont_list = cont_list;
      @@ -3819,7 +3822,7 @@
      (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END;
      SYN_ITEMS(curbuf)[idx].sp_flags |= flags;
      SYN_ITEMS(curbuf)[idx].sp_syn_id = syn_id;
      - SYN_ITEMS(curbuf)[idx].sp_syn_inc_lvl = current_syn_inc_lvl;
      + SYN_ITEMS(curbuf)[idx].sp_syn_inc_tag = current_syn_inc_tag;
      SYN_ITEMS(curbuf)[idx].sp_syn_match_id =
      ppp->pp_matchgroup_id;
      if (item == ITEM_START)
      @@ -4455,7 +4458,7 @@
      short **list; /* where to store the resulting list, if not
      NULL, the list is silently skipped! */
      {
      - char_u *p;
      + char_u *p = *arg;
      char_u *end;
      int round;
      int count;
      @@ -4525,7 +4528,7 @@
      vim_free(name);
      break;
      }
      - id = CONTAINS_ALLBUT + current_syn_inc_lvl;
      + id = CONTAINS_ALLBUT + current_syn_inc_tag;
      }
      else if (name[1] == '@')
      {
      @@ -4662,10 +4665,10 @@
      * Check if "id" is in the "contains" or "nextgroup" list of pattern "idx".
      */
      static int
      -in_id_list(list, id, inclvl, contained)
      +in_id_list(list, id, inctag, contained)
      short *list; /* id list */
      int id; /* group id */
      - int inclvl; /* ":syn include" level of group id */
      + int inctag; /* ":syn include" level of group id */
      int contained; /* group id is contained */
      {
      int retval;
      @@ -4686,7 +4689,7 @@
      */
      if (*list >= CONTAINS_ALLBUT && *list < CLUSTER_ID_MIN)
      {
      - if (*list - CONTAINS_ALLBUT != inclvl)
      + if (*list - CONTAINS_ALLBUT != inctag)
      return FALSE;
      ++list;
      retval = FALSE;
      @@ -4705,7 +4708,7 @@
      if (scl_id >= 0)
      {
      scl_list = SYN_CLSTR(syn_buf)[scl_id].scl_list;
      - if (scl_list != NULL && in_id_list(scl_list, id, inclvl, contained))
      + if (scl_list != NULL && in_id_list(scl_list, id, inctag, contained))
      return retval;
      }
      }
      --- src/structs.h.orig Thu Dec 2 11:43:04 1999
      +++ src/structs.h Sun May 21 17:33:19 2000
      @@ -323,7 +323,7 @@
      struct keyentry
      {
      struct keyentry *next; /* next keyword in the hash list */
      - int syn_inc_lvl; /* ":syn include" level for this match */
      + int syn_inc_tag; /* ":syn include" tag for this match */
      short syn_id; /* syntax ID for this match (if non-zero) */
      short *next_list; /* ID list for next match (if non-zero) */
      short flags; /* see syntax.c */
    Your message has been successfully submitted and would be delivered to recipients shortly.