4

I have a syntax highlight for cpp to highlight STL algorithms, one line is

syn keywork cppSTL find

My problem is that on a project that I am working, there are a number of classes with a method named find which are getting highlighted, and I want it only highlighted for STL calls.

So I decided to change the previous line to:

syn match cppSTL /[^.>:]\<find\>/ms=s+1
syn match cppSTL /\<std::find\>/ contains=cppScope
syn match cppScope /::/
hi clear cppScope

And it works most of the time. However if fails in this line:

vector<string>::iterator i = find(find(x.begin(), x.end(), val), x.end(), term);
                                  ^^^^

The first find is highlighted correctly, but the second fails. My limited knowledge of vim regex says it should match, but I can't figure out why it doesn't.

2
  • Just for kicks, try: i = find(...); i = find(...); ... where they're both on the same line. I'm curious if it's only finding the first match on each line Commented Apr 24, 2013 at 19:54
  • @Brian: two calls on the same line works; I think that the problem is because the second find in inside a parentesis - the highlight fails if I surround a call in () like (find(...)) Commented Apr 25, 2013 at 14:29

2 Answers 2

2

This might be what your looking for. It highlights all words find that are on a line that also contains a :: before it.

syn match cppSTL /\(::.*\)\@<=\<find\>/

If this isn't what you are asking for please tell me.

Sign up to request clarification or add additional context in comments.

2 Comments

this doesn't work for me. This would highlight wrongly in util::s->find() and will fail in the double find example of the question if the type of i is declared on another line. But it's getting closer to what I want.
Can you add more examples of cases where find should be highlighted and cases where find should not be highlighted?
0

I got it!

The problem is that my regex required a char behind find, and inside the parenthesis, the open parenthesis had already been matched, invalidating my regex.

It works if I replace the first line with:

syn match cppSTL "[^.>:]\@<=\<find\>"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.