The following set of rules highlights your syntax:
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
The FirstTuple
region matches tuples, of either tokens or of other tuples, that are the first in their parent tuple; OtherTuple
is used for all other tuples. This is done via mutually exclusive lookbehinds, and proper nesting is handled automatically. FirstToken
uses a positive lookbehind to only match at the beginning of a region. FirstToken
and FirstTuple
use the nextgroup
attribute to attempt to match SecondToken
immediately after themselves, ignoring whitespace, newlines, and empty lines. SecondToken
uses the contained
attribute to avoid matching everywhere by itself.