I'm trying to improve on the MySQL syntax highlighting, for my particular code base.
I have a lot of this sort of thing
FROM TBL_ENTITIES E
JOIN TBL_RELATED_ENTITIES RE ON RE.entityFK = E.entityPK
My table nams are always uppercase and always start with TBL_, and my aliases are always uppercase and 1-3 characters long.
In this example, I'd like to create a syntax group mysqlQualifier
for RE
and E
.
In the ON clause (and further use when they're a qualifier before a column name) it seems quite trivial
syn match mysqlQualifier "\<[A-Z]\+\."
That correctly picks up on "RE." and "R." (Though I'd prefer it not to highlight the period if possible!)
But the alias clause is proving harder. I'm sure it'll be very simple to someone who's edited a syntax file before, but this is all new to me.
This is what I've tried, based on my understanding of Custom syntax highlighting: highlight word following keyword :
syn match mysqlTable "TBL_[A-Z_]\+" nextgroup=mysqlQualifier skipwhite
syn match mysqlQualifier "\<[A-Z]\+\>" contained
But it doesn't seem to work, and matches far too much (e.g. COALESCE
when COALESCE
hasn't immediately followed a table name.
I thought maybe I could simply match one, and then match the other, so as to "overwrite" part of it:
syn match mysqlQualifier "TBL_[A-Z_]\+.\s\+[A-Z]\+"
syn match mysqlTable "TBL_[A-Z_]\+"
But the second match seems to undo the first one; TBL_ENTITIES
correctly recognised as a table, but E
is not recognised as a qualifier, so I guess syntax can't be "overwritten" in the way that I hoped it might.
EDIT: I've now improved on the above...
syn match mysqlTable2 "TBL_[A-Z_]\+"
syn match mysqlQualifier "TBL_[A-Z_]\+.\s\+[A-Z]\+" contains=mysqlTable
syn match mysqlTable "TBL_[A-Z_]\+" contained
syn match mysqlQualifier "[A-Z]\+\."
This is almost perfect, with one exception - I still have the problem with the period being hightlighted after the qualifier, e.g. in RE.entityFK
.
Any help appreciated, thank you!