Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim syntax highlighting - exclude specific text from a pattern

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.)

like image 227
William Robertson Avatar asked Nov 10 '22 00:11

William Robertson


1 Answers

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.

like image 114
Kent Avatar answered Nov 15 '22 04:11

Kent