Tuesday, February 20, 2018

Re: A syntax highlighting trivia: matching operators

one @ two
two @@ three
three @@@ four
lotsa @@@@s
one @
two @@
three @@@
lotsa @@@@
syn match OneAt '@\{1,3}\([^@]\|$\)'
syn match LotsaAt '@\{4,}'

hi default link OneAt Operator
hi default link TwoAt Operator
hi default link ThreeAt Operator
Lifepillar wrote:
> 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.
Hello:

Please try the attached at.vim file. I've included a "junk" file for
illustration.

Enjoy!
Chip Campbell

--
--
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:

Post a Comment