I'm trying to establish syntax coloring for a certain lexical syntax: a "buffer literal". A buffer literal begins with #b'
and ends with '
. Between the single quotes, there can be undivided pairs of hex digits, with optional whitespace in between, that being spaces, tabs and newlines.
Valid buffer literals:
#b'' #b'FF' #b'Fe' #b'dead be
ef'
Invalid:
#b'z' #b'FFF' #b'9 0'
Here is what I have:
syn match buferr "." contained
syn match bufok "[0-9A-Fa-f][0-9A-Fa-f]\|[\t\n ]" contained
syn region buflit start="#b'"rs=e+1 end="'"re=s-1 contains=bufok,buferr
hi def link buferr Error
hi def link bufok String
hi def link buflit String
The problem is that the bufok
and buferr
match items are being applied to the region delimiters. And thus the #b'
start and '
end are matching buferr
and being highlighted as Error
.
I tried to compensate for this using the rs
(region start) and re
(region end) offset options on the region
patterns, seen above, but it has no effect. The matches are not contained to occur between the indicated region start and end.
How can we tell Vim that we want this:
#b'....'
rrrr <- this is the region, in which bufok and buferr are contained!
It really looks like rs
and re
offsets should be doing this, since the documentation says:
The pattern can be followed by a character offset. This can be used to change the highlighted part, and to change the text area included in the match or region (which only matters when trying to match other items).
On the contrary, my above fiddling with rs
and re
doesn't seem to be having an effect on the matching of contained items.
I'm working with Vim as old as 7.3.429.