I've defined sqlVariable
and sqlString
in my syntax file as
syn match sqlVariable ":[a-z][a-z0-9_#$]*"
syn region sqlString start=+'+ end=+'+ contains=sqlVariable
(plus some other quoting variations.) Strings can contain sqlVariable
in order to highlight binds within dynamic code like the :b1
in 'select a from b where c = :b1'
. (This is for Oracle btw.)
This all works nicely - except for the specific annoying case of date format masks containing colons, e.g.
to_char(sysdate,'YYYY-MM-DD HH24:MI:SS')
:MI and :SS are highlighted as variables because of course they match my pattern.
Is there a way to make :MI and :SS not match sqlVariable
within a quoted string? (I think just those two cases would do it.)
does this help?
syn match sqlVariable ":[a-z][a-z0-9_#$]*\ze\(\s\|'$\)"
It will match those :foo
if they are followed by a white space or a '
then the EOL($
).
So, :a1 :b1 and :c1
will be matched:
'select * from foo where a= :a1 and b=: b1 and c = :c1'
but no match in:
to_char(sysdate,'YYYY-MM-DD HH24:MI:SS')
Hope it helps.
If it doesn't, maybe you can re-think about the region
definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With