hightlight syntax problem

16 views
Skip to first unread message

Ni Va

unread,
Dec 2, 2019, 7:57:12 AM12/2/19
to vim_use
Hi all,

Considering this kind of line:

      SPB   ERR2; 



With in my syntax file these syntax pattern recognition:

syn match s7JumpsOperand    /^\s\+\zs\(SPA\|SPL\|SPBNB\|SPBN\|SPBB\|SPB\|SPBI\|SPBIN\|SLW\|SPO\|SPS\|SPZ\|SPN\|SPP\|SPM\|SPPZ\|SPMZ\|SPU\|LOOP\)\ze/
syn match s7JumpsLabel         /^\(\s\+SPB\s\+\)\zs\([^;]\+\)\ze;/

HiLink s7JumpsOperand        JumpsColorDarkRed
HiLink s7JumpsLabel             JumpsColorDarkRed



Why it highlights only first SPB Operand and no ERR2 like that ?

      SPB   ERR2; 


Thank you

Christian Brabandt

unread,
Dec 2, 2019, 9:48:28 AM12/2/19
to vim_use
They both try to match at the same location, because you implicitly
anchored your match. For that kind of thing you can use nextgroup e.g.

:syn match s7JumpsOperand /SPB\ze\s\+/ nextgroup=s7JumpLabel
:syn match s7JumpLabel /ERR2\ze;$/


Best,
Christian
--
So verblaßt das Abwesende, und eine neue Liebe tritt ein.
-- Ovid (Liebeskunst)

Ni Va

unread,
Dec 2, 2019, 10:08:41 AM12/2/19
to vim_use
 i tried this 

syn match s7JumpsOperand    /^\s\+\zs\(SPA\|SPL\|SPBNB\|SPBN\|SPBB\|SPB\|SPBI\|SPBIN\|SLW\|SPO\|SPS\|SPZ\|SPN\|SPP\|SPM\|SPPZ\|SPMZ\|SPU\|LOOP\)\ze/ nextgroup=s7JumpLabel
syn match s7JumpsLabel      /^\s\+\S\+\s\+\zs\([^;]\+\)\ze;/


It does not highlight second group s7JumLabel because of same location ... how to avoid this ?

Christian Brabandt

unread,
Dec 2, 2019, 10:15:43 AM12/2/19
to vim_use

On Mo, 02 Dez 2019, Ni Va wrote:

>  i tried this 
>
> syn match s7JumpsOperand    /^\s\+\zs\(SPA\|SPL\|SPBNB\|SPBN\|SPBB\|SPB\|SPBI\|
> SPBIN\|SLW\|SPO\|SPS\|SPZ\|SPN\|SPP\|SPM\|SPPZ\|SPMZ\|SPU\|LOOP\)\ze/ nextgroup
> =s7JumpLabel
> syn match s7JumpsLabel      /^\s\+\S\+\s\+\zs\([^;]\+\)\ze;/
>
>
> It does not highlight second group s7JumLabel because of same location ... how
> to avoid this ?

Remove the anchoring at the start of the line for Label group


Mit freundlichen Grüßen
Christian
--
Man verliert die meiste Zeit damit, daß man Zeit gewinnen will.
-- John Ernst Steinbeck

Ni Va

unread,
Dec 2, 2019, 10:30:28 AM12/2/19
to vim_use
Tried with 
syn match s7JumpsOperand    /^\s\+\zs\(SPA\|SPL\|SPBNB\|SPBN\|SPBB\|SPB\|SPBI\|SPBIN\|SLW\|SPO\|SPS\|SPZ\|SPN\|SPP\|SPM\|SPPZ\|SPMZ\|SPU\|LOOP\)\ze/ nextgroup=s7JumpLabel
syn match s7JumpsLabel      /\s\+\S\+\s\+\zs\([^;]\+\)\ze;/

do that:

Capture.PNG

Christian Brabandt

unread,
Dec 2, 2019, 10:36:08 AM12/2/19
to vim_use

On Mo, 02 Dez 2019, Ni Va wrote:

> Tried with 
> syn match s7JumpsOperand    /^\s\+\zs\(SPA\|SPL\|SPBNB\|SPBN\|SPBB\|SPB\|SPBI\|
> SPBIN\|SLW\|SPO\|SPS\|SPZ\|SPN\|SPP\|SPM\|SPPZ\|SPMZ\|SPU\|LOOP\)\ze/ nextgroup
> =s7JumpLabel
> syn match s7JumpsLabel      /\s\+\S\+\s\+\zs\([^;]\+\)\ze;/
>
> do that:

well, also remove the matching from the previous group. s7JumpsOperand
already matched the part before the \zs of the s7Jumpslabel, so why add
it here again? That cannot happen to match.

> Capture.PNG

please do not attach png pictures.

Best,
Christian
--
Selbst ißt der Mann.

Ni Va

unread,
Dec 2, 2019, 10:48:10 AM12/2/19
to vim_use
Effectively,  just want to match and highlight with two colors the two sentence like above:


      SPB _003;

So, the first no need to specify nextgroup I thought:
syn match s7JumpsOperand   /^\s\+\zs\(SPA\|SPL\|SPBNB\|SPBN\|SPBB\|SPB\|SPBI\|SPBIN\|SLW\|SPO\|SPS\|SPZ\|SPN\|SPP\|SPM\|SPPZ\|SPMZ\|SPU\|LOOP\)\ze/

the second has to know if it is preceeded by the first to highlight:
for example: syn match s7JumpsLabels    \(SPBNB\s\+\)\@<=\([^;]\+\)\ze;  but it has same location......

Ni Va

unread,
Dec 2, 2019, 10:50:57 AM12/2/19
to vim_use
This seems to work

Capture.PNG

syn match s7JumpsOperand    /^\s\+\zs\(SPA\|SPL\|SPBNB\|SPBN\|SPBB\|SPB\|SPBI\|SPBIN\|SLW\|SPO\|SPS\|SPZ\|SPN\|SPP\|SPM\|SPPZ\|SPMZ\|SPU\|LOOP\)\ze/
syn match s7JumpsLabel      /\(SPB\s\+\)\@<=\([^; ]\+\)\ze;/
Reply all
Reply to author
Forward
0 new messages