Ok, let me be more specific then. This is needed for C++ syntax
highlighting. This language uses also entities enclosed in "angle
brackets" < > - but the < character is also used as "less" operator.

So, I need something that will define:

head < contents >

and will highlight only < and >.
The "contents" may contain subexpressions, as long as there are
bracket matching pairs: <>, (), [], {}. However, if there happens a
single ), ], } without the opening party, the highlighting should be
cancelled, and possibly other rules should apply.

For example:

if ( curent_value < limits<int>::min and filtered(current_value) )  ...

This should: take the first < and consider highlighting. However, next
it gets - skipping ( ... ) - an unpaired closed parenthesis, in which
case this highlighting rule is dropped. Next, the < after "limits"
meets a paired > without any unpaired ) ] } in between, so the
highlighting rule applies. There's also defined another rule, which
highlights "if (" and the closing parenthesis ")". This parenthesis
was used to determine that the highlighting for the first < should be
cancelled - however, it still undergoes highlighting for the rule for
region start="if\s*(" end=")".

Currently I'm using a simpler rule: if there's no space between the
head and < then I consider it template instatiation, if there is
space, then less operator. However I need something more inteligent
because many people don't put space before "less" operator and it
confuses my syntax highlighting rules.


On 19 October 2012 17:12, ZyX <[email protected]> wrote:
> пятница, 19 октября 2012 г., 13:32:19 UTC+4 пользователь Sektor van Skijlen 
> написал:
>> Hello,
>>
>> I would like to use 'syntax region', where I have a defined start and 
>> possible end of region, BUT: after the pattern considered as start it may 
>> happen that there is a pattern that should cause the whole region match to 
>> be cancelled. It's not something like for 'skip' because it still makes the 
>> region to be matched.
>>
>> In other words: my region starts from found A letter and ends with Z letter, 
>> but can't contain Q letter, so:
>>
>> A T W Z E
>>
>> makes the region to be matched since the first letter to the last but one. 
>> But here:
>>
>> T A Q E Z
>>
>> despite matching start with A, there is no region to be matched in this 
>> sequence because he Q letter causes the matching to be cancelled.
>>
>> How to do something like that in vim syntax definition?
>
> In vim regular
>
>     syntax match {group} /\vA[^Q]{-}Z/
> can contain syntax elements just like ":syntax region" (and, I believe, but 
> have not tried, ":syn keyword"). So, in your example both the above will 
> work. With using "\_[^Q]" it will even work for multi-line matches (use 
> "\v%(%(Q)@!.){-}" if "Q" is actually a complex pattern). If you are using 
> ":syntax region" because of nesting possibility you may try to use something 
> like "start=/\vA%(%(%(Z)@!\_.){-}Q\_.{-}Z)@!/". Both solutions imply 
> performance penalty, second one is more huge (while trying to test this on 
> nested if conditions I got "E363: pattern uses more memory than 
> 'maxmempattern'", increasing it to 200000 has shown that it is working). Any 
> regex solution I can imagine won't disable the match in nested regions 
> without retreating to handling a number of specific cases:
>
> ("<" stands for "A", ">" for "Z" and "X" for "Q")
> Text:          < < < > > < < X > > >
> Nesting level: 112233322111111111111
>
> --
> You received this message from the "vim_dev" 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



-- 
Sektor

-- 
You received this message from the "vim_dev" 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

Raspunde prin e-mail lui