To: vim_dev@googlegroups.com Subject: Patch 7.3.1113 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.3.1113 Problem: New regexp engine: \%'m not supported. Solution: Implement \%'m. Add tests. Files: src/regexp.c, src/regexp_nfa.c, src/testdir/test64.in, src/testdir/test64.ok *** ../vim-7.3.1112/src/regexp.c 2013-06-04 18:28:45.000000000 +0200 --- src/regexp.c 2013-06-04 21:06:13.000000000 +0200 *************** *** 4401,4408 **** break; case RE_MARK: ! /* Compare the mark position to the match position. NOTE: Always ! * uses the current buffer. */ { int mark = OPERAND(scan)[0]; int cmp = OPERAND(scan)[1]; --- 4401,4407 ---- break; case RE_MARK: ! /* Compare the mark position to the match position. */ { int mark = OPERAND(scan)[0]; int cmp = OPERAND(scan)[1]; *************** *** 4410,4416 **** pos = getmark_buf(reg_buf, mark, FALSE); if (pos == NULL /* mark doesn't exist */ ! || pos->lnum <= 0 /* mark isn't set (in curbuf) */ || (pos->lnum == reglnum + reg_firstlnum ? (pos->col == (colnr_T)(reginput - regline) ? (cmp == '<' || cmp == '>') --- 4409,4415 ---- pos = getmark_buf(reg_buf, mark, FALSE); if (pos == NULL /* mark doesn't exist */ ! || pos->lnum <= 0 /* mark isn't set in reg_buf */ || (pos->lnum == reglnum + reg_firstlnum ? (pos->col == (colnr_T)(reginput - regline) ? (cmp == '<' || cmp == '>') *** ../vim-7.3.1112/src/regexp_nfa.c 2013-06-04 18:28:45.000000000 +0200 --- src/regexp_nfa.c 2013-06-04 21:19:11.000000000 +0200 *************** *** 178,183 **** --- 178,186 ---- NFA_VCOL, /* Match cursor virtual column */ NFA_VCOL_GT, /* Match > cursor virtual column */ NFA_VCOL_LT, /* Match < cursor virtual column */ + NFA_MARK, /* Match mark */ + NFA_MARK_GT, /* Match > mark */ + NFA_MARK_LT, /* Match < mark */ NFA_VISUAL, /* Match Visual area */ NFA_FIRST_NL = NFA_ANY + ADD_NL, *************** *** 984,1002 **** { EMIT(n); if (c == 'l') EMIT(cmp == '<' ? NFA_LNUM_LT : ! cmp == '>' ? NFA_LNUM_GT : NFA_LNUM); else if (c == 'c') EMIT(cmp == '<' ? NFA_COL_LT : ! cmp == '>' ? NFA_COL_GT : NFA_COL); else EMIT(cmp == '<' ? NFA_VCOL_LT : ! cmp == '>' ? NFA_VCOL_GT : NFA_VCOL); break; } - else if (c == '\'') - /* TODO: \%'m not supported yet */ - return FAIL; } syntax_error = TRUE; EMSGN(_("E867: (NFA) Unknown operator '\\%%%c'"), --- 987,1013 ---- { EMIT(n); if (c == 'l') + /* \%{n}l \%{n}l */ EMIT(cmp == '<' ? NFA_LNUM_LT : ! cmp == '>' ? NFA_LNUM_GT : NFA_LNUM); else if (c == 'c') + /* \%{n}c \%{n}c */ EMIT(cmp == '<' ? NFA_COL_LT : ! cmp == '>' ? NFA_COL_GT : NFA_COL); else + /* \%{n}v \%{n}v */ EMIT(cmp == '<' ? NFA_VCOL_LT : ! cmp == '>' ? NFA_VCOL_GT : NFA_VCOL); ! break; ! } ! else if (c == '\'' && n == 0) ! { ! /* \%'m \%<'m \%>'m */ ! EMIT(getchr()); ! EMIT(cmp == '<' ? NFA_MARK_LT : ! cmp == '>' ? NFA_MARK_GT : NFA_MARK); break; } } syntax_error = TRUE; EMSGN(_("E867: (NFA) Unknown operator '\\%%%c'"), *************** *** 1931,1936 **** --- 1942,1962 ---- case NFA_BOW: STRCPY(code, "NFA_BOW "); break; case NFA_EOF: STRCPY(code, "NFA_EOF "); break; case NFA_BOF: STRCPY(code, "NFA_BOF "); break; + case NFA_LNUM: STRCPY(code, "NFA_LNUM "); break; + case NFA_LNUM_GT: STRCPY(code, "NFA_LNUM_GT "); break; + case NFA_LNUM_LT: STRCPY(code, "NFA_LNUM_LT "); break; + case NFA_COL: STRCPY(code, "NFA_COL "); break; + case NFA_COL_GT: STRCPY(code, "NFA_COL_GT "); break; + case NFA_COL_LT: STRCPY(code, "NFA_COL_LT "); break; + case NFA_VCOL: STRCPY(code, "NFA_VCOL "); break; + case NFA_VCOL_GT: STRCPY(code, "NFA_VCOL_GT "); break; + case NFA_VCOL_LT: STRCPY(code, "NFA_VCOL_LT "); break; + case NFA_MARK: STRCPY(code, "NFA_MARK "); break; + case NFA_MARK_GT: STRCPY(code, "NFA_MARK_GT "); break; + case NFA_MARK_LT: STRCPY(code, "NFA_MARK_LT "); break; + case NFA_CURSOR: STRCPY(code, "NFA_CURSOR "); break; + case NFA_VISUAL: STRCPY(code, "NFA_VISUAL "); break; + case NFA_STAR: STRCPY(code, "NFA_STAR "); break; case NFA_STAR_NONGREEDY: STRCPY(code, "NFA_STAR_NONGREEDY "); break; case NFA_QUEST: STRCPY(code, "NFA_QUEST"); break; *************** *** 2715,2720 **** --- 2741,2749 ---- case NFA_COL: case NFA_COL_GT: case NFA_COL_LT: + case NFA_MARK: + case NFA_MARK_GT: + case NFA_MARK_LT: if (nfa_calc_size == TRUE) { nstate += 1; *************** *** 2724,2730 **** s = alloc_state(*p, NULL, NULL); if (s == NULL) goto theend; ! s->val = e1.start->c; PUSH(frag(s, list1(&s->out))); break; --- 2753,2759 ---- s = alloc_state(*p, NULL, NULL); if (s == NULL) goto theend; ! s->val = e1.start->c; /* lnum, col or mark name */ PUSH(frag(s, list1(&s->out))); break; *************** *** 4723,4728 **** --- 4752,4781 ---- t->pim, &listidx); break; + case NFA_MARK: + case NFA_MARK_GT: + case NFA_MARK_LT: + { + pos_T *pos = getmark_buf(reg_buf, t->state->val, FALSE); + + /* Compare the mark position to the match position. */ + result = (pos != NULL /* mark doesn't exist */ + && pos->lnum > 0 /* mark isn't set in reg_buf */ + && (pos->lnum == reglnum + reg_firstlnum + ? (pos->col == (colnr_T)(reginput - regline) + ? t->state->c == NFA_MARK + : (pos->col < (colnr_T)(reginput - regline) + ? t->state->c == NFA_MARK_GT + : t->state->c == NFA_MARK_LT)) + : (pos->lnum < reglnum + reg_firstlnum + ? t->state->c == NFA_MARK_GT + : t->state->c == NFA_MARK_LT))); + if (result) + addstate_here(thislist, t->state->out, &t->subs, + t->pim, &listidx); + break; + } + case NFA_CURSOR: result = (reg_win != NULL && (reglnum + reg_firstlnum == reg_win->w_cursor.lnum) *** ../vim-7.3.1112/src/testdir/test64.in 2013-06-04 18:28:45.000000000 +0200 --- src/testdir/test64.in 2013-06-04 21:20:13.000000000 +0200 *************** *** 466,471 **** --- 466,478 ---- :/^Visual/+1,/^Visual/+4yank Gop:" :" + :" Check matching marks + /^Marks: + jfSmsfEme:.-4,.+6s/.\%>'s.*\%<'e../here/ + jfSmsj0fEme:.-4,.+6s/.\%>'s\_.*\%<'e../again/ + :/^Marks:/+1,/^Marks:/+3yank + Gop:" + :" :" Check patterns matching cursor position. :func! Postest() new *************** *** 534,537 **** --- 541,549 ---- oooxofor foroxooo oooxofor foroxooo + Marks: + asdfSasdfsadfEasdf + asdfSas + dfsadfEasdf + Results of test64: *** ../vim-7.3.1112/src/testdir/test64.ok 2013-06-04 18:28:45.000000000 +0200 --- src/testdir/test64.ok 2013-06-04 20:55:08.000000000 +0200 *************** *** 862,867 **** --- 862,871 ---- AndAxAnd AndAxAnd oooxOfOr fOrOxooo oooxOfOr fOrOxooo + + asdfhereasdf + asdfagainasdf + -0- ffo bob *** ../vim-7.3.1112/src/version.c 2013-06-04 18:28:45.000000000 +0200 --- src/version.c 2013-06-04 21:25:20.000000000 +0200 *************** *** 730,731 **** --- 730,733 ---- { /* Add new patch number below this line */ + /**/ + 1113, /**/ -- hundred-and-one symptoms of being an internet addict: 89. In addition to your e-mail address being on your business cards you even have your own domain. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///