Reputation: 33569
I am writing a vim syntax file for a yacc-like language, which contains another language in blocks delimited by braces. My problem stems from the inner language also using braces as part of its own syntax. Here's a minimized example:
meta lang {
lang { meta lang } lang }
meta lang
meta
is a keyword of the outer language, and lang
is a keyword of the inner language. Those same tokens may also appear in the other language, where they are not keywords.
The highlighting should look like the snippet below, where upper case META
and LANG
represent highlighted keywords, and lower case words are not highlighted.
META lang {
LANG { meta LANG } LANG } META lang
My naive attempt below produces this incorrect highlighting (fails to detect the end of the block):
META lang {
LANG { meta LANG } LANG } meta LANG
My syntax file:
" .vim/syntax/mylang.vim
sy cluster lang contains=langKeyword,langBlock
sy keyword metaKeyword meta
sy keyword langKeyword lang contained
sy region metaBlock start="{" end="}" contains=@lang
sy region langBlock start="{" end="}" contains=@lang contained
hi link metaKeyword Constant
hi link langKeyword Keyword
What am I doing wrong?
Upvotes: 2
Views: 52