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

24276Re: Regex problem in syntax description [patch]

Expand Messages
  • Bram Moolenaar
    Sep 3 4:55 AM
    • 0 Attachment
      Preben Peppe Guldberg wrote:

      > Thus wrote Corinna Vinschen (vinschen@...) on [010901]:
      >
      > > The expressions I'm using to describe entries are the following:
      > >
      > > Standard entries:
      > >
      > > syn match changelogFiles "^\s\+[+*]\s\+\_.\{-}:\s"
      > >
      > > Followup lines:
      > >
      > > syn match changeLogFuncs contained "^\s\+[([]\_.\{-}:\s"
      > >
      > > Surprise, the first example is only highlighted in the first line,
      > > while the second example is highlighted correctly up to the colon
      > > in line 4.
      >
      > It does appear that way...
      >
      > Actually, the "match" statements must be within one line (":help
      > syn-define"). So changelogFiles matches the first line, and in the
      > second example changeLogFuncs matches each of the following line
      > (three matches).

      Although it is true that originally a "match" would only work within one
      line, that comes from the time that a regexp pattern could not span more
      than one line. It would now be possible to let the "match" item span
      more than one line. That is in fact a good way to find specific items.
      Using a region quickly makes it more complicated.

      I made a change recently to avoid that a match with a contained item
      would continue when the contained items ends. But this was done a bit
      drastically, it also truncates any match that spans more than one line.
      It seems it is quite easy to avoid this and make the example above work.

      Please try this patch. It does work for the example above, but this
      code is very complicated, it's hard to predict if there now is another
      situation where it fails.

      *** ../vim-6.0au/src/syntax.c Sun Sep 2 19:29:02 2001
      --- src/syntax.c Mon Sep 3 12:36:47 2001
      ***************
      *** 940,951 ****

      if (startofline)
      {
      ! /* A match carried over from a previous line must have a contained
      ! * region. The match ends as soon as the region ends. */
      for (i = 0; i < current_state.ga_len; ++i)
      {
      cur_si = &CUR_STATE(i);
      ! if ((SYN_ITEMS(syn_buf)[cur_si->si_idx]).sp_type == SPTYPE_MATCH)
      {
      cur_si->si_flags |= HL_MATCHCONT;
      cur_si->si_m_endpos.lnum = 0;
      --- 940,952 ----

      if (startofline)
      {
      ! /* Check for a match carried over from a previous line with a
      ! * contained region. The match ends as soon as the region ends. */
      for (i = 0; i < current_state.ga_len; ++i)
      {
      cur_si = &CUR_STATE(i);
      ! if ((SYN_ITEMS(syn_buf)[cur_si->si_idx]).sp_type == SPTYPE_MATCH
      ! && cur_si->si_m_endpos.lnum < current_lnum)
      {
      cur_si->si_flags |= HL_MATCHCONT;
      cur_si->si_m_endpos.lnum = 0;

      --
      Life is a gift, living is an art. (Bram Moolenaar)

      /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
      ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim )))
      \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
    • Show all 6 messages in this topic