home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.3 / 7.3.1139 < prev    next >
Encoding:
Internet Message Format  |  2013-06-06  |  14.5 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.1139
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.3.1139
  11. Problem:    New regexp engine: negated flag is hardly used.
  12. Solution:   Add separate _NEG states, remove negated flag.
  13. Files:        src/regexp_nfa.c, src/regexp.h
  14.  
  15.  
  16. *** ../vim-7.3.1138/src/regexp_nfa.c    2013-06-07 14:59:14.000000000 +0200
  17. --- src/regexp_nfa.c    2013-06-07 16:31:29.000000000 +0200
  18. ***************
  19. *** 64,72 ****
  20. --- 64,75 ----
  21.       NFA_NOPEN,                /* Start of subexpression marked with \%( */
  22.       NFA_NCLOSE,                /* End of subexpr. marked with \%( ... \) */
  23.       NFA_START_INVISIBLE,
  24. +     NFA_START_INVISIBLE_NEG,
  25.       NFA_START_INVISIBLE_BEFORE,
  26. +     NFA_START_INVISIBLE_BEFORE_NEG,
  27.       NFA_START_PATTERN,
  28.       NFA_END_INVISIBLE,
  29. +     NFA_END_INVISIBLE_NEG,
  30.       NFA_END_PATTERN,
  31.       NFA_COMPOSING,            /* Next nodes in NFA are part of the
  32.                          composing multibyte char */
  33. ***************
  34. *** 481,487 ****
  35.           }
  36.   
  37.           default:
  38. !         if (p->c > 0 && !p->negated)
  39.               return p->c; /* yes! */
  40.           return 0;
  41.       }
  42. --- 484,490 ----
  43.           }
  44.   
  45.           default:
  46. !         if (p->c > 0)
  47.               return p->c; /* yes! */
  48.           return 0;
  49.       }
  50. ***************
  51. *** 1991,2000 ****
  52. --- 1994,2008 ----
  53.       case NFA_NOPEN:            STRCPY(code, "NFA_NOPEN"); break;
  54.       case NFA_NCLOSE:        STRCPY(code, "NFA_NCLOSE"); break;
  55.       case NFA_START_INVISIBLE:   STRCPY(code, "NFA_START_INVISIBLE"); break;
  56. +     case NFA_START_INVISIBLE_NEG:
  57. +                    STRCPY(code, "NFA_START_INVISIBLE_NEG"); break;
  58.       case NFA_START_INVISIBLE_BEFORE:
  59.                   STRCPY(code, "NFA_START_INVISIBLE_BEFORE"); break;
  60. +     case NFA_START_INVISIBLE_BEFORE_NEG:
  61. +             STRCPY(code, "NFA_START_INVISIBLE_BEFORE_NEG"); break;
  62.       case NFA_START_PATTERN:   STRCPY(code, "NFA_START_PATTERN"); break;
  63.       case NFA_END_INVISIBLE:        STRCPY(code, "NFA_END_INVISIBLE"); break;
  64. +     case NFA_END_INVISIBLE_NEG: STRCPY(code, "NFA_END_INVISIBLE_NEG"); break;
  65.       case NFA_END_PATTERN:        STRCPY(code, "NFA_END_PATTERN"); break;
  66.   
  67.       case NFA_COMPOSING:        STRCPY(code, "NFA_COMPOSING"); break;
  68. ***************
  69. *** 2227,2234 ****
  70.       fprintf(debugf, " %s", p);
  71.   
  72.       nfa_set_code(state->c);
  73. !     fprintf(debugf, "%s%s (%d) (id=%d) val=%d\n",
  74. !          state->negated ? "NOT " : "",
  75.            code,
  76.            state->c,
  77.            abs(state->id),
  78. --- 2235,2241 ----
  79.       fprintf(debugf, " %s", p);
  80.   
  81.       nfa_set_code(state->c);
  82. !     fprintf(debugf, "%s (%d) (id=%d) val=%d\n",
  83.            code,
  84.            state->c,
  85.            abs(state->id),
  86. ***************
  87. *** 2330,2336 ****
  88.       s->id   = istate;
  89.       s->lastlist[0] = 0;
  90.       s->lastlist[1] = 0;
  91. -     s->negated = FALSE;
  92.   
  93.       return s;
  94.   }
  95. --- 2337,2342 ----
  96. ***************
  97. *** 2741,2763 ****
  98.       case NFA_PREV_ATOM_JUST_BEFORE_NEG:
  99.       case NFA_PREV_ATOM_LIKE_PATTERN:
  100.         {
  101. -         int neg = (*p == NFA_PREV_ATOM_NO_WIDTH_NEG
  102. -                       || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG);
  103.           int before = (*p == NFA_PREV_ATOM_JUST_BEFORE
  104.                         || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG);
  105.           int pattern = (*p == NFA_PREV_ATOM_LIKE_PATTERN);
  106. !         int start_state = NFA_START_INVISIBLE;
  107. !         int end_state = NFA_END_INVISIBLE;
  108.           int n = 0;
  109.           nfa_state_T *zend;
  110.           nfa_state_T *skip;
  111.   
  112. !         if (before)
  113. !         start_state = NFA_START_INVISIBLE_BEFORE;
  114. !         else if (pattern)
  115.           {
  116. !         start_state = NFA_START_PATTERN;
  117. !         end_state = NFA_END_PATTERN;
  118.           }
  119.   
  120.           if (before)
  121. --- 2747,2783 ----
  122.       case NFA_PREV_ATOM_JUST_BEFORE_NEG:
  123.       case NFA_PREV_ATOM_LIKE_PATTERN:
  124.         {
  125.           int before = (*p == NFA_PREV_ATOM_JUST_BEFORE
  126.                         || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG);
  127.           int pattern = (*p == NFA_PREV_ATOM_LIKE_PATTERN);
  128. !         int start_state;
  129. !         int end_state;
  130.           int n = 0;
  131.           nfa_state_T *zend;
  132.           nfa_state_T *skip;
  133.   
  134. !         switch (*p)
  135.           {
  136. !         case NFA_PREV_ATOM_NO_WIDTH:
  137. !             start_state = NFA_START_INVISIBLE;
  138. !             end_state = NFA_END_INVISIBLE;
  139. !             break;
  140. !         case NFA_PREV_ATOM_NO_WIDTH_NEG:
  141. !             start_state = NFA_START_INVISIBLE_NEG;
  142. !             end_state = NFA_END_INVISIBLE_NEG;
  143. !             break;
  144. !         case NFA_PREV_ATOM_JUST_BEFORE:
  145. !             start_state = NFA_START_INVISIBLE_BEFORE;
  146. !             end_state = NFA_END_INVISIBLE;
  147. !             break;
  148. !         case NFA_PREV_ATOM_JUST_BEFORE_NEG:
  149. !             start_state = NFA_START_INVISIBLE_BEFORE_NEG;
  150. !             end_state = NFA_END_INVISIBLE_NEG;
  151. !             break;
  152. !         case NFA_PREV_ATOM_LIKE_PATTERN:
  153. !             start_state = NFA_START_PATTERN;
  154. !             end_state = NFA_END_PATTERN;
  155. !             break;
  156.           }
  157.   
  158.           if (before)
  159. ***************
  160. *** 2783,2793 ****
  161.           s = alloc_state(start_state, e.start, s1);
  162.           if (s == NULL)
  163.           goto theend;
  164. -         if (neg)
  165. -         {
  166. -         s->negated = TRUE;
  167. -         s1->negated = TRUE;
  168. -         }
  169.           if (before)
  170.           s->val = n; /* store the count */
  171.           if (pattern)
  172. --- 2803,2808 ----
  173. ***************
  174. *** 3009,3015 ****
  175.       matchstate = &state_ptr[istate++]; /* the match state */
  176.       matchstate->c = NFA_MATCH;
  177.       matchstate->out = matchstate->out1 = NULL;
  178. -     matchstate->negated = FALSE;
  179.       matchstate->id = 0;
  180.   
  181.       patch(e.out, matchstate);
  182. --- 3024,3029 ----
  183. ***************
  184. *** 3772,3778 ****
  185.           return OK;
  186.           break;
  187.       case NFA_CLASS_SPACE:
  188. !         if ((c >=9 && c <= 13) || (c == ' '))
  189.           return OK;
  190.           break;
  191.       case NFA_CLASS_UPPER:
  192. --- 3786,3792 ----
  193.           return OK;
  194.           break;
  195.       case NFA_CLASS_SPACE:
  196. !         if ((c >= 9 && c <= 13) || (c == ' '))
  197.           return OK;
  198.           break;
  199.       case NFA_CLASS_UPPER:
  200. ***************
  201. *** 3971,3977 ****
  202.       int        result;
  203.       int        need_restore = FALSE;
  204.   
  205. !     if (state->c == NFA_START_INVISIBLE_BEFORE)
  206.       {
  207.       /* The recursive match must end at the current position. */
  208.       endposp = &endpos;
  209. --- 3985,3992 ----
  210.       int        result;
  211.       int        need_restore = FALSE;
  212.   
  213. !     if (state->c == NFA_START_INVISIBLE_BEFORE
  214. !         || state->c == NFA_START_INVISIBLE_BEFORE_NEG)
  215.       {
  216.       /* The recursive match must end at the current position. */
  217.       endposp = &endpos;
  218. ***************
  219. *** 4452,4457 ****
  220. --- 4467,4473 ----
  221.             }
  222.   
  223.           case NFA_END_INVISIBLE:
  224. +         case NFA_END_INVISIBLE_NEG:
  225.           case NFA_END_PATTERN:
  226.           /*
  227.            * This is only encountered after a NFA_START_INVISIBLE or
  228. ***************
  229. *** 4489,4495 ****
  230.               break;
  231.   
  232.           /* do not set submatches for \@! */
  233. !         if (!t->state->negated)
  234.           {
  235.               copy_sub(&m->norm, &t->subs.norm);
  236.   #ifdef FEAT_SYN_HL
  237. --- 4505,4511 ----
  238.               break;
  239.   
  240.           /* do not set submatches for \@! */
  241. !         if (t->state->c != NFA_END_INVISIBLE_NEG)
  242.           {
  243.               copy_sub(&m->norm, &t->subs.norm);
  244.   #ifdef FEAT_SYN_HL
  245. ***************
  246. *** 4505,4511 ****
  247. --- 4521,4529 ----
  248.           break;
  249.   
  250.           case NFA_START_INVISIBLE:
  251. +         case NFA_START_INVISIBLE_NEG:
  252.           case NFA_START_INVISIBLE_BEFORE:
  253. +         case NFA_START_INVISIBLE_BEFORE_NEG:
  254.           {
  255.               nfa_pim_T *pim;
  256.               int cout = t->state->out1->out->c;
  257. ***************
  258. *** 4524,4529 ****
  259. --- 4542,4548 ----
  260.                   || cout == NFA_NCLOSE
  261.                   || t->pim != NULL
  262.                   || (t->state->c != NFA_START_INVISIBLE_BEFORE
  263. +                     && t->state->c != NFA_START_INVISIBLE_BEFORE_NEG
  264.                   && failure_chance(t->state->out1->out, 0)
  265.                         < failure_chance(t->state->out, 0)))
  266.               {
  267. ***************
  268. *** 4534,4541 ****
  269.               result = recursive_regmatch(t->state, prog,
  270.                                  submatch, m, &listids);
  271.   
  272. !             /* for \@! it is a match when result is FALSE */
  273. !             if (result != t->state->negated)
  274.               {
  275.                   /* Copy submatch info from the recursive call */
  276.                   copy_sub_off(&t->subs.norm, &m->norm);
  277. --- 4553,4563 ----
  278.               result = recursive_regmatch(t->state, prog,
  279.                                  submatch, m, &listids);
  280.   
  281. !             /* for \@! and \@<! it is a match when the result is
  282. !              * FALSE */
  283. !             if (result != (t->state->c == NFA_START_INVISIBLE_NEG
  284. !                         || t->state->c
  285. !                        == NFA_START_INVISIBLE_BEFORE_NEG))
  286.               {
  287.                   /* Copy submatch info from the recursive call */
  288.                   copy_sub_off(&t->subs.norm, &m->norm);
  289. ***************
  290. *** 4646,4656 ****
  291.           break;
  292.   
  293.           case NFA_BOW:
  294. !         {
  295. !         int bow = TRUE;
  296.   
  297.           if (curc == NUL)
  298. !             bow = FALSE;
  299.   #ifdef FEAT_MBYTE
  300.           else if (has_mbyte)
  301.           {
  302. --- 4668,4677 ----
  303.           break;
  304.   
  305.           case NFA_BOW:
  306. !         result = TRUE;
  307.   
  308.           if (curc == NUL)
  309. !             result = FALSE;
  310.   #ifdef FEAT_MBYTE
  311.           else if (has_mbyte)
  312.           {
  313. ***************
  314. *** 4659,4685 ****
  315.               /* Get class of current and previous char (if it exists). */
  316.               this_class = mb_get_class_buf(reginput, reg_buf);
  317.               if (this_class <= 1)
  318. !             bow = FALSE;
  319.               else if (reg_prev_class() == this_class)
  320. !             bow = FALSE;
  321.           }
  322.   #endif
  323.           else if (!vim_iswordc_buf(curc, reg_buf)
  324.                  || (reginput > regline
  325.                      && vim_iswordc_buf(reginput[-1], reg_buf)))
  326. !             bow = FALSE;
  327. !         if (bow)
  328.               addstate_here(thislist, t->state->out, &t->subs,
  329.                                   t->pim, &listidx);
  330.           break;
  331. -         }
  332.   
  333.           case NFA_EOW:
  334. !         {
  335. !         int eow = TRUE;
  336.           if (reginput == regline)
  337. !             eow = FALSE;
  338.   #ifdef FEAT_MBYTE
  339.           else if (has_mbyte)
  340.           {
  341. --- 4680,4703 ----
  342.               /* Get class of current and previous char (if it exists). */
  343.               this_class = mb_get_class_buf(reginput, reg_buf);
  344.               if (this_class <= 1)
  345. !             result = FALSE;
  346.               else if (reg_prev_class() == this_class)
  347. !             result = FALSE;
  348.           }
  349.   #endif
  350.           else if (!vim_iswordc_buf(curc, reg_buf)
  351.                  || (reginput > regline
  352.                      && vim_iswordc_buf(reginput[-1], reg_buf)))
  353. !             result = FALSE;
  354. !         if (result)
  355.               addstate_here(thislist, t->state->out, &t->subs,
  356.                                   t->pim, &listidx);
  357.           break;
  358.   
  359.           case NFA_EOW:
  360. !         result = TRUE;
  361.           if (reginput == regline)
  362. !             result = FALSE;
  363.   #ifdef FEAT_MBYTE
  364.           else if (has_mbyte)
  365.           {
  366. ***************
  367. *** 4690,4707 ****
  368.               prev_class = reg_prev_class();
  369.               if (this_class == prev_class
  370.                       || prev_class == 0 || prev_class == 1)
  371. !             eow = FALSE;
  372.           }
  373.   #endif
  374.           else if (!vim_iswordc_buf(reginput[-1], reg_buf)
  375.               || (reginput[0] != NUL
  376.                          && vim_iswordc_buf(curc, reg_buf)))
  377. !             eow = FALSE;
  378. !         if (eow)
  379.               addstate_here(thislist, t->state->out, &t->subs,
  380.                                   t->pim, &listidx);
  381.           break;
  382. -         }
  383.   
  384.           case NFA_BOF:
  385.           if (reglnum == 0 && reginput == regline
  386. --- 4708,4724 ----
  387.               prev_class = reg_prev_class();
  388.               if (this_class == prev_class
  389.                       || prev_class == 0 || prev_class == 1)
  390. !             result = FALSE;
  391.           }
  392.   #endif
  393.           else if (!vim_iswordc_buf(reginput[-1], reg_buf)
  394.               || (reginput[0] != NUL
  395.                          && vim_iswordc_buf(curc, reg_buf)))
  396. !             result = FALSE;
  397. !         if (result)
  398.               addstate_here(thislist, t->state->out, &t->subs,
  399.                                   t->pim, &listidx);
  400.           break;
  401.   
  402.           case NFA_BOF:
  403.           if (reglnum == 0 && reginput == regline
  404. ***************
  405. *** 4740,4746 ****
  406.           {
  407.               /* If \Z was present, then ignore composing characters.
  408.                * When ignoring the base character this always matches. */
  409. -             /* TODO: How about negated? */
  410.               if (len == 0 && sta->c != curc)
  411.               result = FAIL;
  412.               else
  413. --- 4757,4762 ----
  414. ***************
  415. *** 4813,4838 ****
  416.           }
  417.           break;
  418.   
  419. -         case NFA_CLASS_ALNUM:
  420. -         case NFA_CLASS_ALPHA:
  421. -         case NFA_CLASS_BLANK:
  422. -         case NFA_CLASS_CNTRL:
  423. -         case NFA_CLASS_DIGIT:
  424. -         case NFA_CLASS_GRAPH:
  425. -         case NFA_CLASS_LOWER:
  426. -         case NFA_CLASS_PRINT:
  427. -         case NFA_CLASS_PUNCT:
  428. -         case NFA_CLASS_SPACE:
  429. -         case NFA_CLASS_UPPER:
  430. -         case NFA_CLASS_XDIGIT:
  431. -         case NFA_CLASS_TAB:
  432. -         case NFA_CLASS_RETURN:
  433. -         case NFA_CLASS_BACKSPACE:
  434. -         case NFA_CLASS_ESCAPE:
  435. -         result = check_char_class(t->state->c, curc);
  436. -         ADD_STATE_IF_MATCH(t->state);
  437. -         break;
  438.           case NFA_START_COLL:
  439.           case NFA_START_NEG_COLL:
  440.             {
  441. --- 4829,4834 ----
  442. ***************
  443. *** 5212,5221 ****
  444.           int c = t->state->c;
  445.   
  446.           /* TODO: put this in #ifdef later */
  447. !         if (c < -256)
  448.               EMSGN("INTERNAL: Negative state char: %ld", c);
  449. -         if (is_Magic(c))
  450. -             c = un_Magic(c);
  451.           result = (c == curc);
  452.   
  453.           if (!result && ireg_ic)
  454. --- 5208,5215 ----
  455.           int c = t->state->c;
  456.   
  457.           /* TODO: put this in #ifdef later */
  458. !         if (c < 0)
  459.               EMSGN("INTERNAL: Negative state char: %ld", c);
  460.           result = (c == curc);
  461.   
  462.           if (!result && ireg_ic)
  463. ***************
  464. *** 5252,5259 ****
  465.                            prog, submatch, m, &listids);
  466.               t->pim->result = result ? NFA_PIM_MATCH
  467.                                   : NFA_PIM_NOMATCH;
  468. !             /* for \@! it is a match when result is FALSE */
  469. !             if (result != t->pim->state->negated)
  470.               {
  471.                   /* Copy submatch info from the recursive call */
  472.                   copy_sub_off(&t->pim->subs.norm, &m->norm);
  473. --- 5246,5257 ----
  474.                            prog, submatch, m, &listids);
  475.               t->pim->result = result ? NFA_PIM_MATCH
  476.                                   : NFA_PIM_NOMATCH;
  477. !             /* for \@! and \@<! it is a match when the result is
  478. !              * FALSE */
  479. !             if (result != (t->pim->state->c
  480. !                             == NFA_START_INVISIBLE_NEG
  481. !                         || t->pim->state->c
  482. !                        == NFA_START_INVISIBLE_BEFORE_NEG))
  483.               {
  484.                   /* Copy submatch info from the recursive call */
  485.                   copy_sub_off(&t->pim->subs.norm, &m->norm);
  486. ***************
  487. *** 5274,5281 ****
  488.   #endif
  489.               }
  490.   
  491. !             /* for \@! it is a match when result is FALSE */
  492. !             if (result != t->pim->state->negated)
  493.               {
  494.               /* Copy submatch info from the recursive call */
  495.               copy_sub_off(&t->subs.norm, &t->pim->subs.norm);
  496. --- 5272,5281 ----
  497.   #endif
  498.               }
  499.   
  500. !             /* for \@! and \@<! it is a match when result is FALSE */
  501. !             if (result != (t->pim->state->c == NFA_START_INVISIBLE_NEG
  502. !                     || t->pim->state->c
  503. !                        == NFA_START_INVISIBLE_BEFORE_NEG))
  504.               {
  505.               /* Copy submatch info from the recursive call */
  506.               copy_sub_off(&t->subs.norm, &t->pim->subs.norm);
  507. *** ../vim-7.3.1138/src/regexp.h    2013-06-06 18:46:00.000000000 +0200
  508. --- src/regexp.h    2013-06-07 16:11:12.000000000 +0200
  509. ***************
  510. *** 73,79 ****
  511.       nfa_state_T        *out1;
  512.       int            id;
  513.       int            lastlist[2]; /* 0: normal, 1: recursive */
  514. -     int            negated;
  515.       int            val;
  516.   };
  517.   
  518. --- 73,78 ----
  519. *** ../vim-7.3.1138/src/version.c    2013-06-07 14:59:14.000000000 +0200
  520. --- src/version.c    2013-06-07 16:11:59.000000000 +0200
  521. ***************
  522. *** 730,731 ****
  523. --- 730,733 ----
  524.   {   /* Add new patch number below this line */
  525. + /**/
  526. +     1139,
  527.   /**/
  528.  
  529. -- 
  530. Common sense is what tells you that the world is flat.
  531.  
  532.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  533. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  534. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  535.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  536.