A syntax highlighting trivia: matching operators

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

A syntax highlighting trivia: matching operators

Lifepillar
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: A syntax highlighting trivia: matching operators

Charles E Campbell Jr
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

junk (130 bytes) Download Attachment
at.vim (220 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: A syntax highlighting trivia: matching operators

Lifepillar
On 20/02/2018 16:10, Charles E Campbell wrote:

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

Nice! I think that the first syntax rule should include \ze, though:

    syn match OneAt '@\{1,3}\ze\([^@]\|$\)'

And, correct me if I am wrong, the rules can be further simplified to:

   syn match OneAt    '@\{1,3}'
   syn match LotsaAt  '@\{4,}'

   hi default link OneAt Operator

I hadn't thought of using a rule without a corresponding highlighting
to catch "negative" matches. Clever trick!

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 [hidden email].
For more options, visit https://groups.google.com/d/optout.