Saturday, February 17, 2018

A syntax highlighting trivia: matching operators

Suppose that @, @@, and @@@ are three operators and that @ is not in
iskeyword. Besides, the operators may not necessarily be surrounded
by spaces or alphanumeric characters: for example, one may encounter
@( at the begin of the line (as in this line).

How would you define syntax rules to highlight those three operators,
but not @@@@, @@@@@, and so on?

The above is an instance of a problem I have encountered in my
PostgreSQL syntax plugin. Currently, I have rules like these:

syn match sqlIsOperator "[!?~#^@<=>%&|*/+-]\+" contains=sqlOperator
syn match sqlOperator contained "@@@\|@@\|@"
etc...

but those do not limit the highlighted sequences to just those defined
by the sqlOperator rules. More precisely, @@@@ is entirely highlighted
because its @@@ prefix matches and the last @ matches, too.

Thanks,
Life.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: