1

I am attempting to revive the cocoa.vim script.

Error detected while processing function objc#man#ShowDoc:
line   32:
E888: (NFA regexp) cannot repeat 

Line 32 of the function objc#man#ShowDoc is:

let attrs = split(matchstr(line, '^ \zs*\S*'), '/')[:2]

First, I don't understand the error. What's repeating? What can't it repeat? Searching for that error online brings me to where it's defined in vim's source code, but it's obtuse enough that I don't understand it.

Second, I find it strange that this regexp used to work, but now it doesn't with newer vim.

I have very little vimscript experience and not much regexp experience. Guidance on where to look from those who do would be much appreciated. Here is the whole src if you're interested.

Xander Dunn
  • 2,349
  • 2
  • 20
  • 32
  • 1
    `\z` usually means "end of string" in regex (not sure about this flavor). So let's assume that it means the same in this context then you're basically asserting to "match optional `s` and optional non-whitespaces after end of string". Which doesn't make sense. I'm guessing that you either need to replace `\z` with `$` or remove `s*\S*`. – HamZa Dec 24 '14 at 01:27
  • Looking closer it might also seem like a typo. So you might try `^ \s*\S*` – HamZa Dec 24 '14 at 01:37
  • @HamZa: `\z` seems to have different meaning in Vim regex. It is a beast of its own. – nhahtdh Dec 24 '14 at 02:27
  • What is the code intended to do? – nhahtdh Dec 24 '14 at 02:30
  • 2
    @HamZa `\zs` is the atom. `:h \zs`. Basically it just marks that this is the start of the regex. Most likely the star isn't supposed to be after it. (As I don't see it doing anything.) – FDinoff Dec 24 '14 at 04:16
  • @FDinoff thanks a lot for this. I had no idea vim's :h would also work for regexp atoms. I'll have to use that in the future! – Xander Dunn Dec 24 '14 at 05:14
  • @FDinoff Ah I get it. It seems like the [escape sequence `\K`](http://stackoverflow.com/questions/13542950/support-of-k-in-regex) in perl-like regexes. – HamZa Dec 25 '14 at 23:20

1 Answers1

4

The problem is that \zs is the start of match regex atom. Repeating it zero or more times doesn't make any sense since you can always start the match at the point the \zs is.

This error was introduced vim patch 7.4.421 to stop a crash in vim when the NFA engine tried to generate the regex. Most likely the star shouldn't even be there. The old regex engine allowed it however I don't believe it did anything meaningful.

You should be able to fix it by just removing the star.

let attrs = split(matchstr(line, '^ \zs\S*'), '/')[:2]

(You might also try adding \%#=1 to the regex to force the old engine. You might want to read :h E888 to see if it says anything useful. I don't have a vim version with this patch level to test right now.)


The help for :h \zs is copied below.

                                                        /\zs
\zs     Matches at any position, and sets the start of the match there: The
        next char is the first char of the whole match. /zero-width
        Example:
                /^\s*\zsif
        matches an "if" at the start of a line, ignoring white space.
        Can be used multiple times, the last one encountered in a matching
        branch is used.  Example:
                /\(.\{-}\zsFab\)\{3}
        Finds the third occurrence of "Fab".
        {not in Vi} {not available when compiled without the +syntax feature}
FDinoff
  • 30,689
  • 5
  • 75
  • 96
  • Wow! It didn't occur to me that :h would do the trick. In the future, I'll try :h on everything as a first resort. It gives this: This cannot be followed by a multi. E888. This makes sense with what you're explaining. – Xander Dunn Dec 24 '14 at 05:19
  • 2
    @thoughtadvances the vim help is great. Every feature/setting/error is documented. – FDinoff Dec 24 '14 at 05:21
  • I believe this did the trick. Removing the asterisk prevents the error. However, the function doesn't give the output it ought to. I'll need to step through the entire function and debug the whole thing to figure out that cause of that. – Xander Dunn Dec 25 '14 at 21:59
  • @thoughtadvances if you figure it out, could you send a pull request on git? – HamZa Dec 25 '14 at 23:19
  • 1
    @HamZa The original project by M Sanders is very very dead. I'm using a foek that's maintained: https://github.com/kentaroi/cocoa.vim. I'll make a pull request there. – Xander Dunn Dec 26 '14 at 00:38