Sunday, March 29, 2015

Correct syntax for enums in C++

Hi everyone.

I want to correctly highlight enumeration values in a C++ application. I tried several approaches but the only one that worked is a little overkill. So I got here to ask the experts.

Suppose that I have a class named "MyClass". That class declares an enum with several values: "EnumConst1", "EnumConst2", etc. In the syntax file, off course, I added "MyClass" in a keyword group of C++ classes:

syn keyword cppClass MyClass

What I want to do is highlight the enumeration values only when they are typed with the class identifier. Like; "MyClass::EnumConst1". I tried this in the following way:

syn macth cppEnum transparent /\<MyClass::\@<=\i\w*\>/
syn keyword cppEnumValue contained EnumConst1 EnumConst2 containedin=cppEnum

Didn't work. I know that the keyword syntax of "MyClass" have precedence over the match syntax but I thought that using it in a transparent match would not interfere in the highlight of the contained enumeration value, since the operator '\@<=' is only to check the presence of a string before the real match. Writing the match in the following way works:

syn match cppEnumValue /\<MyClass::\@<=\(EnumConst1\|EnumConst2\)\>/

But then the 'MyClass' is not highlighted as cppClass group. Only the numeration values are highlighted. And, for a large list of enumeration values, would be overkill to write matches all over it.

There is a solution to this?

Thanks in advance.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment