以下规则集突出显示了您的语法:
highlight FirstToken ctermfg=green guifg=green
highlight SecondToken ctermfg=red guifg=red
syntax region FirstTuple start="\(\[\_s*\)\@<=\[" end="]"
\ containedin=FirstTuple,OtherTuple
\ nextgroup=SecondToken
\ skipwhite skipnl skipempty
syntax region OtherTuple start="\(\[\_s*\)\@<!\[" end="]"
\ containedin=FirstTuple,OtherTuple
syntax match FirstToken "\(\[\_s*\)\@<=[^ [\]]\+"
\ containedin=FirstTuple,OtherTuple
\ nextgroup=SecondToken
\ skipwhite skipnl skipempty
syntax match SecondToken "[^ [\]]\+"
\ contained
该FirstTuple区域匹配其父元组中的第一个元组,无论是标记还是其他元组;OtherTuple用于所有其他元组。这是通过互斥的lookbehinds 完成的,并且会自动处理正确的嵌套。FirstToken使用正向回溯仅匹配区域的开头。FirstToken并FirstTuple使用该nextgroup属性尝试SecondToken在自己之后立即匹配,忽略空格、换行符和空行。SecondToken使用该contained属性来避免自己到处匹配。