1

In my syntax description file I'm trying to define something like the following

syn match arbSAMPLEop   "\<\(TEX\|TEX_SAT\|TXP\|TXP_SAT\|TXB\|TXB_SAT\)\>"
syn match arbTexTarget     "\<\(1D\|2D\|3D\|CUBE\|RECT\)\>" contained
syn region arbSampleInstruction start="\<\(TEX\|TEX_SAT\|TXP\|TXP_SAT\|TXB\|TXB_SAT\)\>" end=";" contains=arbSAMPLEop,arbTexTarget

This allows to highlight texture sampling instructions and texture targets only inside the region started by a sampling instruction.

What bothers me is that the region starts by arbSAMPLEop, but the string to define arbSAMPLEop is copy-pasted as the start= pattern. Is there any way I could achieve the same without duplicating the string?

2

Try:

syn match arbTexTarget "\<\(1D\|2D\|3D\|CUBE\|RECT\)\>" contained
syn region arbSampleInstruction matchgroup=arbSAMPLEop start="\<\(TEX\|TEX_SAT\|TXP\|TXP_SAT\|TXB\|TXB_SAT\)\>" end=";" contains=arbTexTarget

matchgroup allows highlighting the delimiting patterns of a region separately from the body of the region.

:help syn-matchgroup

If you really had to, you could store a pattern in a string variable, and then use execute to build up your syntax command. However I doubt this is necessary in a well-structured syntax file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.