Friday, November 27, 2009

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

"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)

> > [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\>
>
> 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;
}

Hence the need to play with \@** patterns -- as we need to match:
)
/* somme comment
on several lines */
return 42;

> Alternative:
> /)\_s*\%(\%(\/\*.\{-}\*\/\|\/\/.*$\)\_s*\)*return\>
>
> This way it's easier to restrict the number of comments:
> /)\_s*\%(\%(\/\*.\{-}\*\/\|\/\/.*$\)\_s*\)\{,5}return\>

--
Luc Hermitte
http://lh-vim.googlecode.com/
http://hermitte.free.fr/vim/

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

No comments: