Friday, November 27, 2009

Re: Detect when a return follow an if instruction without bracket

Luc Hermitte schrieb:
> "Andy Wokula" <anwoku@yahoo.de> wrote:
>
>>> In GotoImpl [1], I've implemented the [[:blank_or_comment:]] this
>> way:
>>> \(\_s\|/\*.\{-}\*/\|//.*$\)*
>> Epanda, for a C-comment, the pattern
>> \/\*\_.\{-}\*\/
>> is simpler than what I gave you.
>>
>>> (Hum ... oddly I did not use \_. instead of . in the second
>>> expression... I guess the pattern should be modified to use the \@
>>> multi-items)
>> '\@' multi item?
>
> :h /\@!
> :h /\@=
> :h /\@<=
> ...
>
> (I've never been able to make sense out of them)

Really? Ok, I'll try to give a short explanation ...

/B\@!A
match A, but fail if B matches at the same position

/B\@=A
match A, but only if also B matches at the same position
same as B\&A

/B\@<!A
match A, but fail if B matches left from it

/B\@<=A
match A, but only if B matches left from it


>>> [1] http://code.google.com/p/lh-vim/wiki/lhCpp and more precisely:
>>>
>> http://code.google.com/p/lh-vim/source/browse/cpp/trunk/autoload/lh/cpp/AnalysisLib_Function.vim#526
>>
>> Result:
>> /)\%(\_s\|\/\*.\{-}\*\/\|\/\/.*$\)*return\>

"Hum ... oddly I did not use \_. instead of .". I actually meant:
/)\%(\_s\|\/\*\_.\{-}\*\/\|\/\/.*$\)*return\>

>> Minor difference: it will match wrong code like
>>
>> )
>> /* */ */
>> return
>
> Worse, with \_. instead of ., it will match
> )
> /* some comment */
> g(42);
> }
> void g(int i) {
> /* other comment */
> return i;
> }

Oh right, I knew I had something in mind with my original pattern (which
doesn't make this mistake).

--
Andy

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment