This question might be related to Custom syntax highlighting: highlight word following keyword but after studying that for hours, I could not get it to work.
What I want is to highlight vulkan types that match vk::(Instance|Device)
(in reality a much longer expression, but this will do as example).
It should not match vk::InstanceCreateInfo
(because that is a different type).
It should work when this match is contained inside a unrelated region. For example, I have a very complex regions that match parenthesis for different type of things; so complex that I really don't want this to be added as exception too. Yet, the highlight should work in code like:
void setup(vk::Instance vh_instance, vk::SurfaceKHR surface, DeviceCreateInfo&& device_create_info);
Aka, work while contained inside region cParen
.
I already have:
syn keyword cwNamespaceTag vk
which is auto-generated; I'd prefer to be able to leave that alone. But if necessary it can be changed.
I tried the following (already changing the above keyword):
syn keyword cwNamespaceVkTag vk nextgroup=cwVulkanHandle
syn match cwVulkanHandle '\v::(Instance|Device)>' contained
but that fails in that ::Device
in
void setup(foo::Device foo);
is highlighted (because it is contained (in cParen). Obviously this is not what I want; cwVulkanHandle
should only be enabled when immediately following cwNamespaceVkTag
.
I also tried,
syn keyword cwNamespaceVkTag vk contained
syn match cwVulkanHandle '\v<vk::(Instance|Device)>' contains=cwNamespaceVkTag
but that highlights vk
(as cwNamespaceVkTag
) and then cwVulkanHandle
isn't used anymore for some reason. When I remove the keyword line then the match works. It seems that the fact that vk
already matches a keyword stops the region
from matching against it, despite that I say that it contains it.
How can I get this to work?
EDIT:
This,
syn match cwNamespaceVkTag /vk::\(Instance\|Device\)\>/ contains=cwVulkanHandle
syn match cwVulkanHandle /::\w\+/ contained
leads to